yvquanli / GLAM

Code for "An adaptive graph learning method for automated molecular interactions and properties predictions".
https://www.nature.com/articles/s42256-022-00501-8
MIT License
39 stars 8 forks source link

Problem to run demo.py #7

Closed vitorom-01 closed 1 year ago

vitorom-01 commented 1 year ago

After following all the command in the sction "Installation" I tried to run a demo with command: "cd ./GLAM/src_1gp python3 demo.py" but there is this error: (GLAM) vito@vito-HP-ENVY-15-Notebook-PC:~/project/GLAM/src_1gp$ python3 demo.py Traceback (most recent call last): File "demo.py", line 2, in os.chdir(os.path.dirname(file)) FileNotFoundError: [Errno 2] No such file or directory: ''

I don't know what's wrong and how can I resolve this problem

yvquanli commented 1 year ago

This is because the directory change command run with error, you can delete this line

os.chdir(os.path.dirname(__file__))

and try again

vitorom-01 commented 1 year ago

I deleted that line and this is the error:

Without "conda activate GLAM" I obtain this:

(base) @.***:~/projectA/GLAM/src_1gp$ python3 demo.py Test for dataset.py and run.py! Traceback (most recent call last): File "./run.py", line 2, in from model import Model File "/home/vito/projectA/GLAM/src_1gp/model.py", line 2, in from torch_geometric.nn import Set2Set ModuleNotFoundError: No module named 'torch_geometric' Demo running... Please install rdkit for data processing Traceback (most recent call last): File "./glam.py", line 7, in from logger import config2cmd File "/home/vito/projectA/GLAM/src_1gp/logger.py", line 3, in from metrics import auto_metrics File "/home/vito/projectA/GLAM/src_1gp/metrics.py", line 5, in from dataset import dataset_names File "/home/vito/projectA/GLAM/src_1gp/dataset.py", line 9, in from torch_scatter import scatter ModuleNotFoundError: No module named 'torch_scatter'

With previous command: conda activate GLAM

I obtain this:

(GLAM) @.***:~/projectA/GLAM/src_1gp$ python3 demo.py Test for dataset.py and run.py! Traceback (most recent call last): File "./run.py", line 2, in from model import Model File "/home/vito/projectA/GLAM/src_1gp/model.py", line 2, in from torch_geometric.nn import Set2Set File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_geometric/init.py", line 5, in import torch_geometric.data File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_geometric/data/init.py", line 1, in from .data import Data File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_geometric/data/data.py", line 8, in from torch_sparse import coalesce, SparseTensor File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_sparse/init.py", line 40, in from .tensor import SparseTensor # noqa File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_sparse/tensor.py", line 13, in class SparseTensor(object): File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch/jit/_script.py", line 1128, in script _compile_and_register_class(obj, _rcb, qualified_name) File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch/jit/_script.py", line 138, in _compile_and_register_class script_class = torch._C._jit_script_class_compile(qualified_name, ast, defaults, rcb) RuntimeError: object has no attribute sparse_csr_tensor: File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_sparse/tensor.py", line 511 value = torch.ones(self.nnz(), dtype=dtype, device=self.device())

    return torch.sparse_csr_tensor(rowptr, col, value, self.sizes())
           ~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE

Demo running... Traceback (most recent call last): File "./glam.py", line 7, in from logger import config2cmd File "/home/vito/projectA/GLAM/src_1gp/logger.py", line 3, in from metrics import auto_metrics File "/home/vito/projectA/GLAM/src_1gp/metrics.py", line 5, in from dataset import dataset_names File "/home/vito/projectA/GLAM/src_1gp/dataset.py", line 10, in from torch_geometric.data import Data, InMemoryDataset File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_geometric/init.py", line 5, in import torch_geometric.data File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_geometric/data/init.py", line 1, in from .data import Data File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_geometric/data/data.py", line 8, in from torch_sparse import coalesce, SparseTensor File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_sparse/init.py", line 40, in from .tensor import SparseTensor # noqa File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_sparse/tensor.py", line 13, in class SparseTensor(object): File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch/jit/_script.py", line 1128, in script _compile_and_register_class(obj, _rcb, qualified_name) File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch/jit/_script.py", line 138, in _compile_and_register_class script_class = torch._C._jit_script_class_compile(qualified_name, ast, defaults, rcb) RuntimeError: object has no attribute sparse_csr_tensor: File "/home/vito/anaconda3/envs/GLAM/lib/python3.8/site-packages/torch_sparse/tensor.py", line 511 value = torch.ones(self.nnz(), dtype=dtype, device=self.device())

    return torch.sparse_csr_tensor(rowptr, col, value, self.sizes())
           ~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE

Il giorno mer 11 gen 2023 alle ore 07:09 leo @.***> ha scritto:

Closed #7 https://github.com/yvquanli/GLAM/issues/7 as completed.

— Reply to this email directly, view it on GitHub https://github.com/yvquanli/GLAM/issues/7#event-8198377168, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUFIK5YKRFISPF74PXHRWODWRZFDNANCNFSM6AAAAAATVSI224 . You are receiving this because you authored the thread.Message ID: @.***>

yvquanli commented 1 year ago

This is because your torch_sparse installed failed. Please show me your version of torch and cudatoolkit. Please do not install the latest version of them

yvquanli commented 1 year ago

We find a problem with the enviroment installation, this may because the problem of torch_sparse

https://github.com/rusty1s/pytorch_sparse/issues/207

Anyway, we will give the new enviromental config later.

yvquanli commented 1 year ago

Thank you for your issue up, all problems are solved!

vitorom-01 commented 1 year ago

demo.py correctly run! So I've tried the command: python3 run.py --epochs 1

(GLAM) user@user-HP-ENVY-15-Notebook-PC:~/GLAM/src_1gp$ python3 run.py --epochs 1 Loading dataset... Training init... ################################################################################ dataset_root:../../Dataset/GLAM-GP dataset:esol split:random seed:1234 split_seed:1234 gpu:0 note:None2 hid_dim_alpha:4 mol_block:_NNConv e_dim:1024 out_dim:1 message_steps:3 mol_readout:GlobalPool5 pre_norm:_None graph_norm:_PairNorm flat_norm:_None end_norm:_None pre_do:_None() graph_do:_None() flat_do:Dropout(0.2) end_do:Dropout(0.2) pre_act:RReLU graph_act:RReLU flat_act:RReLU graph_res:1 batch_size:32 epochs:1 loss:mse optim:Adam k:6 lr:0.001 lr_reduce_rate:0.7 lr_reduce_patience:20 early_stop_patience:50 verbose_patience:500 ################################################################################ save id: 2023-01-13_14:20:41.944_seed_1234 run device: cpu train set num:904 valid set num:112 test set num: 112 total parameters:454789 ################################################################################ Architecture( (mol_lin0): LinearBlock( (norm): _None() (dropout): _None() (linear): Linear(in_features=15, out_features=60, bias=True) (act): RReLU(lower=0.125, upper=0.3333333333333333) ) (mol_conv): MessageBlock( (norm): _PairNorm( (norm): PairNorm() ) (dropout): _None() (conv): _NNConv( (conv): NNConv(60, 60, aggr="mean", nn=Sequential( (0): Linear(in_features=4, out_features=32, bias=True) (1): ReLU() (2): Linear(in_features=32, out_features=3600, bias=True) )) ) (gru): GRU(60, 60) (act): RReLU(lower=0.125, upper=0.3333333333333333) ) (mol_readout): GlobalPool5() (mol_flat): LinearBlock( (norm): _None() (dropout): Dropout(p=0.2, inplace=False) (linear): Linear(in_features=300, out_features=1024, bias=True) (act): RReLU(lower=0.125, upper=0.3333333333333333) ) (lin_out1): LinearBlock( (norm): _None() (dropout): Dropout(p=0.2, inplace=False) (linear): Linear(in_features=1024, out_features=1, bias=True) (act): _None() ) ) ################################################################################ Training start... 0%| | 0/1 [00:00<?, ?it/s]batch 0 training loss: 8.70186 time elapsed 0.00 hrs (0.0 mins) Epoch:0 trn_loss:13.60003 val_loss:3.30766 val_result:{'ci': 0.7748146954560103, 'mse': 3.4477494, 'rmse': 1.8568116157265382, 'r2': 0.32129932361229274} lr_cur:0.0010000 time elapsed 0.00 hrs (0.0 mins) Model saved at epoch 0 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:02<00:00, 2.25s/it] Model saved at epoch 0 Testing... The best ckpt is /home/user/GLAM/src_1gp/log_esol/2023-01-13_14:20:41.944_seed_1234/best_save.ckpt Ckpt loading: /home/user/GLAM/src_1gp/log_esol/2023-01-13_14:20:41.944_seed_1234/best_save.ckpt {'dataset_root': '../../Dataset/GLAM-GP', 'dataset': 'esol', 'split': 'random', 'seed': 1234, 'split_seed': 1234, 'gpu': 0, 'note': 'None2', 'hid_dim_alpha': 4, 'mol_block': '_NNConv', 'e_dim': 1024, 'out_dim': 1, 'message_steps': 3, 'mol_readout': 'GlobalPool5', 'pre_norm': '_None', 'graph_norm': '_PairNorm', 'flat_norm': '_None', 'end_norm': '_None', 'pre_do': '_None()', 'graph_do': '_None()', 'flat_do': 'Dropout(0.2)', 'end_do': 'Dropout(0.2)', 'pre_act': 'RReLU', 'graph_act': 'RReLU', 'flat_act': 'RReLU', 'graph_res': 1, 'batch_size': 32, 'epochs': 1, 'loss': 'mse', 'optim': 'Adam', 'k': 6, 'lr': 0.001, 'lr_reduce_rate': 0.7, 'lr_reduce_patience': 20, 'early_stop_patience': 50, 'verbose_patience': 500} {'testloss': 3.831183910369873, 'valloss': 3.3076584339141846}|{'ci': 0.7792981326464906, 'mse': 3.5419254, 'rmse': 1.8820003799940774, 'r2': 0.2003656506781354}|{'valci': 0.7748146954560103, 'valmse': 3.4477494, 'valrmse': 1.8568116157265382, 'valr2': 0.32129932361229274}

Is the file running correctly? In case in which run.py doesn't running correctly, can you please write how to put all the "Dataset" in the "Full structure of workplace" more clearly? Can you tell me in more detail where to put them please? Thanks so much for your work

yvquanli commented 1 year ago

Yes, it running correctly

yvquanli commented 1 year ago

OK, I will write the dataset guide clearly, with more details

vitorom-01 commented 1 year ago

Thank you so much for your work! I have an other question, in which way can I put the inputs? Is there a command that can I use or a guide for example that explains how to put the molecules to study in input?

yvquanli commented 1 year ago

This may be a bit tricky, but you can try this idea Firstly, you should process your data to PYG dataset as GLAM and then you can try this pesudo code

from torch_geometric.data import DataLoader
test_dataloader=DataLoader(YOUR_PYG_DATASET)

trainer.load_best_ckpt()
trainer.test_dataloader = test_dataloader
trainer.valid_iterations(mode='inference')