openmm / openmm-torch

OpenMM plugin to define forces with neural networks
185 stars 24 forks source link

Failure to import openmmtorch #127

Closed eva-not closed 11 months ago

eva-not commented 11 months ago

I'm trying to install openmm-torch in a fresh conda environment (Ubuntu 20.04 LTS with CUDA 12.0). When I use the default installation command conda install -c conda-forge openmm-torch and try to import openmmtorch, I get the following error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/eva/anaconda3/envs/openmm-torch/lib/python3.11/site-packages/openmmtorch.py", line 15, in <module> import _openmmtorch ImportError: libtorch_cuda.so: cannot open shared object file: No such file or directory

From the output of conda list, I can see that the installed pytorch is the CPU version cpu_generic_py311h495eaba_0, which probably explains the incompatibility.

If I install openmm-torch and pytorch simultaneously with mamba install pytorch torchvision torchaudio pytorch-cuda=11.8 openmm-torch -c pytorch -c nvidia -c conda-forge and try to import openmmtorch, I get this other error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/eva/anaconda3/envs/openmm-torch/lib/python3.10/site-packages/openmmtorch.py", line 15, in <module> import _openmmtorch ImportError: /home/eva/anaconda3/envs/openmm-torch/lib/python3.10/site-packages/../../libOpenMMTorch.so: undefined symbol: _ZN5torch3jit4loadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3c108optionalINS9_6DeviceEEEb

Is there a way to overcome this? Any help would be greatly appreciated!

peastman commented 11 months ago

You need to remove the extra channels-c pytorch -c nvidia. The builds of PyTorch from the different channels aren't compatible with each other.

sef43 commented 11 months ago

Hi @eva-not

The first import error sounds like https://github.com/openmm/openmm-torch/issues/94

Can you try setting: export CONDA_OVERRIDE_CUDA=12.0 before installing the package from conda-forge

eva-not commented 11 months ago

Thank you both! I managed to install it with: conda install pytorch=2=*cuda* -c conda-forge conda install openmm-torch -c conda-forge

and importing works fine now.