CMA-ES / libcmaes

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
Other
321 stars 78 forks source link

Bug in parameters.h:113 #73

Closed hermanbanken closed 10 years ago

hermanbanken commented 10 years ago

When compiling on OSX with Homebrew I get a compile error:

/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-recursive
Making all in src
/bin/sh ../libtool  --tag=CXX   --mode=compile clang++ -DHAVE_CONFIG_H -I. -I..  -I/usr/local/include/eigen3  -Wall -g -fopenmp -std=gnu++11 -MT cmastrategy.lo -MD -MP -MF .deps/cmastrategy.Tpo -c -o cmastrategy.lo cmastrategy.cc
libtool: compile:  clang++ -DHAVE_CONFIG_H -I. -I.. -I/usr/local/include/eigen3 -Wall -g -fopenmp -std=gnu++11 -MT cmastrategy.lo -MD -MP -MF .deps/cmastrategy.Tpo -c cmastrategy.cc  -fno-common -DPIC -o .libs/cmastrategy.o
clang: warning: argument unused during compilation: '-fopenmp'
In file included from cmastrategy.cc:25:
In file included from ./cmastrategy.h:25:
In file included from ./esostrategy.h:26:
In file included from ./candidate.h:26:
In file included from ./cmaparameters.h:25:
./parameters.h:113:20: error: assigning to 'const double *' from incompatible type 'dVec' (aka 'Matrix<double, Dynamic, 1>')
    _x0min = x0max = dVec(_dim);
                   ^ ~~~~~~~~~~

After this compile error clang crashes:

1.  cmastrategy.cc:263:74: current parser token ';'
2.  cmastrategy.cc:31:1: parsing namespace 'libcmaes'
clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal (use -v to see invocation)

I noticed that running ./configure with the provided parameters (adjusted to Homebrew) does not work. Configuring for clang++ works with `./configure CXX="clang++" CXXFLAGS="-std=gnu++11"``. These are the only parameters necessary with Homebrew. Eigen(3) is found automatically.

Originally I tried to install with a newer gcc (4.9 via Homebrew) and running configure as

CCDIR=/usr/local/Cellar/gcc/4.9.1/bin
./configure CC="$CCDIR/gcc-4.9" CXX="g++-4.9" --with-eigen3-include=/usr/local/Cellar/eigen/3.2.2/include/eigen3 CXXFLAGS="-Wc++11-extensions -stdlib=libc++ -lstdc++ -I/usr/local/include -04" LDADD=-lgflags LDFLAGS=-L/usr/local/lib

but then it can't find c++11 extensions:

checking whether g++-4.9 supports C++11 features by default... no
checking whether g++-4.9 supports C++11 features with -std=gnu++11... no
checking whether g++-4.9 supports C++11 features with -std=gnu++0x... no
checking whether g++-4.9 supports C++11 features with -std=c++11... no
checking whether g++-4.9 supports C++11 features with -std=c++0x... no
configure: error: *** A compiler with support for C++11 language features is required.

So I guess there are 2 issues here, a piece of c++ invalid with clang and something that crashes the compiler. Did you experience this too? Do you have a workaround?

I want to use CMA-ES for my Combinatorial Solvers course at the Delft University of Technology in the Netherlands, and this library looked most promising...

beniz commented 10 years ago

Yes, this is a know bug, clang itself is crashing, see https://github.com/beniz/libcmaes/issues/19 I haven't heard from clang's devs for a while now, so I don't expect to see this fixed soon.

However, you should be able to more or less easily compile with gcc, see: https://github.com/beniz/libcmaes/wiki/Building-libcmaes-on-Mac-OSX

gcc-4.9 will do just fine, and you'll have support for openmp as well, something that clang is still lacking.

EDIT: note that you should be able to use Homebrew instead of macports. If you do so, please let me know the details if you can, as I will be able to update the doc for Homebrew.

hermanbanken commented 10 years ago

Thanks for the quick reply @beniz. As the second part of my message states I tried gcc 4.9 but the C++11 features are not found by configure. I had already read that wiki page, converting it for the Homebrew tool.

(As some people consider Homebrew to be better than MacPorts I installed the first. But both create some sort of vendor lock-in, so I can't really switch now).

Do you know how to get the configure script to pick up the C++11 features?

beniz commented 10 years ago

Try to fix your configure line:

hermanbanken commented 10 years ago

I think it was indeed the combination of the CXXFLAGS that broke things. This worked:

brew install gcc autoconf automake eigen gflags # currently installs gcc 4.9
git clone https://github.com/beniz/libcmaes.git
cd libcmaes
./autogen.sh
CCDIR=/usr/local/Cellar/gcc/4.9.1/bin # adjust to the installed version
CCVER=4.9
./configure CC="$CCDIR/gcc-$CCVER" CXX="$CCDIR/g++-$CCVER" --with-eigen3-include=/usr/local/Cellar/eigen/3.2.2/include/eigen3 CXXFLAGS="-lstdc++ -I/usr/local/include -O4" LDADD=-lgflags LDFLAGS=-L/usr/local/lib
make
./tests/test_functions

You should add this to the Mac OSX wiki page :+1:

By the way, I got the following warning a lot:

In file included from /usr/local/Cellar/eigen/3.2.2/include/eigen3/Eigen/Cholesky:24:0,
                 from /usr/local/Cellar/eigen/3.2.2/include/eigen3/Eigen/Eigenvalues:8,
                 from /usr/local/Cellar/eigen/3.2.2/include/eigen3/unsupported/Eigen/MatrixFunctions:21,
                 from eo_matrix.h:33,
                 from parameters.h:25,
                 from cmaparameters.h:25,
                 from covarianceupdate.h:25,
                 from covarianceupdate.cc:22:
/usr/local/Cellar/eigen/3.2.2/include/eigen3/Eigen/src/Cholesky/LDLT.h: In member function 'void Eigen::internal::solve_retval<Eigen::LDLT<MatrixType, _UpLo>, Rhs>::evalTo(Dest&) const':
/usr/local/Cellar/eigen/3.2.2/include/eigen3/Eigen/src/Cholesky/LDLT.h:505:39: warning: typedef 'Scalar' locally defined but not used [-Wunused-local-typedefs]
     typedef typename LDLTType::Scalar Scalar;