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

Embedding libcmaes #202

Open MRebolle opened 4 years ago

MRebolle commented 4 years ago

Hello,

I want to use libcmaes (main reason is because it is written in c++ which I need) as an optimizer for robot controllers. For this I need to embed libcmaes into a large robot simulator framework that is written in python3.7. Is it possible to do that? so far my tries of including all the files into the simulator and modifying the CMakelist.txt have failed but I am not sure I am doing everything correctly since this is not my are of expertise. Is this even the correct approach?

beniz commented 4 years ago

Hi, first make sure you are building and using the Python bindings by following instructions from https://github.com/beniz/libcmaes#python-bindings

Additionnally, please make sure to look at the Python documentation here: https://github.com/beniz/libcmaes/wiki/Python-bindings

If for some reason you are having troubles with the bindings and Python 3.7, share all details (build logs, code using the bindings, errors, ...).

Good luck with your project, and thanks for using libcmaes !

MRebolle commented 4 years ago

I followed the instructions for MacOSx and after finishing with apparently no problem I cannot run the last test /opt/local/bin/python ptest_bounds.py The error I get is:

Traceback (most recent call last): File "ptest_bounds.py", line 1, in <module> import lcmaes ModuleNotFoundError: No module named 'lcmaes'

I am wondering if the command should be with python3 instead of python. All the libraries needed libraries are installed (including boost).

I re-run the ./configure step and this is my terminal ouput: p058171:libcmaes tarigarma$ ./configure --with-eigen3-include=/opt/local/include/eigen3 CXXFLAGS="-I/opt/local/include -O3 -I/opt/local//Library/Frameworks/Python.framework/Versions/2.7/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include" LDADD=-lgflags LDFLAGS="-L/opt/local/lib" BOOST_LDFLAGS=-L/opt/local/lib --enable-python PYTHON=/opt/local/bin/python PYTHON_EXTRA_LDFLAGS="-u _PyMac_Error" LDFLAGS="-L/opt/local/lib python-config --ldflags python-config --libs" configure: libcmaes 0.9.5 checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... ./install-sh -c -d checking for gawk... no checking for mawk... no checking for nawk... no checking for awk... awk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking build system type... x86_64-apple-darwin17.7.0 checking host system type... x86_64-apple-darwin17.7.0 checking for clang++... clang++ checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether clang++ accepts -g... yes checking for clang++ option to accept ISO C89... unsupported checking whether clang++ understands -c and -o together... yes checking whether make supports the include directive... yes (GNU style) checking dependency style of clang++... gcc3 checking for clang++... clang++ checking whether we are using the GNU C++ compiler... yes checking whether clang++ accepts -g... yes checking dependency style of clang++... gcc3 checking how to print strings... printf checking for a sed that does not truncate output... /usr/bin/sed checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for fgrep... /usr/bin/grep -F checking for ld used by clang++... /Library/Developer/CommandLineTools/usr/bin/ld checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 196608 checking how to convert x86_64-apple-darwin17.7.0 file names to x86_64-apple-darwin17.7.0 format... func_convert_file_noop checking how to convert x86_64-apple-darwin17.7.0 file names to toolchain format... func_convert_file_noop checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for ar... ar checking for archiver @FILE support... no checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from clang++ object... ok checking for sysroot... no checking for a working dd... /bin/dd checking how to truncate binary pipes... /bin/dd bs=4096 count=1 checking for mt... no checking if : is a manifest tool... no checking for dsymutil... dsymutil checking for nmedit... nmedit checking for lipo... lipo checking for otool... otool checking for otool64... no checking for -single_module linker flag... yes checking for -exported_symbols_list linker flag... yes checking for -force_load linker flag... yes checking how to run the C preprocessor... clang++ -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if clang++ supports -fno-rtti -fno-exceptions... yes checking for clang++ option to produce PIC... -fno-common -DPIC checking if clang++ PIC flag -fno-common -DPIC works... yes checking if clang++ static flag -static works... no checking if clang++ supports -c -o file.o... yes checking if clang++ supports -c -o file.o... (cached) yes checking whether the clang++ linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes checking dynamic linker characteristics... darwin17.7.0 dyld checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking how to run the C++ preprocessor... clang++ -E checking for ld used by clang++... /Library/Developer/CommandLineTools/usr/bin/ld checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no checking whether the clang++ linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes checking for clang++ option to produce PIC... -fno-common -DPIC checking if clang++ PIC flag -fno-common -DPIC works... yes checking if clang++ static flag -static works... no checking if clang++ supports -c -o file.o... yes checking if clang++ supports -c -o file.o... (cached) yes checking whether the clang++ linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes checking dynamic linker characteristics... darwin17.7.0 dyld checking how to hardcode library paths into programs... immediate checking whether clang++ supports C++11 features by default... no checking whether clang++ supports C++11 features with -std=gnu++11... yes checking for eigen3... checking for /opt/local/include/eigen3/Eigen... no checking for /usr/local/include/eigen3... yes checking Eigen/Dense usability... yes checking Eigen/Dense presence... yes checking for Eigen/Dense... yes checking for main in -lgflags... yes checking for main in -lglog... no checking gtest/gtest.h usability... no checking gtest/gtest.h presence... no checking for gtest/gtest.h... no checking for python... /opt/local/bin/python checking for a version of Python >= '2.1.0'... yes checking for the distutils Python package... yes checking for Python include path... -I/opt/local/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m checking for Python library path... -L/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib -lpython3.7m checking for Python site-packages path... /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages checking python extra libraries... -ldl -framework CoreFoundation checking python extra linking flags... -u _PyMac_Error checking consistency of all components of python development environment... yes checking whether the Boost::Python library is available... yes checking for exit in -lboost_python... no checking for exit in -lboost_python... (cached) no configure: error: boost python required for building the python wrapper p058171:libcmaes tarigarma$ make /Library/Developer/CommandLineTools/usr/bin/make all-recursive Making all in src make[2]: Nothing to be done for all'. Making all in tests make[2]: Nothing to be done forall'. Making all in examples make[2]: Nothing to be done for all'. make[2]: Nothing to be done forall-am'.

beniz commented 4 years ago

It seems you are missing boost_python library. Have you followed the section https://github.com/beniz/libcmaes/wiki/Building-libcmaes-on-Mac-OSX#build-python-bindings ?

MRebolle commented 4 years ago

The steps I followed from the link for the python bindings where these:

configure and compile: ./configure --with-eigen3-include=/opt/local/include/eigen3 CXXFLAGS="-I/opt/local/include -O3 -I/opt/local//Library/Frameworks/Python.framework/Versions/2.7/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include" LDADD=-lgflags LDFLAGS="-L/opt/local/lib" BOOST_LDFLAGS=-L/opt/local/lib --enable-python PYTHON=/opt/local/bin/python PYTHON_EXTRA_LDFLAGS="-u _PyMac_Error" LDFLAGS="-L/opt/local/libpython-config --ldflags`python-config --libs" make **run:** cd python export DYLD_LIBRARY_PATH=../src/.libs /opt/local/bin/python ptest_bounds.py `

If I look in my system I see the boost libraries

$ brew list | grep "boost" boost boost-python boost-python3 boost@1.60