MolecularAI / Reinvent

Apache License 2.0
338 stars 110 forks source link

Can't run the reinforcement learning part in the notebook #35

Closed xuzhang5788 closed 3 years ago

xuzhang5788 commented 3 years ago

Thank you for your great repo. I struggled with this problem for a while. I don't know where I am wrong. I just followed the instructions you gave. I will show how I installed the libraries and how I run the notebooks in detail. It is a little bit longer, but please help me.

  1. install reinvent library $ git clone https://github.com/MolecularAI/Reinvent.git $ cd Reinvent $ conda env create -f reinvent.yml $ conda activate reinvent.v3.0

  2. then I opened another terminal to install ReinventCommunity $ git clone https://github.com/MolecularAI/ReinventCommunity.git $ cd ReinventCommunity $ conda env create -f environment.yml $ conda activate ReinventCommunity

  3. ran one of the notebooks, here I chose the first example. (ReinventCommunity) pharma1@pharma1:/mnt/SSD/projects/ReinventCommunity$ jupyter notebook a. opened file "Complete_Use-Case-DRD2_Demo.ipynb"

b. changed cell No.1 only the following part to meet my system

from: reinvent_dir = os.path.expanduser("~/Desktop/Projects/Publications/2020/2020-04_REINVENT_2.0/Reinvent") reinvent_env = os.path.expanduser("~/miniconda3/envs/reinvent_shared.v2.1") output_dir = os.path.expanduser("~/Desktop/REINVENT_Use-Case-DRD2_demo")

to: reinvent_dir = os.path.expanduser("../../Reinvent") reinvent_env = os.path.expanduser("~/miniconda3/envs/reinvent.v3.0") output_dir = os.path.expanduser("~/Desktop/REINVENT_Use-Case-DRD2_demo")

c. ran the following cells until cell No.12 without any error

d. ran cell No.13 showed the following error messages: Traceback (most recent call last): File "../../Reinvent/input.py", line 6, in from running_modes.manager import Manager File "/mnt/SSD/projects/Reinvent/running_modes/manager.py", line 4, in from running_modes.configurations import GeneralConfigurationEnvelope File "/mnt/SSD/projects/Reinvent/running_modes/configurations/init.py", line 2, in from running_modes.configurations.scoring import ScoringRunnerComponents, ScoringRunnerConfiguration File "/mnt/SSD/projects/Reinvent/running_modes/configurations/scoring/init.py", line 1, in from running_modes.configurations.scoring.scoring_runner_components import ScoringRunnerComponents File "/mnt/SSD/projects/Reinvent/running_modes/configurations/scoring/scoring_runner_components.py", line 3, in from reinvent_scoring.scoring import ScoringFuncionParameters ModuleNotFoundError: No module named 'reinvent_scoring'

e. I checked if reinvent_scoring was installed (reinvent.v3.0) pharma1@pharma1:/mnt/SSD/projects/Reinvent$ python Python 3.7.7 (default, Mar 26 2020, 15:48:22) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information.

import reinvent_scoring

It showed reinvent_scoring was installed for sure. So I don't know how this error happened.

f. I tried to run reinvent using the command-line execution just like you mentioned: $ conda activate reinvent.v3.0 (reinvent.v3.0) pharma1@pharma1:/mnt/SSD/projects/Reinvent$ python input.py /home/pharma1/Desktop/REINVENT_Use-Case-DRD2_demo/DRD2_config.json

I got the following error messages:

Traceback (most recent call last): File "input.py", line 20, in manager = Manager(configuration) File "/mnt/SSD/projects/Reinvent/running_modes/manager.py", line 13, in init self._load_environmental_variables() File "/mnt/SSD/projects/Reinvent/running_modes/manager.py", line 22, in _load_environmental_variables with open(os.path.join(project_root, '../configs/config.json'), 'r') as f: FileNotFoundError: [Errno 2] No such file or directory: '/mnt/SSD/projects/Reinvent/running_modes/../configs/config.json'

Do I need to change the name "DRD2_config.json" to "config.json" and put it into the folder where "example.config.json" is?

g. I tries the other examples, everything was okay until I need to run REINVENT, and the same errors appeared.

I really don't know where I was wrong! Any help is highly appreciated. I was so so frustrated. Many thanks.

GuoJeff commented 3 years ago

Hi @xuzhang5788,

Sorry for the delay. I just pushed many changes to the reinvent and reinvent community repositories. The new changes are related to the release of the new REINVENT 3.0 version. Some of the errors you were receiving were due to out of date packages which should now all be fixed.

I have executed all the notebooks in https://github.com/MolecularAI/ReinventCommunity and they should all work. Would you be able to re-install the new conda environments and try the notebooks again (they have been updated)? Let me know if anything does not work.

xuzhang5788 commented 3 years ago

Thank you for your update. I reinstalled Reinvent 3.0 and ReinventCommunity. Unfortunately, I still got error messages: (ran in the notebook and also in command-line)

Traceback (most recent call last): File "../../Reinvent/input.py", line 20, in manager = Manager(configuration) File "/mnt/SSD/projects/Reinvent/running_modes/manager.py", line 13, in init self._load_environmental_variables() File "/mnt/SSD/projects/Reinvent/running_modes/manager.py", line 22, in _load_environmental_variables with open(os.path.join(project_root, '../configs/config.json'), 'r') as f: FileNotFoundError: [Errno 2] No such file or directory: '/mnt/SSD/projects/Reinvent/running_modes/../configs/config.json'

In your example, you used reinvent_dir = os.path.expanduser("~/Desktop/reinventcli") I think it is where the reinvent 3.0 is. From git clone, I got a new folder called Reinvent. So, I used reinvent_dir = os.path.expanduser("../../Reinvent"). Because the folders of Reinvent3.0 and ReinventCoomunity are in the same directory.

GuoJeff commented 3 years ago

Hi @xuzhang5788,

Before running REINVENT, a config.json needs to be set-up. In the directory: Reinvent/configs, there is a file called example.config.json. This file is the template for how the config.json needs to be set-up. The easiest way is to make a copy of the example.config.json and name it config.json. At this point, you should be able to run REINVENT without any further changes.

However, it is good to run the provided unit tests to make sure everything is working properly. If you want to run the unit tests, the config.json needs to be edited to specify absolute paths to different REINVENT tools/files. These are the paths that the unit tests will use. For example, you can specify the absolute path to the provided prior in the PRIOR_PATH field. Once specified, unit tests which require a prior will find the prior from that path. There is some information regarding this in the README.

xuzhang5788 commented 3 years ago

@GuoJeff Thank you so much. According to your advice, I changed the name example.config.json to config.json and tried all the notebooks. Everyone works except Transfer_Learning_Demo_Teachers_Forcing.jpynb. I got:

Traceback (most recent call last): File "../../Reinvent/input.py", line 21, in manager.run() File "/mnt/SSD/projects/Reinvent/running_modes/manager.py", line 16, in run runner = RunningMode(self.configuration) File "/mnt/SSD/projects/Reinvent/running_modes/constructors/running_mode.py", line 22, in new return TransferLearningModeConstructor(configuration) File "/mnt/SSD/projects/Reinvent/running_modes/constructors/transfer_learning_mode_constructor.py", line 31, in new model = Model.load_from_file(config.input_model_path) File "/home/pharma1/miniconda3/envs/reinvent.v3.0/lib/python3.7/site-packages/reinvent_models/reinvent_core/models/model.py", line 123, in load_from_file save_dict = torch.load(file_path) File "/home/pharma1/miniconda3/envs/reinvent.v3.0/lib/python3.7/site-packages/torch/serialization.py", line 595, in load return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args) File "/home/pharma1/miniconda3/envs/reinvent.v3.0/lib/python3.7/site-packages/torch/serialization.py", line 774, in _legacy_load result = unpickler.load() ModuleNotFoundError: No module named 'models' Exception ignored in: <function LocalTransferLearningLogger.del at 0x7fb414e33e60> Traceback (most recent call last): File "/mnt/SSD/projects/Reinvent/running_modes/transfer_learning/logging/local_transfer_learning_logger.py", line 20, in del File "/home/pharma1/miniconda3/envs/reinvent.v3.0/lib/python3.7/site-packages/torch/utils/tensorboard/writer.py", line 1033, in close File "/home/pharma1/miniconda3/envs/reinvent.v3.0/lib/python3.7/site-packages/torch/utils/tensorboard/writer.py", line 133, in flush File "/home/pharma1/miniconda3/envs/reinvent.v3.0/lib/python3.7/site-packages/tensorboard/summary/writer/event_file_writer.py", line 106, in flush File "/home/pharma1/miniconda3/envs/reinvent.v3.0/lib/python3.7/site-packages/tensorboard/summary/writer/event_file_writer.py", line 156, in flush File "/home/pharma1/miniconda3/envs/reinvent.v3.0/lib/python3.7/site-packages/tensorboard/summary/writer/record_writer.py", line 42, in flush File "/home/pharma1/miniconda3/envs/reinvent.v3.0/lib/python3.7/site-packages/tensorflow_core/python/lib/io/file_io.py", line 230, in flush AttributeError: 'NoneType' object has no attribute 'raise_exception_on_not_ok_status'

Anyways, I am glad that I can run most of the examples. About the unit tests, I need time to figure out how to set the config.json. Maybe I still need your help. Thanks again.

patronov commented 3 years ago

I believe the issue reported here should be fixed now.

xuzhang5788 commented 3 years ago

@patronov Thanks. It works now!