ersilia-os / ersilia

The Ersilia Model Hub, a repository of AI/ML models for infectious and neglected disease research.
https://ersilia.io
GNU General Public License v3.0
200 stars 128 forks source link

✍️ Contribution period: Aml #621

Closed Aml-Hassan-Abd-El-hamid closed 1 year ago

Aml-Hassan-Abd-El-hamid commented 1 year ago

Week 1 - Get to know the community

Week 2 - Install and run an ML model

Week 3 - Propose new models

Week 4 - Prepare your final application

Aml-Hassan-Abd-El-hamid commented 1 year ago

I'm done with installing Ersilia :) I've followed the instruction from here.

I didn't have conda installed so I installed it using the Anaconda installer, I followed the instructions from here, and I also found this conda tutorial very useful.

Finally, I wasn't familiar with Docker, so I looked it up and found this nice tutorial, It also contains instructions regarding installing Docker on different operating systems.

Screenshot from 2023-03-08 17-32-45

GemmaTuron commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid

Welcome to Ersilia, and great start of the contribution period. Please, can you specify which system are you running on and wheter you have been able to run Ersilia from the CLI (not web browser) Thanks!

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @GemmaTuron

Thank you very much for the encouragement : ) I'm running on Ubuntu 22.04.1 And I was able to run Ersilia from the terminal, I followed those instructions , and here's a screenshot from my terminal:

Screenshot from 2023-03-09 12-39-11

Aml-Hassan-Abd-El-hamid commented 1 year ago

Why do I want to work at Ersilia:

A year ago, I started developing an interest in ML and Data as I heard a lot about the value that ML can bring into people's lives, but up until the start of this month, I haven't yet gotten many chances to work on projects that can truly help people, more than that: the ChatGpt and the news about ML & AI replacing humans were all that I could see lately online! I was almost losing motivation to continue learning ML. And then I got accepted at Outreachy and got to hear for the first time about Ersilia, an initiative that seeks to utilize ML & AI to help the research in the biomedical field, I felt that this was my new chance to get to see closely how ML can really help humans get cured and contribute to that myself! It's my dream job!

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @GemmaTuron I first chose to work with IDL-PPBopt model. There were 2 main reasons why I was excited to explore that model: First, the model uses an Interpretable Deep Learning Method which I have never worked with before, I was waiting for a chance to learn about Interpretable DL, but my college workload never encouraged me to do that : ) Second, that model doesn't have a very pretty README, so I thought that I can fork the repo and work on that, I think that might be helpful for anyone who wants to use that model in the future. But after a lot of searching, I couldn't get access to the paper on that model and also didn't find any articles about it, I tried to search with the name of the algorithm that they mentioned: "AttentiveFP" but I still got nothing :( Please, if you or @carcablop got anything that can help me to know more about that model, let me know.

Aml-Hassan-Abd-El-hamid commented 1 year ago

Installing the model: I first tried to create a conda environment for that model using the following command: $ conda create --name IDL-PPBot python=3.7 pytorch=1.5.0 openbabel=2.4.1 rdkit cairosvg scipy scikit-learn But I got the following error:

PackagesNotFoundError: The following packages are not available from current channels:

  - cairosvg
  - rdkit
  - openbabel=2.4.1

Current channels:

  - https://repo.anaconda.com/pkgs/main/linux-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/linux-64
  - https://repo.anaconda.com/pkgs/r/noarch

So I tried this line : conda create --name IDL-PPBot python=3.7 pytorch=1.5.0 scipy scikit-learn and after that, I activated the conda environment and started to install those packages one by one: For cairosvg: I looked it up and found that it's PyPi and installed it using pip install CairoSVG. For redkit: I looked up and found its installation instructions here, I used pip install rdkit For openbabel: I followed the installation instructions from here and chose to install it using snap snap install openbabel

Aml-Hassan-Abd-El-hamid commented 1 year ago

The only 2 instructions that were given on using that model were those: 1- Write the given molecules to input_compounds.csv file. 2-Run IDL-PPBopt.ipynb in jupyter notebook. So I downloaded the repo as a zip file and extracted it in the folder of my environment. I worked a lot with Juptyer Notebook before, but I didn't use it with conda before, so I looked that up and found this beautiful tutorial , After setting my Jupiter notebook, I tried to work with it :) but ended up with an error running the first cell: TypeError: type torch.cuda.FloatTensor not available. Torch not compiled with CUDA enabled. so I change the line: torch.set_default_tensor_type('torch.cuda.FloatTensor') to be torch.set_default_tensor_type('torch.FloatTensor') and then faced the errors : "ModuleNotFoundError" one for pandas and one for matplotlib, although both of them weren't mentioned in the requirement of this model. I faced this error: ModuleNotFoundError: No module named 'openbabel' that one was really weird as I already have installed 'openbabel' using snap, I tried to reinstall it using pip bafter I found the openbabel PyPi page but that failed and that didn't work, I finally try installing it using conda as conda install openbabel -c conda-forge and it works. I got the error: ModuleNotFoundError: No module named 'pybel', So I installed pybel using pip, but still got the error : ImportError: cannot import name 'Smarts' from 'pybel' (/home/aml/anaconda3/envs/IDL-PPBot/lib/python3.7/site-packages/pybel/__init__.py)

GemmaTuron commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid !

Indeed, probably you don't have a GPU-workstation and therefore cuda cannot run, you need to change the installation to use torch without cuda, and modify the code as well so that it does not use the cuda, as you have started to do (for example, do not use model.cuda to load the device) For solving the environment, I suggest deleting the current one and starting anew, installing one by one the required packages, starting with the right version of torch without cuda, also make sure to install the right version of pytorch without gpu, this should be sth like conda install pytorch==1.5.0 torchvision==0.6.0 cpuonly -c pytorch

carcablop commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid I'm sorry. By my mistake, I close the problem, my apologies. I reopen it.

carcablop commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid This is the paper of the idl-ppb model. acs.jcim.2c00297.pdf

carcablop commented 1 year ago

@Aml-Hassan-Abd-El-hamid Following the thread of the suggestions that Gemma has mentioned to you before, for packages like pandas and matplotlib, once you have created the conda environment as suggested by Gemma, you should install these packages, even if the author has not mentioned them, that ModuleNotFound error It's because you don't have it installed.

carcablop commented 1 year ago

@Aml-Hassan-Abd-El-hamid
A suggestion: You could also download the code, if you have git installed, from the command terminal, with the "git clone "url" command. Try to document in an orderly way all the changes you make to the code, and also the additional packages you have installed to run the model successfully on your local machine.

Aml-Hassan-Abd-El-hamid commented 1 year ago

Thank you very much for your help @carcablop @GemmaTuron Sorry for responding back late. I deleted the environment and created a new one, and stated installing the packages one by one, installed git and cloned the repo like @carcablop suggested , I only changed one line in the code : torch.set_default_tensor_type('torch.FloatTensor') I didn't get the errors from before but that error : ImportError: cannot import name 'Smarts' from 'pybel' (/home/aml/anaconda3/envs/IDL-PPBot/lib/python3.7/site-packages/pybel/__init__.py) I tried to uninstall pybel and reinstall it using different ways, I used conda install -c "bioconda/label/cf201901" pybel, conda install -c bioconda pybel and finally pip uninstall pybel but still that didn't fix anything, can you please help me with that ?

carcablop commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid In the model requirements they indicate that you must install openbabel 2.4.1 You can see this documentation about openbabel installation: http://openbabel.org/wiki/Category:Installation One option is with conda. So it should not be necessary to install pybel. You can see this documentation about pybel : https://openbabel.org/docs/dev/UseTheLibrary/Python_Pybel.html

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hey @carcablop thank you for your help, I already have installed openbabel using the following command: conda install openbabel -c conda-forge, I tried installing it using snap in the environment before that but the notebook failed to import it.

Aml-Hassan-Abd-El-hamid commented 1 year ago

I just figured out that there's really no problem with the installation pybel on my current env as I tried it in the terminal and it worked just fine, the problem was that the files of the cloned repo couldn't find that library although it could find other libs that were only installed on that environment.

Screenshot from 2023-03-17 04-30-40

that's the error that I've been getting for reference:

ImportError                               Traceback (most recent call last)
/tmp/ipykernel_58107/1286787695.py in <module>
     47 import scipy
     48 
---> 49 from sarpy import SARpy
     50 import operator,pybel
     51 import os

~/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/sarpy/SARpy.py in <module>
      3 from math import log
      4 from time import time
----> 5 from sarpy.SARpytools import *
      6 
      7 def collectSubs(structures, grinder):

~/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/sarpy/SARpytools.py in <module>
      5 from csv import reader
      6 from openbabel import OBConversion, obErrorLog
----> 7 from pybel import Smarts, readfile, readstring
      8 obErrorLog.SetOutputLevel(0)
      9 Break = 'x'

ImportError: cannot import name 'Smarts' from 'pybel' (/home/aml/anaconda3/envs/IDL-PPBot/lib/python3.7/site-packages/pybel/__init__.py)
GemmaTuron commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid

Can you try uninstallying pybel from the conda environment and installing openbabel only conda install -c openbabel openbabel

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @GemmaTuron I did that and it didn't work, so I deleted that env and created a new one and this time I only installed openbabel using conda install -c openbabel openbabel and it worked, the only errors that I'm having right now are cuda related, I tried to trace cuda through the file and erase it but I got that error:

RuntimeError                              Traceback (most recent call last)
 in 
----> 1 remain_pred_list = eval(model, remained_df)
      2 remained_df['Predicted_values'] = remain_pred_list
      3 remained_df

 in eval(model, dataset)
     54 
     55         x_atom, x_bonds, x_atom_index, x_bond_index, x_mask, smiles_to_rdkit_list = get_smiles_array(smiles_list,feature_dicts)
---> 56         atoms_prediction, mol_prediction = model(torch.Tensor(x_atom),torch.Tensor(x_bonds),torch.LongTensor(x_atom_index),torch.LongTensor(x_bond_index),torch.Tensor(x_mask))
     57 #        MAE = F.l1_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')
     58 #        MSE = F.mse_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')

[~/anaconda3/envs/IDL/lib/python3.7/site-packages/torch/nn/modules/module.py](https://file+.vscode-resource.vscode-cdn.net/home/aml/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/~/anaconda3/envs/IDL/lib/python3.7/site-packages/torch/nn/modules/module.py) in __call__(self, *input, **kwargs)
    548             result = self._slow_forward(*input, **kwargs)
    549         else:
--> 550             result = self.forward(*input, **kwargs)
    551         for hook in self._forward_hooks.values():
    552             hook_result = hook(self, input, result)

[~/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/AttentiveFP/AttentiveLayers.py](https://file+.vscode-resource.vscode-cdn.net/home/aml/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/~/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/AttentiveFP/AttentiveLayers.py) in forward(self, atom_list, bond_list, atom_degree_list, bond_degree_list, atom_mask)
     48         attend_mask[attend_mask != mol_length-1] = 1
     49         attend_mask[attend_mask == mol_length-1] = 0
---> 50         attend_mask = attend_mask.type(torch.FloatTensor).unsqueeze(-1)
     51 
     52         softmax_mask = atom_degree_list.clone()

RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason.  The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols.  You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.

I'm trying to setup cuda in a new env now and I'll install cuda pytorch, I'll keep you updated with the results, thank you for your help : )

carcablop commented 1 year ago

Hello @Aml-Hassan-Abd-El-hamid . To work with cuda you must have a CUDA compatible GPU on your system. But from previous comments I've seen, I think you don't have a cuda compatible gpu, so you should install pytorch to work with cpu only, like this: conda install pytorch==1.5.0 torchvision==0.6.0 cpuonly -c pytorch. Then you must change the original code so that it does not use cuda. For example: if you are working inside a code editor like visual studio code, you can search for the option "find in files" and search for the word "cuda". There you will get all the files where the word 'cuda' appears. For example, you can get torch.cuda.LongTensor, you must change it to torch.LongTensor. You must define the device to CPU at the beginning of the code, it can be after the imports device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') and when we are going to load the model, the command model.cuda() should be changed tomodel.to(device). ('device' is the one you defined above). I hope this helps. I recommend you create an environment again with the packages installed correctly and specify the versions of each package as indicated in the documentation. This to avoid future issues of incompatibilities between packages.

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @carcablop, thank you very much for your guidance, I was already installing pytorch using: conda install pytorch==1.5.0 cpuonly -c pytorch also, I searched for every 'cuda' in the code and I deleted it or switched it the device, here's what I've changed: torch.cuda.LongTensor -->torch.LongTensor model.cuda--> model.to(device) best_model = torch.load('saved_models/model_ppb_3922_Tue_Dec_22_22-23-22_2020_'+'54'+'.pt') --> best_model = torch.load('saved_models/model_ppb_3922_Tue_Dec_22_22-23-22_2020_'+'54'+'.pt',map_location=torch.device(device)) And all the cells ran just fine expert for the predict cell with the following code:

remain_pred_list = eval(model, remained_df)
remained_df['Predicted_values'] = remain_pred_list
remained_df

I checked the code inside the eval function and tried to turn it into a CPU friendly one, and that's the eval code now:

def eval(model, dataset):
    model.to(device).eval()
#    eval_MAE_list = []
#    eval_MSE_list = []
#    y_val_list = []
    y_pred_list = []
    valList = np.arange(0,dataset.shape[0])
    batch_list = []
    for i in range(0, dataset.shape[0], batch_size):
        batch = valList[i:i+batch_size]
        batch_list.append(batch)
    for counter, eval_batch in enumerate(batch_list):
        batch_df = dataset.loc[eval_batch,:]
        smiles_list = batch_df.cano_smiles.values
#         print(batch_df)
#        y_val = batch_df[tasks[0]].values

        x_atom, x_bonds, x_atom_index, x_bond_index, x_mask, smiles_to_rdkit_list = get_smiles_array(smiles_list,feature_dicts)
        atoms_prediction, mol_prediction = model(torch.Tensor(x_atom).to(device),torch.Tensor(x_bonds).to(device),torch.LongTensor(x_atom_index).to(device),torch.LongTensor(x_bond_index).to(device),torch.Tensor(x_mask).to(device))
#        MAE = F.l1_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')
#        MSE = F.mse_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')
#         print(x_mask[:2],atoms_prediction.shape, mol_prediction,MSE)
#        y_val_list.extend(y_val)
        y_pred_list.extend(np.array(mol_prediction.data.squeeze().cpu().numpy()))

#        eval_MAE_list.extend(MAE.data.squeeze().cpu().numpy())
#        eval_MSE_list.extend(MSE.data.squeeze().cpu().numpy())
#    r2 = r2_score(y_val_list,y_pred_list)
#    pr2 = scipy.stats.pearsonr(y_val_list,y_pred_list)[0]
    return y_pred_list

But still I got the same error that I've mentioned earlier:

 in 
----> 1 remain_pred_list = eval(model, remained_df)
      2 remained_df['Predicted_values'] = remain_pred_list
      3 remained_df

 in eval(model, dataset)
     54 
     55         x_atom, x_bonds, x_atom_index, x_bond_index, x_mask, smiles_to_rdkit_list = get_smiles_array(smiles_list,feature_dicts)
---> 56         atoms_prediction, mol_prediction = model(torch.Tensor(x_atom),torch.Tensor(x_bonds),torch.LongTensor(x_atom_index),torch.LongTensor(x_bond_index),torch.Tensor(x_mask))
     57 #        MAE = F.l1_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')
     58 #        MSE = F.mse_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')

[~/anaconda3/envs/IDL/lib/python3.7/site-packages/torch/nn/modules/module.py](https://file+.vscode-resource.vscode-cdn.net/home/aml/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/~/anaconda3/envs/IDL/lib/python3.7/site-packages/torch/nn/modules/module.py) in __call__(self, *input, **kwargs)
    548             result = self._slow_forward(*input, **kwargs)
    549         else:
--> 550             result = self.forward(*input, **kwargs)
    551         for hook in self._forward_hooks.values():
    552             hook_result = hook(self, input, result)

[~/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/AttentiveFP/AttentiveLayers.py](https://file+.vscode-resource.vscode-cdn.net/home/aml/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/~/anaconda3/envs/IDL-PPBot/IDL-Repo/IDL-PPBopt/Code/AttentiveFP/AttentiveLayers.py) in forward(self, atom_list, bond_list, atom_degree_list, bond_degree_list, atom_mask)
     48         attend_mask[attend_mask != mol_length-1] = 1
     49         attend_mask[attend_mask == mol_length-1] = 0
---> 50         attend_mask = attend_mask.type(torch.FloatTensor).unsqueeze(-1)
     51 
     52         softmax_mask = atom_degree_list.clone()

RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason.  The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols.  You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.
Aml-Hassan-Abd-El-hamid commented 1 year ago

Also, I used lspci | grep ' VGA ' | cut -d" " -f 1 | xargs -i lspci -v -s {} to check my GPU and that's what I got:

00:02.0 VGA compatible controller: Intel Corporation HD Graphics 530 (rev 06) (prog-if 00 [VGA controller])
    DeviceName: Onboard IGD
    Subsystem: Hewlett-Packard Company HD Graphics 530
    Flags: bus master, fast devsel, latency 0, IRQ 129
    Memory at e3000000 (64-bit, non-prefetchable) [size=16M]
    Memory at 40000000 (64-bit, prefetchable) [size=256M]
    I/O ports at 6000 [size=64]
    Expansion ROM at 000c0000 [virtual] [disabled] [size=128K]
    Capabilities: <access denied>
    Kernel driver in use: i915
    Kernel modules: i915

01:00.0 VGA compatible controller: NVIDIA Corporation GM107GLM [Quadro M1000M] (rev a2) (prog-if 00 [VGA controller])
    Subsystem: Hewlett-Packard Company GM107GLM [Quadro M1000M]
    Flags: bus master, fast devsel, latency 0, IRQ 255
    Memory at e4000000 (32-bit, non-prefetchable) [size=16M]
    Memory at a0000000 (64-bit, prefetchable) [size=256M]
    Memory at b0000000 (64-bit, prefetchable) [size=32M]
    I/O ports at 3000 [disabled] [size=128]
    Expansion ROM at e5080000 [disabled] [size=512K]
    Capabilities: <access denied>
    Kernel modules: nvidiafb, nouveau

I thought because the last one is NVIDIA, that I could install cuda 😅

carcablop commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid Are all these the changes that you made? It seems that the error is because somewhere in the code it is still using cuda. I remember that I made more changes than the ones you mentioned. . Please can you upload this code that you currently have to your repository and share the link with us. This way we can see this better and help you.

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @carcablop That's a link to the file that I changed code in: https://github.com/Aml-Hassan-Abd-El-hamid/IDL-PPBopt/blob/main/Code/IDL-PPBopt.ipynb

carcablop commented 1 year ago

Hello @Aml-Hassan-Abd-El-hamid

In this line of the code, LINE 152 of the IDL-PPBopt. : https://github.com/Aml-Hassan-Abd-El-hamid/IDL-PPBopt/commit/a94b42a20fc879ed670e9a2c16812a67c1b39705#diff-29efb89b56ac68bfed1c0beb3505e731a289471ed8eac9914933340bb05c4c61R152

I see that you have added ".to(device)" to the tensor types, remove everything from that ".to(device)" line. You just had to do the following: Whatever: torch.cuda.LongTensor(x_atom_index) change it to : torch.LongTensor(x_atom_index), don't add the .to(device). In the documentation here: https://pytorch.org/docs/stable/tensors.html. There you find the difference to define the tensor types to work on CPU or GPU.

I hope to make myself understood. The line 152 that you have modified before should look like this:

atoms_prediction, mol_prediction = model(torch.Tensor(x_atom),torch.Tensor(x_bonds),torch.LongTensor(x_atom_index),torch.LongTensor(x_bond_index),torch.Tensor(x_mask))\n",

Aml-Hassan-Abd-El-hamid commented 1 year ago

ok, thank you @carcablop I also did some changes in https://github.com/Aml-Hassan-Abd-El-hamid/IDL-PPBopt/blob/main/Code/AttentiveFP/AttentiveLayers_viz.py and in https://github.com/Aml-Hassan-Abd-El-hamid/IDL-PPBopt/blob/main/Code/AttentiveFP/AttentiveLayers.py and removed the .to(device) but still having the same error :

RuntimeError                              Traceback (most recent call last)
 in 
----> 1 remain_pred_list = eval(model, remained_df)
      2 remained_df['Predicted_values'] = remain_pred_list
      3 remained_df
      4 

 in eval(model, dataset)
     54 
     55         x_atom, x_bonds, x_atom_index, x_bond_index, x_mask, smiles_to_rdkit_list = get_smiles_array(smiles_list,feature_dicts)
---> 56         atoms_prediction, mol_prediction = model(torch.Tensor(x_atom).to(device),torch.Tensor(x_bonds).to(device),torch.LongTensor(x_atom_index).to(device),torch.LongTensor(x_bond_index).to(device),torch.Tensor(x_mask).to(device))
     57 #        MAE = F.l1_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')
     58 #        MSE = F.mse_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')

[~/anaconda3/envs/IDL-normal_pytorch/lib/python3.7/site-packages/torch/nn/modules/module.py](https://file+.vscode-resource.vscode-cdn.net/home/aml/Desktop/IDL-PPBopt-main/Code/~/anaconda3/envs/IDL-normal_pytorch/lib/python3.7/site-packages/torch/nn/modules/module.py) in __call__(self, *input, **kwargs)
    548             result = self._slow_forward(*input, **kwargs)
    549         else:
--> 550             result = self.forward(*input, **kwargs)
    551         for hook in self._forward_hooks.values():
    552             hook_result = hook(self, input, result)

[~/Desktop/IDL-PPBopt-main/Code/AttentiveFP/AttentiveLayers.py](https://file+.vscode-resource.vscode-cdn.net/home/aml/Desktop/IDL-PPBopt-main/Code/~/Desktop/IDL-PPBopt-main/Code/AttentiveFP/AttentiveLayers.py) in forward(self, atom_list, bond_list, atom_degree_list, bond_degree_list, atom_mask)
     48         attend_mask[attend_mask != mol_length-1] = 1
     49         attend_mask[attend_mask == mol_length-1] = 0
...
---> 50         attend_mask = attend_mask.type(torch.FloatTensor).unsqueeze(-1)
     51 
     52         softmax_mask = atom_degree_list.clone()

RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason.  The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols.  You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.
Aml-Hassan-Abd-El-hamid commented 1 year ago

@carcablop Also I checked the rest of the python files of that repo for a "cuda" and I didn't find anything

carcablop commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid But in the log you share of the error, I see that line 56 you are still using the .to(device). Are you sure that the changes are being made?

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @carcablop thank you very much for taking the time to help me : ) That was my mistake, I just shared the error message from before deleting to(device) because the error didn't change, you can see my most resent error below:

untimeError                              Traceback (most recent call last)
 in 
----> 1 remain_pred_list = eval(model, remained_df)
      2 remained_df['Predicted_values'] = remain_pred_list
      3 remained_df
      4 

 in eval(model, dataset)
     54 
     55         x_atom, x_bonds, x_atom_index, x_bond_index, x_mask, smiles_to_rdkit_list = get_smiles_array(smiles_list,feature_dicts)
---> 56         atoms_prediction, mol_prediction = model(torch.Tensor(x_atom),torch.Tensor(x_bonds),torch.LongTensor(x_atom_index),torch.LongTensor(x_bond_index),torch.Tensor(x_mask))
     57 #        MAE = F.l1_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')
     58 #        MSE = F.mse_loss(mol_prediction, torch.Tensor(y_val).view(-1,1), reduction='none')

[~/anaconda3/envs/IDL-normal_pytorch/lib/python3.7/site-packages/torch/nn/modules/module.py](https://file+.vscode-resource.vscode-cdn.net/home/aml/Desktop/IDL-PPBopt-main/Code/~/anaconda3/envs/IDL-normal_pytorch/lib/python3.7/site-packages/torch/nn/modules/module.py) in __call__(self, *input, **kwargs)
    548             result = self._slow_forward(*input, **kwargs)
    549         else:
--> 550             result = self.forward(*input, **kwargs)
    551         for hook in self._forward_hooks.values():
    552             hook_result = hook(self, input, result)

[~/Desktop/IDL-PPBopt-main/Code/AttentiveFP/AttentiveLayers.py](https://file+.vscode-resource.vscode-cdn.net/home/aml/Desktop/IDL-PPBopt-main/Code/~/Desktop/IDL-PPBopt-main/Code/AttentiveFP/AttentiveLayers.py) in forward(self, atom_list, bond_list, atom_degree_list, bond_degree_list, atom_mask)
     48         attend_mask[attend_mask != mol_length-1] = 1
     49         attend_mask[attend_mask == mol_length-1] = 0
...
---> 50         attend_mask = attend_mask.type(torch.FloatTensor).unsqueeze(-1)
     51 
     52         softmax_mask = atom_degree_list.clone()

RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason.  The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols.  You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.
Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @carcablop, I think that I managed to get cuda installed on my machine, I followed the instruction to setup Nvidia from that article, and followed this instructions to install cuda I will try now to install cuda on my conda env and use it. Screenshot from 2023-03-18 04-16-46

GemmaTuron commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid ! Do you have a Cuda device in your system that you can use? Most laptops do not and we need to work with CPU only, which are the changes in the code that @carcablop was mentioning. Let us know if that's the case!

Aml-Hassan-Abd-El-hamid commented 1 year ago

Sorry for the late response @GemmaTuron but I got caught up in some college work -that's my final semester in college which in my college means that I have extra work than usual as at the end of that college year I have to deliver my graduation project, our graduation project is very important for our final graduation and it takes a lot of work and attention so please forgive me for the delays- I checked the graphic cards that I have on my laptop, and as it turned out, I got two, one is Intel and the other is NVIDIA, you can see that below:

aml@aml-HP-ZBook-15-G3:~$ sudo lshw -numeric -C display
[sudo] password for aml: 
  *-display                 
       description: VGA compatible controller
       product: GM107GLM [Quadro M1000M] [10DE:13B1]
       vendor: NVIDIA Corporation [10DE]
       physical id: 0
       bus info: pci@0000:01:00.0
       version: a2
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
       configuration: driver=nvidia latency=0
       resources: irq:130 memory:e4000000-e4ffffff memory:a0000000-afffffff memory:b0000000-b1ffffff ioport:3000(size=128) memory:e5080000-e50fffff
  *-display
       description: VGA compatible controller
       product: HD Graphics 530 [8086:191B]
       vendor: Intel Corporation [8086]
       physical id: 2
       bus info: pci@0000:00:02.0
       logical name: /dev/fb0
       version: 06
       width: 64 bits
       clock: 33MHz
       capabilities: pciexpress msi pm vga_controller bus_master cap_list rom fb
       configuration: depth=32 driver=i915 latency=0 resolution=1920,1080
       resources: irq:129 memory:e3000000-e3ffffff memory:40000000-4fffffff ioport:6000(size=64) memory:c0000-dffff

So I first installed nivadia drivers by following the instructions from that article I then installed cuda following those instructions I checked my cuda version using that command nvidia-smi and that's the output:

+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.30.02              Driver Version: 530.30.02    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  Quadro M1000M                   On | 00000000:01:00.0 Off |                  N/A |
| N/A   43C    P8               N/A /  N/A|   1027MiB /  2048MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      2655      G   /usr/lib/xorg/Xorg                          217MiB |
|    0   N/A  N/A      3011      G   /usr/bin/gnome-shell                         80MiB |
|    0   N/A  N/A      3738      G   ...irefox/2432/usr/lib/firefox/firefox      651MiB |
|    0   N/A  N/A     31245      G   ...sktop/4654/usr/bin/telegram-desktop       19MiB |
|    0   N/A  N/A     47176      G   /snap/vlc/3078/usr/bin/vlc                   24MiB |
+---------------------------------------------------------------------------------------+

I tried to access it through pytorch as the screen that I shared before shows and it seemed to be working fine. That's my first time installing cuda on my machine and I'm not very good with hardware so if there is anything that I got wrong, please let me know

Aml-Hassan-Abd-El-hamid commented 1 year ago

Right After that I tried to get cuda to work with my conda env but I had some troubles until I found that tutriol, I created the following yml file and created a new conda env using it and that command conda env create --name hey_cuda -f environment.yml:

name: null

channels:
  - pytorch
  - conda-forge
  - defaults

dependencies:
  - cudatoolkit=10.1
  - pip=20.0
  - python=3.7
  - pytorch=1.5
  - torchvision=0.6

and right after that I tried to access cuda through pytorch and it seemed to be working fine, you can see a screenshot from that below: Screenshot from 2023-03-21 04-45-22

right after that, I started installing the rest of the required packages, and then I tried to run the code using vs code, I started getting an error that "kernal hey_cuda is not usable" I copied the Juptyer log and I'll attach to that comment. I tried different things starting from installing juptyer notebook using pip, I tried conda install ipykernel and conda install -n hey_cuda ipykernel --update-deps --force-reinstall and still didn't work so can you please help me error.txt

GemmaTuron commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid

No problem, as I mentioned in the Slack channel we still have time ad we are aware you have other commitments, i just regularly check in on all your work. At this moment I can't provide specific support for setting up the torch on NVIDIA, the permissions for each system are a bit different and it's difficult to point you out to a specific solution, I'm sorry! I suggest, to ensure you have time to complete the application, to either:

Aml-Hassan-Abd-El-hamid commented 1 year ago

Thank you @GemmaTuron for your understanding and guidance, I 'll take your advice and I will try to explore a new model or try and run the current one on CPU only. If anything new popped up regarding the Cuda situation, I will let you know.

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @GemmaTuron : Here's my update regarding my work through the last few days: I worked on 2 things: 1- exploring a new model. 2- Trying to fix the cuda error.

1- I installed the STOUT and thanks god it was a smooth experience, I only ran into 1 error during the installation, The error happened while I was running that command conda install -c decimer stout-pypi, I got the following error message:

Collecting package metadata (current_repodata.json): done                                                               
Solving environment: failed with initial frozen solve. Retrying with flexible solve.                                    
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.             
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: / 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                                                                  

UnsatisfiableError: The following specifications were found to be incompatible with each other:

Output in format: Requested package -> Available versionsThe following specifications were found to be incompatible with your system:

  - feature:/linux-64::__glibc==2.35=0
  - feature:|@/linux-64::__glibc==2.35=0

Your installed version is: 2.35

I then ran that command : pip install STOUT-pypi inside the same conda env that the error happened in, and it ran successfully :) I then ran that sample:

from STOUT import translate_forward, translate_reverse

# SMILES to IUPAC name translation

SMILES = "CN1C=NC2=C1C(=O)N(C(=O)N2C)C"
IUPAC_name = translate_forward(SMILES)
print("IUPAC name of "+SMILES+" is: "+IUPAC_name)

# IUPAC name to SMILES translation

IUPAC_name = "1,3,7-trimethylpurine-2,6-dione"
SMILES = translate_reverse(IUPAC_name)
print("SMILES of "+IUPAC_name+" is: "+SMILES)

and got the right results with no error.

2- Regarding the cuda situation, I finally managed to run the notebook from IDL-PPBopt with no errors :), I also made a yml file that can help anyone who needs to install IDL-PPBopt model in the future and have a cuda device on their machine:

name: conda_cuda3

channels:
  - pytorch
  - conda-forge
  - defaults
  - rdkit
  - anaconda
dependencies:
  - cudatoolkit=10.1
  - pip=20.0
  - python=3.7
  - pytorch=1.5
  - torchvision=0.6
  - matplotlib=3.3.0
  - numpy=1.18
  - pandas=1.1.3
  - rdkit=2020.03
  - scikit-learn
  - openbabel=2.4.1
  - scipy
  - cairosvg
  - jupyter 

I use the command conda env create -f environment.yml to create my env using the yml file and I don't have to install any more packages, I hope that file could be helpful for someone.

Aml-Hassan-Abd-El-hamid commented 1 year ago

Currently, I'm working on running the predictions from the Essential medicine list and I'll compare the results with the Ersilia models.

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @GemmaTuron, I followed the instructions that were provided in the IDL-PPBopt repo, to get the prediction for the Essential Medicines List and only had to change a few things:

I wrote the predictions into that file : prediction.csv

Those predictions indicate the plasma protein binding (PPB) property, I looked that term up and found those 2 articles kinda understandable for me : wiki definition of the term and sygnaturediscovery article. the PPB property is the degree to which a drug can get attached to the proteins within the blood, and that property may affect the efficiency of the drug, it ranges between 0 and 1, and according to the signature discovery article, PPB isn't key decision-making in evaluating a drug, but it could be used along with other metrics and properties.

But as you can see from the image below, IDL-PPBopt doesn't only predict the PPB property, it also optimizes the PPB, and if you took a look at their notebook, that happens by following those steps: 1 - Predicting the PPB values. 2 - Getting the atoms' attention weights. 3 - Identifying the Privileged Substructure for each molecule. The last step is expected to take a while to run on my machine since It took about 12 minutes to run while I was using a file consisting of 5 rows, and the Essential Medicines List is 444 rows, so if that wasn't a necessary step, please let me know.

images_medium_ci2c00297_0012

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hey @GemmaTuron, I fetched the model from ersilia hub using that command: ersilia fetch eos22io and it was fetched successfully, Then I ran that command ersilia serve eos22io and finally tried to get the prediction using that command : ersilia api predict -i "Essential Medicines List.csv" -o output.csv but I got the following error:

Traceback (most recent call last):
  File "/home/aml/anaconda3/envs/ersi/bin/ersilia", line 33, in <module>
    sys.exit(load_entry_point('ersilia', 'console_scripts', 'ersilia')())
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/bentoml/cli/click_utils.py", line 138, in wrapper
    return func(*args, **kwargs)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/bentoml/cli/click_utils.py", line 115, in wrapper
    return_value = func(*args, **kwargs)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/bentoml/cli/click_utils.py", line 99, in wrapper
    return func(*args, **kwargs)
  File "/home/aml/ersilia/ersilia/cli/commands/api.py", line 38, in api
    api_name=api_name, input=input, output=output, batch_size=batch_size
  File "/home/aml/ersilia/ersilia/core/model.py", line 343, in api
    api_name=api_name, input=input, output=output, batch_size=batch_size
  File "/home/aml/ersilia/ersilia/core/model.py", line 357, in api_task
    for r in result:
  File "/home/aml/ersilia/ersilia/core/model.py", line 184, in _api_runner_iter
    for result in api.post(input=input, output=output, batch_size=batch_size):
  File "/home/aml/ersilia/ersilia/serve/api.py", line 320, in post
    input=unique_input, output=None, batch_size=batch_size
  File "/home/aml/ersilia/ersilia/serve/api.py", line 290, in post_unique_input
    or not schema.is_h5_serializable(api_name=self.api_name)
  File "/home/aml/ersilia/ersilia/serve/schema.py", line 89, in is_h5_serializable
    schema = self.get_output_by_api(api_name)
  File "/home/aml/ersilia/ersilia/serve/schema.py", line 86, in get_output_by_api
    return self.schema[api_name]["output"]
KeyError: 'predict'

Could you please help with that?

GemmaTuron commented 1 year ago

as it indicates: KeyError: 'predict' -- you should try without the predict in the CLI, The API depends on the model so maybe this one does not have an api, these should have been indicated at model serving time Also, I'd suggest making a better csv name, without spaces in it, for the input file- will avoid errors

Aml-Hassan-Abd-El-hamid commented 1 year ago

Thank you @GemmaTuron , I took your advise and ran the command ersilia api -i Essential_Medicines_List.csv -o output.csv and here the prediction file

Aml-Hassan-Abd-El-hamid commented 1 year ago

I compared the predictions of the ersilia model and the repo one and those are my notes:

Other than that both outputs seems pretty similar to me.

AhmedYusuff commented 1 year ago

Hey @GemmaTuron, I fetched the model from ersilia hub using that command: ersilia fetch eos22io and it was fetched successfully, Then I ran that command ersilia serve eos22io and finally tried to get the prediction using that command : ersilia api predict -i "Essential Medicines List.csv" -o output.csv but I got the following error:

Traceback (most recent call last):
  File "/home/aml/anaconda3/envs/ersi/bin/ersilia", line 33, in <module>
    sys.exit(load_entry_point('ersilia', 'console_scripts', 'ersilia')())
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/bentoml/cli/click_utils.py", line 138, in wrapper
    return func(*args, **kwargs)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/bentoml/cli/click_utils.py", line 115, in wrapper
    return_value = func(*args, **kwargs)
  File "/home/aml/anaconda3/envs/ersi/lib/python3.7/site-packages/bentoml/cli/click_utils.py", line 99, in wrapper
    return func(*args, **kwargs)
  File "/home/aml/ersilia/ersilia/cli/commands/api.py", line 38, in api
    api_name=api_name, input=input, output=output, batch_size=batch_size
  File "/home/aml/ersilia/ersilia/core/model.py", line 343, in api
    api_name=api_name, input=input, output=output, batch_size=batch_size
  File "/home/aml/ersilia/ersilia/core/model.py", line 357, in api_task
    for r in result:
  File "/home/aml/ersilia/ersilia/core/model.py", line 184, in _api_runner_iter
    for result in api.post(input=input, output=output, batch_size=batch_size):
  File "/home/aml/ersilia/ersilia/serve/api.py", line 320, in post
    input=unique_input, output=None, batch_size=batch_size
  File "/home/aml/ersilia/ersilia/serve/api.py", line 290, in post_unique_input
    or not schema.is_h5_serializable(api_name=self.api_name)
  File "/home/aml/ersilia/ersilia/serve/schema.py", line 89, in is_h5_serializable
    schema = self.get_output_by_api(api_name)
  File "/home/aml/ersilia/ersilia/serve/schema.py", line 86, in get_output_by_api
    return self.schema[api_name]["output"]
KeyError: 'predict'

Could you please help with that?

Hi @Aml-Hassan-Abd-El-hamid. This could be because you are using a wrong API.

Can you check the API name that came up after serving the Model?

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hey @AhmedYusuff, I checked that and the only available API is run.

AhmedYusuff commented 1 year ago

Hi @Aml-Hassan-Abd-El-hamid. Use this command to get predictions.

ersilia api run -i Essential Medicines List.csv -o output.csv.

Make sure the csv file you are running prediction on is in your working directory.

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hey @AhmedYusuff , I tried that and also ersilia api -i Essential_Medicines_List.csv -o output.csv and they both gave me the same results.

Aml-Hassan-Abd-El-hamid commented 1 year ago

Hi @GemmaTuron, For my first model, I found the following one very interesting:

Paper Tiltle:

Drug Repurposing for Rare Orphan Diseases Using Machine Learning Techniques

Why that Paper:

That paper works on drug repurposing which is a way to find new uses for already existing drugs and accelerate the drug discovery process. Drug repurposing got multiple advantages over traditional drug discovery, It is working with compounds with well-characterized pharmacology and safety profiles, costs less than the traditional discovery ways and also got a reduced timeline. And according to this article and many others, Drug repurposing can help greatly with discovering treatments for rare diseases and help patients with unmet medical needs, the article mention an example for that: Pfizer’s Rapamune® (sirolimus) that was approved to prevent organ transplant rejection, but also became the first approved drug for the rare genetic lung disease lymphagioleiomyomatosis.

How it works:

I haven't yet found a GitHub repo for that paper, but after reading through the paper, I can see that they are using the Random Forest model which is already implemented in multiple frameworks.

Paper Link

Aml-Hassan-Abd-El-hamid commented 1 year ago

By the way, I have a question, I saw a model that I liked but it requires a large GPU power to run so I ignored it, should I have reported it first? @GemmaTuron

AhmedYusuff commented 1 year ago

Hey @AhmedYusuff , I tried that and also ersilia api -i Essential_Medicines_List.csv -o output.csv and they both gave me the same results.

After Serving your Model, can you paste a screenshot of what you got?

Aml-Hassan-Abd-El-hamid commented 1 year ago

Here's a screenshot @AhmedYusuff Screenshot from 2023-03-25 05-29-36

AhmedYusuff commented 1 year ago

Here's a screenshot @AhmedYusuff Screenshot from 2023-03-25 05-29-36

Run a test prediction on simple string. ersilia -v api run -i "CCC".

I just tested the model now and it was successfull.

27