openmmexampleplugin icon indicating copy to clipboard operation
openmmexampleplugin copied to clipboard

Python wrapper error

Open altnossum opened this issue 2 years ago • 9 comments

openmm built like:

$ conda install -c conda-forge cmake make cython swig fftw doxygen numpy
$ git clone https://github.com/openmm/openmm.git
$ cd openmm
$ mkdir build
$ cd build
$ ccmake ..
configure, CPU only build (unset CUDA and OpenCL options), generate

$ make
$ sudo make install
$ make test 
#all good
$ make PythonInstall   #conda doesn't require sudo
$ python  -m openmm.testInstallation   
#all good

openmmexampleplugin built like:

$ git close https://github.com/openmm/openmmexampleplugin.git
$ cd openmmexampleplugin
$ mkdir build
$ cd build
$ ccmake .. 
configure, CPU only build (unset CUDA and OpenCL options), other options already correct, generate
$ make
$ sudo make install
$ make test 
#all good
$ make PythonInstall

in ipython session:

In [1]:  from openmm import system
In [2]:  from exampleplugin import ExampleForce

giving following error:

ImportError                               Traceback (most recent call last) 
ImportError                               Traceback (most recent call last)                                                                                                                                                                  Input In [2], in <cell line: 1>()
----> 1 from openmmtorch import TorchForce

File ~/miniconda3/envs/torch_openmm/lib/python3.9/site-packages/openmmtorch.py:15, in <module>
       13     from . import _openmmtorch
       14 else:
---> 15     import _openmmtorch
       17 try:
       18     import builtins as __builtin__

ImportError: libOpenMMTorch.so: cannot open shared object file: No such file or directory           

I'm working on ubuntu 18.04.6 LTS clean miniconda python3.9 environment. Looks like swig is failing, don't know if this is an easy fix or I'm doing something wrong.

altnossum avatar Mar 22 '22 14:03 altnossum

The error is importing openmmtorch, not the example plugin. According to the stack trace, you're executing the line

from openmmtorch import TorchForce

Where is libOpenMMTorch.so installed?

peastman avatar Mar 22 '22 15:03 peastman

Apologies, I copied across the wrong stack trace. I was getting the same issue with both openmm/openmmtorch and openmm/openmmexampleplugin . The stack trace for exampleplugin was identical (with the the correct paths and library names). I however somehow fixed the issue by going into the build/python folder and running:

$ python setup.py clean --all
$ cd ..
$ make PythonInstall
#removing the python build and install commands from the python/CMakeLists.txt file
$ cd python
$ python setup.py build
$ python setup.py install

Honestly don't know why that worked, seeing as that is exactly what CMakeLists.txt does. Perhaps the "python setup.py clean --all" removed something that was causing an issue. If the issue can't be reproduced then I imagine there was some corruption on my side of things.

altnossum avatar Mar 22 '22 16:03 altnossum

Maybe? I'm glad it's working, though it's always a little disturbing when something starts working and you don't know why. Let us know if the error reappears.

peastman avatar Mar 22 '22 17:03 peastman

I fixed the same issue by copying the libExamplePlugin.so to my miniconda lib directory (~/miniconda3/envs/<env_name>/lib)

SCMusson avatar Mar 24 '22 12:03 SCMusson

When you build it, what is CMAKE_INSTALL_PREFIX set to? If it's set correctly, the library should get installed there automatically.

peastman avatar Mar 24 '22 16:03 peastman

For me CMAKE_INSTALL_PREFIX was /usr/local/openmm, and that's the folder that I was copying from into the environment lib folder. I thought that importing openmm first would allow the plugin to see that folder so Im not sure what the issue is.

SCMusson avatar Mar 25 '22 11:03 SCMusson

The important thing is that CMAKE_INSTALL_PREFIX is set to the same value when building OpenMM and when building the plugin. If you set it to ~/miniconda3/envs/<env_name> for one and to /usr/local/openmm for the other, it won't find the library.

peastman avatar Mar 25 '22 16:03 peastman

Both openmm installation and exampleplugin have identical CMAKE_INSTALL_PREFIX. the lib*.so file is being put in the /usr/local/openmm/lib folder but the python wrapper can't seem to find it. I assumed from python import openmm would enable the modules to find the /usr/local/openmm/lib directory but alas that doesn't seem to be the case.

SCMusson avatar Mar 29 '22 16:03 SCMusson

What is the output of the following?

import openmm
print(openmm.version.openmm_library_path)

That prints the library path that was set when OpenMM was installed. Perhaps you have two copies of OpenMM, one built from source and one installed with conda?

peastman avatar Mar 29 '22 16:03 peastman