Skip to content

Commit

Permalink
Merge pull request #225 from resibots/eigen3.3
Browse files Browse the repository at this point in the history
Eigen3.3 support
  • Loading branch information
costashatz authored Jun 2, 2017
2 parents 69bf900 + 7346d81 commit 43854c5
Show file tree
Hide file tree
Showing 40 changed files with 269 additions and 168 deletions.
57 changes: 39 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,57 @@ env:
global:
- CI_HOME=`pwd`
matrix:
# Test python3
- LIBCMAES=ON NLOPT=ON TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python3
- LIBCMAES=ON NLOPT=ON TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2
- LIBCMAES=ON NLOPT=ON TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2
- LIBCMAES=ON NLOPT=OFF TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2
- LIBCMAES=ON NLOPT=OFF TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2
- LIBCMAES=OFF NLOPT=ON TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2
- LIBCMAES=OFF NLOPT=ON TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2
- LIBCMAES=OFF NLOPT=OFF TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2
- LIBCMAES=OFF NLOPT=OFF TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2
- LIBCMAES=ON NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=OFF PYTHON=python2
- LIBCMAES=OFF NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=OFF PYTHON=python2
- LIBCMAES=ON NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=OFF PYTHON=python2
- LIBCMAES=OFF NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=OFF PYTHON=python2
- LIBCMAES=ON NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=ON PYTHON=python2
- LIBCMAES=OFF NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=ON PYTHON=python2
- LIBCMAES=ON NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=ON PYTHON=python2
- LIBCMAES=OFF NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=ON PYTHON=python2
# Test LAPACK/BLAS
- LIBCMAES=ON NLOPT=ON TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=ON LAPACKE=--lapacke_blas
# Eigen3.3
- LIBCMAES=ON NLOPT=ON TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=ON NLOPT=ON TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=ON NLOPT=OFF TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=ON NLOPT=OFF TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=OFF NLOPT=ON TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=OFF NLOPT=ON TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=OFF NLOPT=OFF TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=OFF NLOPT=OFF TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=ON NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=OFF NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=ON NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=OFF NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=OFF PYTHON=python2 EIGEN33=ON
- LIBCMAES=ON NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=ON PYTHON=python2 EIGEN33=ON
- LIBCMAES=OFF NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=ON PYTHON=python2 EIGEN33=ON
- LIBCMAES=ON NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=ON PYTHON=python2 EIGEN33=ON
- LIBCMAES=OFF NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=ON PYTHON=python2 EIGEN33=ON
# Eigen3
- LIBCMAES=ON NLOPT=ON TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=ON NLOPT=ON TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=ON NLOPT=OFF TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=ON NLOPT=OFF TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=OFF NLOPT=ON TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=OFF NLOPT=ON TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=OFF NLOPT=OFF TBB=ON EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=OFF NLOPT=OFF TBB=OFF EXPERIMENTAL=OFF SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=ON NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=OFF NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=ON NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=OFF NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=OFF PYTHON=python2 EIGEN33=OFF
- LIBCMAES=ON NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=ON PYTHON=python2 EIGEN33=OFF
- LIBCMAES=OFF NLOPT=OFF TBB=OFF EXPERIMENTAL=ON SFERES=ON PYTHON=python2 EIGEN33=OFF
- LIBCMAES=ON NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=ON PYTHON=python2 EIGEN33=OFF
- LIBCMAES=OFF NLOPT=OFF TBB=ON EXPERIMENTAL=ON SFERES=ON PYTHON=python2 EIGEN33=OFF

addons:
apt:
packages:
- libboost1.55-all-dev
- libeigen3-dev
- python
- python3

before_install:
- sudo sed -i -e 's/^Defaults\tsecure_path.*$//' /etc/sudoers

install:
- if [ "$EIGEN33" = "ON" ]; then 'ci/install_eigen3_3.sh' ; else 'ci/install_eigen3.sh' ; fi
- if [ "$LIBCMAES" = "ON" ]; then 'ci/install_libcmaes.sh' ; fi
- if [ "$NLOPT" = "ON" ]; then 'ci/install_nlopt.sh' ; fi
- if [ "$TBB" = "ON" ]; then 'ci/install_tbb.sh' ; fi
Expand All @@ -54,5 +75,5 @@ install:

# Change this to your needs
script:
- if [ "$SFERES" = "OFF" ]; then $PYTHON ./waf configure ; else $PYTHON ./waf configure --sferes=$CI_HOME/sferes2 ; fi
- if [ "$SFERES" = "OFF" ]; then $PYTHON ./waf configure $LAPACKE ; else $PYTHON ./waf configure --sferes=$CI_HOME/sferes2 ; fi
- if [ "$EXPERIMENTAL" = "OFF" ]; then $PYTHON ./waf --tests --alltests -v ; else $PYTHON ./waf --experimental ; fi
2 changes: 2 additions & 0 deletions ci/install_eigen3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sudo apt-get -qq update
sudo apt-get -qq --yes --force-yes install libeigen3-dev
10 changes: 10 additions & 0 deletions ci/install_eigen3_3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sudo apt-get -qq update
sudo apt-get -qq --yes --force-yes install libblas-dev liblapacke liblapacke-dev
cd && hg clone https://bitbucket.org/eigen/eigen
cd eigen
hg up 3.3
mkdir build && cd build
cmake ..
sudo make install
sudo ldconfig
cd $CI_HOME
4 changes: 2 additions & 2 deletions docs/tutorials/advanced_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ The basic layout of your ``main.cpp`` file should look like this:

template <typename Params>
struct eval_func {
static constexpr int dim_in = sample_dimensions;
static constexpr int dim_out = output_dimensions;
BO_PARAM(size_t, dim_in, sample_dimensions);
BO_PARAM(size_t, dim_out, output_dimensions);
// Here we define the evaluation function
};

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/basic_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ Then, we have to define the evaluation function for the optimizer to call:
:linenos:
:lines: 98-112

It is required that the evaluation struct has the static members ``dim_in`` and ``dim_out``, specifying the input and output dimensions.
Also, it should have the ``operator()`` expecting a ``const Eigen::VectorXd&`` of size ``dim_in``, and return another one, of size ``dim_out``.
It is required that the evaluation struct has the static function members ``dim_in()`` and ``dim_out()``, specifying the input and output dimensions.
Also, it should have the ``operator()`` expecting a ``const Eigen::VectorXd&`` of size ``dim_in()``, and return another one, of size ``dim_out()``.

With this, we can declare the main function:

Expand Down
9 changes: 9 additions & 0 deletions docs/tutorials/compilation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ Optional but highly recommended
sudo make
sudo cp *.a /usr/lib

In addition, you should be careful to configure **libcmaes** to use the same Eigen3 version as what you intend to use with Limbo (configuring with Makefiles)::

./configure --with-eigen3-include=YOUR_DESIRED_DIR/include/eigen3

or (configure with CMake)::

cmake -DEIGEN3_INCLUDE_DIR=YOUR_DESIRED_DIR/include/eigen3 ..

* `Intel TBB <https://www.threadingbuildingblocks.org>`_ is not mandatory, but highly recommended; TBB is used in Limbo to take advantage of multicore architectures.

Optional
+++++++++++++
* `Intel MKL <https://software.intel.com/en-us/intel-mkl>`_ is supported as backend for Eigen. In our experience, it provided best results when compiling with Intel's Compiler (ICC)
* `LAPACKE/BLAS <http://www.netlib.org/lapack/lapacke.html>`_ is supported as a backend for Eigen (`version>=3.3 <https://eigen.tuxfamily.org/dox/TopicUsingBlasLapack.html>`_). In our experience, it gives high speed-ups with **big** matrices (i.e., more than 1200 dimensions) and hurts a bit the performance with **small** matrices (i.e., less than 800 dimensions). You can enable LAPACKE/BLAS by using the ``--lapacke_blas`` option (if you have Eigen3.3 or later).
* `Sferes2 <https://github.com/sferes2/sferes2>`_ if you plan to use the multi-objective bayesian optimization algorithms (experimental).

Compilation
Expand Down
2 changes: 1 addition & 1 deletion src/benchmarks/bayesopt/hp_opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void benchmark(const bopt_params& par, const std::string& name)
{
auto t1 = std::chrono::steady_clock::now();
Benchmark<Function> benchmark(par);
vectord result(Function::dim_in);
vectord result(Function::dim_in());
benchmark.optimize(result);
auto time_running = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout.precision(17);
Expand Down
2 changes: 1 addition & 1 deletion src/benchmarks/bayesopt/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void benchmark(const bopt_params& par, const std::string& name)
{
auto t1 = std::chrono::steady_clock::now();
Benchmark<Function> benchmark(par);
vectord result(Function::dim_in);
vectord result(Function::dim_in());
benchmark.optimize(result);
auto time_running = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t1).count();
std::cout.precision(17);
Expand Down
47 changes: 24 additions & 23 deletions src/benchmarks/bayesopt/testfunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ inline vectord t_osz(const vectord& x)
}

struct Sphere {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);

double operator()(const vectord& x) const
{
Expand All @@ -117,17 +117,17 @@ struct Sphere {
};

struct Ellipsoid {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);

double operator()(const vectord& x) const
{
vectord opt(2);
opt <<= 0.5, 0.5;
vectord z = t_osz(x - opt);
double r = 0;
for (size_t i = 0; i < dim_in; ++i)
r += std::pow(10, ((double)i) / (dim_in - 1.0)) * z(i) * z(i) + 1;
for (size_t i = 0; i < dim_in(); ++i)
r += std::pow(10, ((double)i) / (dim_in() - 1.0)) * z(i) * z(i) + 1;
return r;
}

Expand All @@ -140,30 +140,30 @@ struct Ellipsoid {
};

struct Rastrigin {
static constexpr size_t dim_in = 4;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 4);
BO_PARAM(size_t, dim_out, 1);

double operator()(const vectord& x) const
{
double f = 10 * dim_in;
for (size_t i = 0; i < dim_in; ++i)
double f = 10 * dim_in();
for (size_t i = 0; i < dim_in(); ++i)
f += x(i) * x(i) - 10 * cos(2 * M_PI * x(i));
return f;
}

matrixd solutions() const
{
matrixd sols(1, dim_in);
for (size_t i = 0; i < dim_in; ++i)
matrixd sols(1, dim_in());
for (size_t i = 0; i < dim_in(); ++i)
sols(0, i) = 0;
return sols;
}
};

// see : http://www.sfu.ca/~ssurjano/hart3.html
struct Hartmann3 {
static constexpr size_t dim_in = 3;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 3);
BO_PARAM(size_t, dim_out, 1);

double operator()(const vectord& x) const
{
Expand Down Expand Up @@ -196,8 +196,8 @@ struct Hartmann3 {

// see : http://www.sfu.ca/~ssurjano/hart6.html
struct Hartmann6 {
static constexpr size_t dim_in = 6;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 6);
BO_PARAM(size_t, dim_out, 1);

double operator()(const vectord& x) const
{
Expand Down Expand Up @@ -234,8 +234,8 @@ struct Hartmann6 {
// see : http://www.sfu.ca/~ssurjano/goldpr.html
// (with ln, as suggested in Jones et al.)
struct GoldsteinPrice {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);

double operator()(const vectord& xx) const
{
Expand All @@ -256,8 +256,8 @@ struct GoldsteinPrice {
};

struct BraninNormalized {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);

double operator()(const vectord& x) const
{
Expand All @@ -277,8 +277,9 @@ struct BraninNormalized {
};

struct SixHumpCamel {
static constexpr size_t dim_in = 2;
static constexpr size_t dim_out = 1;
BO_PARAM(size_t, dim_in, 2);
BO_PARAM(size_t, dim_out, 1);

double operator()(const vectord& x) const
{
double x1 = -3 + 6 * x(0);
Expand Down Expand Up @@ -308,7 +309,7 @@ struct SixHumpCamel {
template <typename Function>
class Benchmark : public bayesopt::ContinuousModel {
public:
Benchmark(bopt_params par) : ContinuousModel(Function::dim_in, par) {}
Benchmark(bopt_params par) : ContinuousModel(Function::dim_in(), par) {}

double evaluateSample(const vectord& xin)
{
Expand Down
6 changes: 3 additions & 3 deletions src/benchmarks/limbo/hp_opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ template <typename Optimizer, typename Function>
void benchmark(const std::string& name)
{
int iters_base = 250;
DirectParams::opt_nloptnograd::set_iterations(static_cast<int>(iters_base * Function::dim_in * 0.9));
BobyqaParams::opt_nloptnograd::set_iterations(iters_base * Function::dim_in - DirectParams::opt_nloptnograd::iterations());
DirectParams::opt_nloptnograd::set_iterations(static_cast<int>(iters_base * Function::dim_in() * 0.9));
BobyqaParams::opt_nloptnograd::set_iterations(iters_base * Function::dim_in() - DirectParams::opt_nloptnograd::iterations());

BobyqaParams_HP::opt_nloptnograd::set_iterations(10 * Function::dim_in * Function::dim_in);
BobyqaParams_HP::opt_nloptnograd::set_iterations(10 * Function::dim_in() * Function::dim_in());

auto t1 = std::chrono::steady_clock::now();
Optimizer opt;
Expand Down
4 changes: 2 additions & 2 deletions src/benchmarks/limbo/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ template <typename Optimizer, typename Function>
void benchmark(const std::string& name)
{
int iters_base = 250;
DirectParams::opt_nloptnograd::set_iterations(static_cast<int>(iters_base * Function::dim_in * 0.9));
BobyqaParams::opt_nloptnograd::set_iterations(iters_base * Function::dim_in - DirectParams::opt_nloptnograd::iterations());
DirectParams::opt_nloptnograd::set_iterations(static_cast<int>(iters_base * Function::dim_in() * 0.9));
BobyqaParams::opt_nloptnograd::set_iterations(iters_base * Function::dim_in() - DirectParams::opt_nloptnograd::iterations());

auto t1 = std::chrono::steady_clock::now();
Optimizer opt;
Expand Down
Loading

0 comments on commit 43854c5

Please sign in to comment.