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

deprecated EigenMultivariateNormal #225

Closed phbasler closed 3 years ago

phbasler commented 3 years ago

Hi @beniz ,

In BSMPT we use FetchContent to get your code in cmake. There I noticed that adding the "-Wextra" compiler flag with gcc 9 creates the following Warnings while compiling the master branch

  -- The C compiler identification is GNU 9.3.0
  -- The CXX compiler identification is GNU 9.3.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /usr/bin/c++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Looking for dlfcn.h
  -- Looking for dlfcn.h - found
  -- Looking for unistd.h
  -- Looking for unistd.h - found
  -- Looking for string.h
  -- Looking for string.h - found
  -- Looking for strings.h
  -- Looking for strings.h - found
  -- Looking for inttypes.h
  -- Looking for inttypes.h - found
  -- Looking for memory.h
  -- Looking for memory.h - found
  -- Looking for stdlib.h
  -- Looking for stdlib.h - found
  -- Looking for stdint.h
  -- Looking for stdint.h - found
  -- Looking for sys/types.h
  -- Looking for sys/types.h - found
  -- Looking for sys/stat.h
  -- Looking for sys/stat.h - found
  -- Found Eigen3: /home/phil/libraries/eigen-3.4.0-installed/include/eigen3 (Required is at least version "3.0.0") 
  -- Found OpenMP_C: -fopenmp (found version "4.5") 
  -- Found OpenMP_CXX: -fopenmp (found version "4.5") 
  -- Found OpenMP: TRUE (found version "4.5")  
  -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
  -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
  -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
  -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
  -- Performing Test COMPILER_HAS_DEPRECATED_ATTR
  -- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /home/phil/Coding/Cmaes-new/build

  >  cmake --build . -j                                                                                            

  Scanning dependencies of target cmaes
  [  2%] Building CXX object src/CMakeFiles/cmaes.dir/cmaparameters.cc.o
  [  5%] Building CXX object src/CMakeFiles/cmaes.dir/acovarianceupdate.cc.o
  [  8%] Building CXX object src/CMakeFiles/cmaes.dir/cmastopcriteria.cc.o
  [ 11%] Building CXX object src/CMakeFiles/cmaes.dir/covarianceupdate.cc.o
  [ 17%] Building CXX object src/CMakeFiles/cmaes.dir/pwq_bound_strategy.cc.o
  [ 20%] Building CXX object src/CMakeFiles/cmaes.dir/vdcmaupdate.cc.o
  [ 23%] Building CXX object src/CMakeFiles/cmaes.dir/cmasolutions.cc.o
  [ 26%] Building CXX object src/CMakeFiles/cmaes.dir/bipopcmastrategy.cc.o
  [ 17%] Building CXX object src/CMakeFiles/cmaes.dir/esostrategy.cc.o
  [ 29%] Building CXX object src/CMakeFiles/cmaes.dir/cmastrategy.cc.o
  [ 32%] Building CXX object src/CMakeFiles/cmaes.dir/errstats.cc.o
  [ 35%] Building CXX object src/CMakeFiles/cmaes.dir/ipopcmastrategy.cc.o
  [ 38%] Building CXX object src/CMakeFiles/cmaes.dir/surrogatestrategy.cc.o
  In file included from /home/phil/Coding/Cmaes-new/include/libcmaes/esostrategy.h:27,
                   from /home/phil/Coding/Cmaes-new/include/libcmaes/cmastrategy.h:25,
                   from /home/phil/Coding/Cmaes-new/src/cmastrategy.cc:24:
  /home/phil/Coding/Cmaes-new/include/libcmaes/eigenmvn.h: In instantiation of ‘libcmaes::CMAStrategy<U, V>::CMAStrategy(libcmaes::FitFunc&, libcmaes::CMAParameters<TGenoPheno>&) [with TCovarianceUpdate = libcmaes::CovarianceUpdate; TGenoPheno = libcmaes::GenoPheno<libcmaes::NoBoundStrategy, libcmaes::NoScalingStrategy>; libcmaes::FitFunc = std::function<double(const double*, const int&)>]’:
  /home/phil/Coding/Cmaes-new/src/cmastrategy.cc:397:18:   required from here
  /home/phil/Coding/Cmaes-new/include/libcmaes/eigenmvn.h:76:11: warning: implicitly-declared ‘constexpr Eigen::internal::scalar_normal_dist_op<double>& Eigen::internal::scalar_normal_dist_op<double>::operator=(const Eigen::internal::scalar_normal_dist_op<double>&)’ is deprecated [-Wdeprecated-copy]
     76 |     class EigenMultivariateNormal
        |           ^~~~~~~~~~~~~~~~~~~~~~~
  In file included from /home/phil/libraries/eigen-3.4.0-installed/include/eigen3/Eigen/Core:165,
                   from /home/phil/libraries/eigen-3.4.0-installed/include/eigen3/Eigen/Dense:1,
                   from /home/phil/Coding/Cmaes-new/include/libcmaes/eo_matrix.h:26,
                   from /home/phil/Coding/Cmaes-new/include/libcmaes/esostrategy.h:25,
                   from /home/phil/Coding/Cmaes-new/include/libcmaes/cmastrategy.h:25,
                   from /home/phil/Coding/Cmaes-new/src/cmastrategy.cc:24:
  /home/phil/Coding/Cmaes-new/include/libcmaes/eigenmvn.h:55:26: note: because ‘Eigen::internal::scalar_normal_dist_op<double>’ has user-provided ‘Eigen::internal::scalar_normal_dist_op<Scalar>::scalar_normal_dist_op(const Eigen::internal::scalar_normal_dist_op<Scalar>&) [with Scalar = double]’
     55 |  EIGEN_EMPTY_STRUCT_CTOR(scalar_normal_dist_op)
        |                          ^~~~~~~~~~~~~~~~~~~~~
  /home/phil/Coding/Cmaes-new/src/cmastrategy.cc:108:14: note: synthesized method ‘Eigen::EigenMultivariateNormal<double>& Eigen::EigenMultivariateNormal<double>::operator=(Eigen::EigenMultivariateNormal<double>&&)’ first required here
    108 |     _esolver = Eigen::EigenMultivariateNormal<double>(false,eostrat<TGenoPheno>::_parameters._seed); // seeding the multivariate normal generator.
        |     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  [ 41%] Linking CXX shared library libcmaes.so
  [ 41%] Built target cmaes
  Scanning dependencies of target sample-code-gradient
  Scanning dependencies of target sample-code-genopheno
  Scanning dependencies of target sample-code-lscaling-sigmas
  Scanning dependencies of target sample-code-bounds
  Scanning dependencies of target sample-code
  Scanning dependencies of target sample-code-ask-tell
  Scanning dependencies of target sample-code-lscaling
  Scanning dependencies of target sample-code-pffunc
  Scanning dependencies of target sample-code-ask-tell-uh
  Scanning dependencies of target sample-code-pfunc
  [ 47%] Building CXX object examples/CMakeFiles/sample-code-ask-tell.dir/sample-code-ask-tell.cc.o
  [ 47%] Building CXX object examples/CMakeFiles/sample-code-gradient.dir/sample-code-gradient.cc.o
  [ 50%] Building CXX object examples/CMakeFiles/sample-code-pffunc.dir/sample-code-pffunc.cc.o
  [ 52%] Building CXX object examples/CMakeFiles/sample-code-lscaling.dir/sample-code-lscaling.cc.o
  [ 55%] Building CXX object examples/CMakeFiles/sample-code.dir/sample-code.cc.o
  [ 58%] Building CXX object examples/CMakeFiles/sample-code-lscaling-sigmas.dir/sample-code-lscaling-sigmas.cc.o
  [ 61%] Building CXX object examples/CMakeFiles/sample-code-pfunc.dir/sample-code-pfunc.cc.o
  [ 64%] Building CXX object examples/CMakeFiles/sample-code-genopheno.dir/sample-code-genopheno.cc.o
  [ 67%] Building CXX object examples/CMakeFiles/sample-code-bounds.dir/sample-code-bounds.cc.o
  [ 70%] Building CXX object examples/CMakeFiles/sample-code-ask-tell-uh.dir/sample-code-ask-tell-uh.cc.o
  [ 73%] Linking CXX executable sample-code-ask-tell-uh
  [ 76%] Linking CXX executable sample-code-ask-tell
  [ 76%] Built target sample-code-ask-tell-uh
  [ 76%] Built target sample-code-ask-tell
  [ 79%] Linking CXX executable sample-code-pfunc
  [ 79%] Built target sample-code-pfunc
  [ 82%] Linking CXX executable sample-code-lscaling-sigmas
  [ 85%] Linking CXX executable sample-code
  [ 88%] Linking CXX executable sample-code-gradient
  [ 88%] Built target sample-code-lscaling-sigmas
  [ 88%] Built target sample-code
  [ 88%] Built target sample-code-gradient
  [ 91%] Linking CXX executable sample-code-pffunc
  [ 94%] Linking CXX executable sample-code-genopheno
  [ 97%] Linking CXX executable sample-code-lscaling
  [100%] Linking CXX executable sample-code-bounds
  [100%] Built target sample-code-pffunc
  [100%] Built target sample-code-genopheno
  [100%] Built target sample-code-lscaling
  [100%] Built target sample-code-bounds

Do you have any plans on fixing this? Do you need more information?

phbasler commented 3 years ago

It seems that we need a user defined move constructor because of the randN copy being deprecated. I tried it localy with a swap idiom move constructor and deleted copy constructor. It compiled without warnings. Both tests in ctest also still pass.

Should I open a PR or is there something else I need to check first?

beniz commented 3 years ago

Hi @phbasler please do!