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 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 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
6d1b59b
Merge branch 'conan-io:master' into packages/cmaes
phbasler Nov 15, 2024
b3bee09
Cleanup
AbrilRBS Nov 22, 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"
103 changes: 103 additions & 0 deletions recipes/cmaes/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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,
)
from conan.tools.build import check_min_cppstd
import os


class CmaesConan(ConanFile):
name = "cmaes"

generators = "CMakeDeps"

license = "LGPL-3.0-or-later"
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")
package_type = "library"

settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"surrog": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"surrog": True,
}

short_paths = True

@property
def _min_cppstd(self):
return 11

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 export_sources(self):
export_conandata_patches(self)

def validate(self):
check_min_cppstd(self, self._min_cppstd)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
apply_conandata_patches(self)

def requirements(self):
self.requires("eigen/3.4.0", transitive_headers=True)

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"] = False
phbasler marked this conversation as resolved.
Show resolved Hide resolved
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):
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
Copy link
Member

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?

Copy link
Author

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

@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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)
{
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")

61 changes: 61 additions & 0 deletions recipes/cmaes/all/test_package/src/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#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 test1()
{
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";

Candidate bcand = cmasols.best_candidate();

std::vector<double> xsol = bcand.get_x();
return EXIT_SUCCESS;
}

int test2()
{
int dim = 10; // problem dimensions.
std::vector<double> x0(dim,10.0);
double sigma = 0.1;
double ftol = 1e-5;

CMAParameters<> cmaparams(x0, sigma);
// cmaparams.set_mt_feval(true);
cmaparams.set_algo(aCMAES);
// cmaparams.set_elitism(1);
// cmaparams.set_noisy();
cmaparams.set_ftolerance(ftol);
CMASolutions cmasols = cmaes<>(fsphere, cmaparams);

Candidate bcand = cmasols.best_candidate();

std::vector<double> xsol = bcand.get_x();

std::cout << "best solution: " << cmasols << std::endl;
std::cout << "optimization took " << cmasols.elapsed_time() / 1000.0 << " seconds\n";
return EXIT_SUCCESS;
}

int main()
{
test1();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably simplify this test_package, the less actual computation, the better and the more probable it is for the test package to stay valid for future versions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could remove the first test and just use the second test with the commented lines removed. Would that be ok?

test2();
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