-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
cmaes: Add 0.10.0 #24202
base: master
Are you sure you want to change the base?
cmaes: Add 0.10.0 #24202
Changes from 33 commits
80515f3
a29853a
0198bb0
ab5c602
79f3dda
91724e6
bb9710d
70c7b7b
62b1cea
e45bbab
a8f1be6
2c1c3ab
aef42b4
7f4c46b
6dd4404
cff6a8b
1cc89e8
171eccc
d27837b
95a1ca6
6ca7bc7
4f7ea35
87239b4
209d577
1fa1468
2b34d0f
eb34bdc
b102d9e
ebc0e0b
743b8bb
a0ba9f0
d18682c
ef722e3
9583a7d
33f1c38
f323bcb
025c68d
499f8fb
1434ba5
6d1b59b
b3bee09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
sources: | ||
"0.10.0": | ||
url: "https://github.com/CMA-ES/libcmaes/archive/refs/tags/v0.10.tar.gz" | ||
sha256: "a77fb892654356c5657dd677161b7c67b196dc732cfb77eaca6708abc4f6cffc" | ||
patches: | ||
"0.10.0": | ||
- patch_file: "patches/CompilerOptionsEigen.patch" | ||
Check warning on line 7 in recipes/cmaes/all/conandata.yml GitHub Actions / Lint changed files (YAML files)conandata.yml schema warning
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout | ||
from conan.tools.files import export_conandata_patches, get, rmdir, rm, copy, apply_conandata_patches | ||
import os | ||
|
||
class CmaesConan(ConanFile): | ||
name = "cmaes" | ||
|
||
generators = "CMakeDeps" | ||
|
||
# Optional metadata | ||
license = "LGPLv3" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/CMA-ES/libcmaes" | ||
description = "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" | ||
topics = ("cmaes", "minimization") | ||
|
||
# Binary configuration | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"openmp": [True, False], | ||
"surrog": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"openmp": True, | ||
"surrog": True, | ||
} | ||
|
||
short_paths = True | ||
|
||
def export_sources(self): | ||
export_conandata_patches(self) | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def build_requirements(self): | ||
pass | ||
|
||
def requirements(self): | ||
self.requires("eigen/3.4.0", transitive_headers=True) | ||
if self.options.openmp: | ||
self.requires("llvm-openmp/17.0.6", transitive_headers=True) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
|
||
def layout(self): | ||
cmake_layout(self,src_folder="src") | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["LIBCMAES_BUILD_EXAMPLES"] = False | ||
tc.variables["LIBCMAES_BUILD_SHARED_LIBS"] = self.options.shared | ||
tc.variables["LIBCMAES_USE_OPENMP"] = self.options.openmp | ||
tc.variables["LIBCMAES_ENABLE_SURROG"] = self.options.surrog | ||
tc.variables["LIBCMAES_BUILD_PYTHON"] = False | ||
tc.variables["LIBCMAES_BUILD_TESTS"] = False | ||
tc.generate() | ||
|
||
def build(self): | ||
apply_conandata_patches(self) | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
rmdir(self, os.path.join(self.package_folder, "lib","pkgconfig")) | ||
rm(self, "*.cmake", os.path.join(self.package_folder, "lib", "cmake", "libcmaes")) | ||
copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses")) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["cmaes"] | ||
self.cpp_info.set_property("cmake_target_name", "libcmaes::cmaes") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 4a38212..dccfea4 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -6,12 +6,10 @@ if (NOT DEFINED CMAKE_BUILD_TYPE) | ||
set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type") | ||
endif () | ||
|
||
-set(CMAKE_CXX_FLAGS "-Wall -Wextra") | ||
-set(CMAKE_CXX_FLAGS_DEBUG "-g") | ||
-set(CMAKE_CXX_FLAGS_RELEASE "-O3") | ||
- | ||
list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) | ||
|
||
+include(CompilerOptions) | ||
+ | ||
set (LIBCMAES_TOP_LEVEL NO) | ||
if (${PROJECT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) | ||
set (LIBCMAES_TOP_LEVEL YES) | ||
diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake | ||
new file mode 100644 | ||
index 0000000..af4f716 | ||
--- /dev/null | ||
+++ b/cmake/CompilerOptions.cmake | ||
@@ -0,0 +1,91 @@ | ||
+ | ||
+set(CMAKE_CXX_FLAGS_DEBUG | ||
+ "${CMAKE_CXX_FLAGS_DEBUG} -Wall" | ||
+) | ||
+set(CMAKE_CXX_FLAGS_RELEASE | ||
+ "${CMAKE_CXX_FLAGS_RELEASE} -Wall ") | ||
+ | ||
+if(CMAKE_COMPILER_IS_GNUCXX) | ||
+ set(CMAKE_CXX_FLAGS_DEBUG | ||
+ "${CMAKE_CXX_FLAGS_DEBUG} -Wextra") | ||
+ set(CMAKE_CXX_FLAGS_RELEASE | ||
+ "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wextra") | ||
+endif(CMAKE_COMPILER_IS_GNUCXX) | ||
+ | ||
+if (MSVC) | ||
+ #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_USE_MATH_DEFINES" ) | ||
+ | ||
+ set(CMAKE_CXX_FLAGS_DEBUG | ||
+ "${CMAKE_CXX_FLAGS_DEBUG} /permissive- /bigobj /w44101") | ||
+ | ||
+ set(CMAKE_CXX_FLAGS_RELEASE | ||
+ "${CMAKE_CXX_FLAGS_RELEASE} /permissive- /bigobj /Ox /w44101") | ||
+ | ||
+ set(MSVC_DISABLED_WARNINGS_LIST | ||
+ "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not | ||
+ # explicitly handled by a case label | ||
+ # Disable this because it flags even when there is a default. | ||
+ "C4068" | ||
+ "C4100" # 'exarg' : unreferenced formal parameter | ||
+ "C4127" # conditional expression is constant | ||
+ "C4200" # nonstandard extension used : zero-sized array in | ||
+ # struct/union. | ||
+ "C4204" # nonstandard extension used: non-constant aggregate initializer | ||
+ "C4221" # nonstandard extension used : 'identifier' : cannot be | ||
+ # initialized using address of automatic variable | ||
+ "C4242" # 'function' : conversion from 'int' to 'uint8_t', | ||
+ # possible loss of data | ||
+ "C4244" # 'function' : conversion from 'int' to 'uint8_t', | ||
+ # possible loss of data | ||
+ "C4245" # 'initializing' : conversion from 'long' to | ||
+ # 'unsigned long', signed/unsigned mismatch | ||
+ "C4251" | ||
+ "C4267" # conversion from 'size_t' to 'int', possible loss of data | ||
+ "C4275" | ||
+ "C4355" | ||
+ "C4371" # layout of class may have changed from a previous version of the | ||
+ # compiler due to better packing of member '...' | ||
+ "C4388" # signed/unsigned mismatch | ||
+ "C4296" # '>=' : expression is always true | ||
+ "C4350" # behavior change: 'std::_Wrap_alloc...' | ||
+ "C4365" # '=' : conversion from 'size_t' to 'int', | ||
+ # signed/unsigned mismatch | ||
+ "C4389" # '!=' : signed/unsigned mismatch | ||
+ "C4464" # relative include path contains '..' | ||
+ "C4510" # 'argument' : default constructor could not be generated | ||
+ "C4571" | ||
+ "C4512" # 'argument' : assignment operator could not be generated | ||
+ "C4514" # 'function': unreferenced inline function has been removed | ||
+ "C4548" # expression before comma has no effect; expected expression with | ||
+ # side-effect" caused by FD_* macros. | ||
+ "C4610" # struct 'argument' can never be instantiated - user defined | ||
+ # constructor required. | ||
+ "C4619" | ||
+ "C4623" # default constructor was implicitly defined as deleted | ||
+ "C4625" # copy constructor could not be generated because a base class | ||
+ # copy constructor is inaccessible or deleted | ||
+ "C4626" # assignment operator could not be generated because a base class | ||
+ # assignment operator is inaccessible or deleted | ||
+ "C4643" | ||
+ "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with | ||
+ # '0' for 'directives' | ||
+ # Disable this because GTest uses it everywhere. | ||
+ "C4706" # assignment within conditional expression | ||
+ "C4710" # 'function': function not inlined | ||
+ "C4711" # function 'function' selected for inline expansion | ||
+ "C4800" # 'int' : forcing value to bool 'true' or 'false' | ||
+ # (performance warning) | ||
+ "C4820" # 'bytes' bytes padding added after construct 'member_name' | ||
+ "C4868" | ||
+ "C4996" | ||
+ "C5026" # move constructor was implicitly defined as deleted | ||
+ "C5027" # move assignment operator was implicitly defined as deleted | ||
+ "C5031" | ||
+ "C5039" | ||
+ "C5045" | ||
+ ) | ||
+ string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR | ||
+ ${MSVC_DISABLED_WARNINGS_LIST}) | ||
+ | ||
+ set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} ${MSVC_DISABLED_WARNINGS_STR}") | ||
+ endif() | ||
diff --git a/include/libcmaes/eigenmvn.h b/include/libcmaes/eigenmvn.h | ||
index fb8b11d..6a6943b 100644 | ||
--- a/include/libcmaes/eigenmvn.h | ||
+++ b/include/libcmaes/eigenmvn.h | ||
@@ -58,7 +58,20 @@ public: | ||
static std::mt19937 rng; // The uniform pseudo-random algorithm | ||
mutable std::normal_distribution<Scalar> norm; // gaussian combinator | ||
|
||
- EIGEN_EMPTY_STRUCT_CTOR(scalar_normal_dist_op) | ||
+ scalar_normal_dist_op() = default; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see this change referenced anywhere in the logs/upstream. Is this an issue on the library itself? If this is a backport, it'd be great to separate it to its own patch, so that we can crossreference back to it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is removed in the current eigen master branch https://gitlab.com/libeigen/eigen/-/merge_requests/946 I also got some problems because this additonally defines an empty copy ctr and we needed it to copy the members |
||
+ scalar_normal_dist_op(const scalar_normal_dist_op& other) | ||
+ : norm{other.norm} | ||
+ { | ||
+ rng = other.rng; | ||
+ }; | ||
+ scalar_normal_dist_op &operator=(const scalar_normal_dist_op &other) { | ||
+ if(this != &other) | ||
+ { | ||
+ scalar_normal_dist_op temp(other); | ||
+ swap(temp); | ||
+ } | ||
+ return *this; | ||
+ }; | ||
|
||
scalar_normal_dist_op &operator=(scalar_normal_dist_op &&other) | ||
{ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(PackageTest CXX) | ||
|
||
find_package(cmaes CONFIG REQUIRED) | ||
|
||
add_executable(example src/example.cpp) | ||
target_link_libraries(example libcmaes::cmaes) | ||
target_compile_features(example PUBLIC cxx_std_11) | ||
phbasler marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.tools.cmake import CMake, cmake_layout | ||
from conan.tools.build import can_run | ||
|
||
|
||
class helloTestConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "CMakeDeps", "CMakeToolchain" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def test(self): | ||
if can_run(self): | ||
cmd = os.path.join(self.cpp.build.bindir, "example") | ||
self.run(cmd, env="conanrun") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <libcmaes/cmaes.h> | ||
#include <iostream> | ||
|
||
using namespace libcmaes; | ||
|
||
FitFunc fsphere = [](const double *x, const int N) | ||
{ | ||
double val = 0.0; | ||
for (int i=0;i<N;i++) | ||
val += x[i]*x[i]; | ||
return val; | ||
}; | ||
|
||
int main() | ||
{ | ||
int dim = 10; // problem dimensions. | ||
std::vector<double> x0(dim,10.0); | ||
double sigma = 0.1; | ||
//int lambda = 100; // offsprings at each generation. | ||
CMAParameters<> cmaparams(x0,sigma); | ||
//cmaparams._algo = BIPOP_CMAES; | ||
CMASolutions cmasols = cmaes<>(fsphere,cmaparams); | ||
std::cout << "best solution: " << cmasols << std::endl; | ||
std::cout << "optimization took " << cmasols.elapsed_time() / 1000.0 << " seconds\n"; | ||
return EXIT_SUCCESS; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.10.0": | ||
folder: all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this comes from CMA-ES/libcmaes#234, do you have any insight into wether it will be merged eventually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope so. I will trigger @beniz again. If there is a new version with the PR, then I can adjust the conanfile here to not include this patch for the new version