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
315 stars 79 forks source link

Prepare for conan package #234

Open phbasler opened 2 years ago

phbasler commented 2 years ago

In preparation for the conan package I added the options to get the necessary dependencies through conan.

If you have installed conan you can use -DLIBCMAES_USE_CONAN=On and cmake will download the matching conan packages of eigen, boost( if LIBCMAES_BUILD_PYTHON = On) and gflags (if LIBCMAES_BUILD_TESTS=On).

While configuring this I saw that the PythonInterp find_package call was deprecated and so I updated it to findpackage(Python3) with the modules. This also allowed me to make the python and t* tests run with ctest. You can now just call ctest in your build directory and the 6 tests run.

Furthermore, we can get rid of the custom FindNumpy and FindEigen module. cmake has it's own find modules for eigen and python.

phbasler commented 2 years ago

I just saw that it still does not compile on windows with mvsc. I convert this PR to a draft until I fixed it as well.

phbasler commented 2 years ago

@beniz It would not compile on windows until I defined an explicit copy ctr for scalar_normal_dist_op. Can you check if this one is ok?

ATM the python tests are failing because the module is not found for the ctest call, but everything compiles. (Only with MVSC, with gcc ctest runs the python test sucessfully)

phbasler commented 2 years ago

@beniz @nikohansen

I found the problem and maybe one of you has an idea. On my fork https://github.com/phbasler/libcmaes/tree/conan-windows I set up some CI to run the unit tests, including the python tests, on windows, mac and ubuntu. Mac and ubuntu work without a problem, but on windows the lcames python module is seperated in two files. One build/python/Release/lcames.pyd and the dll build/src/Release/cmaes.dll. It works there if I copy the cmaes.dll to the directory which contains the .pyd. If I don't copy it, then I get an Import Error because the dll is not found.

What should we do here? Do you have an idea on how to fix it or should we copy it during the cmake call?

Edit: A possible cmake solution to fix this with MVSC using cmake is given in https://github.com/phbasler/libcmaes/commit/bfe0eb46bb75c82498835feed587c39092513427
But it is just copying/installing the cmaes.dll to the python location, so the dll would be in two places.

nikohansen commented 2 years ago

Sorry, I have no idea regarding the windows test setup.

beniz commented 2 years ago

Hi @phbasler I would go for the copy of the DLL is that helps. Thanks for all the work on this!

phbasler commented 2 years ago

@beniz That's how I implemented now. I also fixed a small mistake I introduced with another PR: If you include libcmaes as a subdirectory then the doc target was also created, even if you have one of your one (like I have in https://github.com/phbasler/BSMPT) and then I got a cmake error there. I fixed that with the last commit that the doc target is only created if libcmaes is build as the top project

phbasler commented 1 year ago

@nikohansen @beniz I finished the conan package. You can build it with `conan create conanfile.py --profile=SomeProfile" where SomeProfile is a conan profile with your compiler and settings how you want to build. You need to fill in the author and topics in the conanfile.

beniz commented 1 year ago

@phbasler hello, apologies for missing this, you should put your name in the conan file! I am not familiar with conan, if it works for you, then maybe squash and get ready for a merge!

phbasler commented 1 year ago

@beniz In the meantime conan released v2 with some breaking changes, so we would have to make sure everything still works.

phbasler commented 1 year ago

Seems that there are some changes necessary. I will have a look at it if I have some time to spare, but this may take a while.

phbasler commented 1 month ago

@beniz @nikohansen So after some time I got around to update this PR and now it works with conan 2 If we can go through this PR and you can release a new version, then I can make the official conan recipe