CMA-ES / libcmaes

libcmaes is a multithreaded C++11 library with Python bindings for high performance blackbox stochastic optimization using the CMA-ES algorithm for Covariance Matrix Adaptation Evolution Strategy
Other
321 stars 78 forks source link

ModuleNotFoundError after cmake #241

Closed AtWillTeam closed 1 year ago

AtWillTeam commented 1 year ago

Hello, I have successfully used cmake .. -DCMAKE_INSTALL_PREFIX=~/.local/ -DLIBCMAES_BUILD_PYTHON=ON to build the Python bindings. But after make install and exporting the LD_LIBRARY_PATH, the ptest.py reports ModuleNotFoundError: no module named 'lcmaes'. The processes look successful except some unused parameter warnings in make install. I wonder what causes this issue and how to solve it. Thanks.

beniz commented 1 year ago

Try copying the build/python/lcmaes.so file into the dir that has ptest.py and try again. If it works, then you'll have to figure how to load it from another dir.

AtWillTeam commented 1 year ago

I copied it into the python/ dir where the ptest.py is then an ImportError occur: /lib/x86_64-linux-gnu/libboost_python310.so.1.74.0: undefined symbol: PyCMethod_New.

AtWillTeam commented 1 year ago

Update: I find the reason, the python version I use is 3.8 while the libboost works for 3.10. I create a python3.10 environment and it works without error. The problem is fixed! Now I will figure how to load it in other dir.

AtWillTeam commented 1 year ago

I wonder if it is possible to control the stop criteria in Python, e.g., stop when the fitness reach a value or the evaluation budget exhausted?

beniz commented 1 year ago

Have you looked at the set_ftarget function (http://beniz.github.io/libcmaes/doc/html/classlibcmaes_1_1Parameters.html#a6ace7e5d230fcf82c70ba2dd3a801f97) as it appears to be hooked via the Python wrapper ?

AtWillTeam commented 1 year ago

Yes, it is exactly what I need. Thanks 👍 👍