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

cmaes: Add 0.10.0 #24202

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
80515f3
(#24165) remove ericLemanissier from the authorized_users and reviewers
ericLemanissier May 30, 2024
a29853a
(#24163) [libprotobuf-mutator] Compatible with Conan 2.x
uilianries May 30, 2024
0198bb0
(#24060) elfutils: Bump gettext to version 0.22.5 to support GCC 14
jwillikers May 30, 2024
ab5c602
(#24176) [sioclient] Build static libraries in Windows
uilianries May 31, 2024
79f3dda
(#24174) meson: add version 1.4.1
toge May 31, 2024
91724e6
(#24175) ada: add version 2.8.0
toge May 31, 2024
bb9710d
(#24057) add extra-cmake-modules 6.2.0
BLumia May 31, 2024
70c7b7b
add cmaes
phbasler Jun 3, 2024
62b1cea
Update config.yml
phbasler Jun 3, 2024
e45bbab
Remove trailing whitespace
phbasler Jun 3, 2024
a8f1be6
Merge branch 'master' into packages/cmaes
phbasler Jun 3, 2024
2c1c3ab
Apply linter comments
phbasler Jun 3, 2024
aef42b4
Merge branch 'packages/cmaes' of https://github.com/phbasler/conan-ce…
phbasler Jun 3, 2024
7f4c46b
undo copy paste error
phbasler Jun 3, 2024
6dd4404
Remove unused imports
phbasler Jun 3, 2024
cff6a8b
change name
phbasler Jun 3, 2024
1cc89e8
add line break
phbasler Jun 3, 2024
171eccc
Set layout src_folder arg
phbasler Jun 3, 2024
d27837b
Adjust hook warnings and fix find_package
phbasler Jun 3, 2024
95a1ca6
fix missing requirement
phbasler Jun 3, 2024
6ca7bc7
Set minimum conan version to 2
phbasler Jun 3, 2024
4f7ea35
Undo conan minimum requirement
phbasler Jun 3, 2024
87239b4
Add patch to remove pc and exports
phbasler Jun 3, 2024
209d577
Remove patch, remove cmake and pc through conanfile
phbasler Jun 3, 2024
1fa1468
only get openmp on mac and linux
phbasler Jun 4, 2024
2b34d0f
disable openmp on windows for now
phbasler Jun 4, 2024
eb34bdc
Add test workflow
phbasler Jun 9, 2024
b102d9e
Revert "Add test workflow"
phbasler Jun 9, 2024
ebc0e0b
Add patch for eigen and for windows compile options
phbasler Jul 15, 2024
743b8bb
Revert "Add patch for eigen and for windows compile options"
phbasler Jul 15, 2024
a0ba9f0
Apply patch to fix windows build
phbasler Jul 15, 2024
d18682c
Add empty new line at the end
phbasler Jul 15, 2024
ef722e3
Set c++ standard to 11 in test_package
phbasler Jul 15, 2024
9583a7d
Add second example and validate profile to have at least c++11
phbasler Jul 17, 2024
33f1c38
Merge branch 'packages/cmaes' of https://github.com/phbasler/conan-ce…
phbasler Jul 17, 2024
f323bcb
Apply openmp settings from https://github.com/conan-io/conan-center-i…
phbasler Jul 22, 2024
025c68d
Add eigen to requires array
phbasler Jul 25, 2024
499f8fb
Add is_msvc to imports
phbasler Jul 25, 2024
1434ba5
Undo openmp suggestions
phbasler Jul 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions recipes/cmaes/all/conandata.yml
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

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description' not found in - patch_file: patches/Compiler ... ^ (line: 7)
86 changes: 86 additions & 0 deletions recipes/cmaes/all/conanfile.py
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")
142 changes: 142 additions & 0 deletions recipes/cmaes/all/patches/CompilerOptionsEigen.patch
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;
+ 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)
{
8 changes: 8 additions & 0 deletions recipes/cmaes/all/test_package/CMakeLists.txt
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
27 changes: 27 additions & 0 deletions recipes/cmaes/all/test_package/conanfile.py
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")

26 changes: 26 additions & 0 deletions recipes/cmaes/all/test_package/src/example.cpp
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;
}
3 changes: 3 additions & 0 deletions recipes/cmaes/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.10.0":
folder: all
Loading