-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[workspace] Add libcmaes as a testonly dependency (#16441)
In the future, we might use this in production, but for getting started we only need it in the sample test.
- Loading branch information
1 parent
d8a1180
commit ed5fdb0
Showing
6 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- python -*- | ||
|
||
load("//tools/lint:lint.bzl", "add_lint_tests") | ||
|
||
add_lint_tests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- python -*- | ||
|
||
load("//tools/lint:lint.bzl", "add_lint_tests") | ||
|
||
cc_test( | ||
name = "sample_code", | ||
srcs = ["sample_code.cc"], | ||
tags = ["nolint"], | ||
deps = ["@libcmaes"], | ||
) | ||
|
||
add_lint_tests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// From https://github.com/CMA-ES/libcmaes/blob/master/examples/sample-code.cc | ||
// as of 89ebe138eae646f79f326e49944c4cff33106e4f, with slight modifications. | ||
// This program serves to test the CMA-ES build system. Once we have any other | ||
// uses of CMA-ES in Drake, we should remove this file. | ||
|
||
/** | ||
* CMA-ES, Covariance Matrix Adaptation Evolution Strategy | ||
* Copyright (c) 2014 Inria | ||
* Author: Emmanuel Benazera <emmanuel.benazera@lri.fr> | ||
* | ||
* This file is part of libcmaes. | ||
* | ||
* libcmaes is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* libcmaes is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with libcmaes. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#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"; | ||
std::cout << "status " << cmasols.run_status() << "\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- python -*- | ||
|
||
load( | ||
"@drake//tools/workspace:cmake_configure_file.bzl", | ||
"cmake_configure_file", | ||
) | ||
load( | ||
"@drake//tools/workspace:generate_export_header.bzl", | ||
"generate_export_header", | ||
) | ||
|
||
licenses(["notice"]) # Apache-2.0 | ||
|
||
package( | ||
# TODO(jwnimmer-tri) At the time when libdrake depends on libcmaes, we | ||
# will need to change this to public, add the rules to install the | ||
# license file(s), and add it to the drake/tools/wheel build. | ||
default_visibility = ["@//tools/workspace/libcmaes/dev:__pkg__"], | ||
) | ||
|
||
cmake_configure_file( | ||
name = "config", | ||
src = "include/libcmaes/libcmaes_config.h.cmake.in", | ||
out = "include/libcmaes/libcmaes_config.h", | ||
defines = [ | ||
"HAVE_CXX11", | ||
"HAVE_INTTYPES_H", | ||
"HAVE_MEMORY_H", | ||
"HAVE_STDINT_H", | ||
"HAVE_STDLIB_H", | ||
"HAVE_STRINGS_H", | ||
"HAVE_STRING_H", | ||
"HAVE_UNISTD_H", | ||
"LIBCMAES_VERSION_STRING=0.0.0", | ||
], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
generate_export_header( | ||
out = "include/libcmaes/cmaes_export.h", | ||
lib = "cmaes", | ||
static_define = "LIBCMAES_STATIC_DEFINE", | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
cc_library( | ||
name = "libcmaes", | ||
srcs = glob([ | ||
"src/*.cc", | ||
], exclude = [ | ||
"src/surrogatestrategy.cc", | ||
]), | ||
hdrs = [ | ||
":include/libcmaes/libcmaes_config.h", | ||
":include/libcmaes/cmaes_export.h", | ||
] + glob([ | ||
"include/libcmaes/*.h", | ||
], exclude = [ | ||
"surrcmaes.h", | ||
"surrogatestrategy.h", | ||
]), | ||
copts = [ | ||
# Ignore OpenMP-related warnings. | ||
"-Wno-unknown-pragmas", | ||
], | ||
defines = ["LIBCMAES_STATIC_DEFINE"], | ||
deps = ["@eigen"], | ||
includes = ["include"], | ||
linkstatic = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- python -*- | ||
|
||
load("@drake//tools/workspace:github.bzl", "github_archive") | ||
|
||
def libcmaes_repository( | ||
name, | ||
mirrors = None): | ||
github_archive( | ||
name = name, | ||
repository = "CMA-ES/libcmaes", | ||
# TODO(jwnimmer-tri) We use an untagged commit, in order to use the | ||
# Apache-2.0 license. Any time we upgrade this to a newer commit, we | ||
# should check if there is an official version number yet that we | ||
# could use (i.e., newer than v0.10). | ||
commit = "1c39d7f931b267117d365370c6da5334a6948942", | ||
sha256 = "0abb557242da5a4b785e11aec1c00e57d583f23f04579921da9110206d0a6767", # noqa | ||
build_file = "@drake//tools/workspace/libcmaes:package.BUILD.bazel", | ||
mirrors = mirrors, | ||
) |