Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python wrapper error #27

Open
altnossum opened this issue Mar 22, 2022 · 9 comments
Open

Python wrapper error #27

altnossum opened this issue Mar 22, 2022 · 9 comments

Comments

@altnossum
Copy link

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.

@peastman
Copy link
Member

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?

@altnossum
Copy link
Author

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.

@peastman
Copy link
Member

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.

@SCMusson
Copy link

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

@peastman
Copy link
Member

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

@SCMusson
Copy link

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.

@peastman
Copy link
Member

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.

@SCMusson
Copy link

SCMusson commented Mar 29, 2022

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.

@peastman
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants