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

CMA-ES The default example contains an issue. #651

Open
jchahal-wiio opened this issue Oct 21, 2024 · 2 comments
Open

CMA-ES The default example contains an issue. #651

jchahal-wiio opened this issue Oct 21, 2024 · 2 comments
Assignees

Comments

@jchahal-wiio
Copy link

Hello,

Firstly, a big thanks for this library! It is very useful.

When I run the example of CMA-ES (https://pymoo.org/algorithms/soo/cmaes.html) :

import numpy as np
from pymoo.algorithms.soo.nonconvex.cmaes import CMAES
from pymoo.problems import get_problem
from pymoo.optimize import minimize

problem = get_problem("sphere")

algorithm = CMAES(x0=np.random.random(problem.n_var))

res = minimize(problem,
               algorithm,
               seed=1,
               verbose=False)

print(f"Best solution found: \nX = {res.X}\nF = {res.F}\nCV= {res.CV}")

I have this error:

File "[...]\CMA_ES.py", line 11, in <module>
  res = minimize(problem,
        ^^^^^^^^^^^^^^^^^
File "[...]\.venv\Lib\site-packages\pymoo\optimize.py", line 67, in minimize
  res = algorithm.run()
        ^^^^^^^^^^^^^^^
File "[...]\.venv\Lib\site-packages\pymoo\core\algorithm.py", line 138, in run
  self.next()
File "[...]\.venv\Lib\site-packages\pymoo\core\algorithm.py", line 159, in next
  self.advance(infills=infills)
File "[...]\.venv\Lib\site-packages\pymoo\core\algorithm.py", line 214, in advance
  self._initialize_advance(infills=infills, **kwargs)
File "[...]\.venv\Lib\site-packages\pymoo\algorithms\soo\nonconvex\cmaes.py", line 431, in _initialize_advance
  self.next_X = next(self.es)
                ^^^^^^^^^^^^^
File "[...]\.venv\Lib\site-packages\pymoo\vendor\vendor_cmaes.py", line 128, in my_fmin
  es = MyCMAEvolutionStrategy(x0, sigma_factor * sigma0, opts)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[...]\.venv\Lib\site-packages\cma\evolution_strategy.py", line 1503, in __init__
  self.boundary_handler = self.boundary_handler(opts['bounds'])
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[...]\.venv\Lib\site-packages\cma\constraints_handler.py", line 259, in __init__
  self.bounds_tf = BoxConstraintsLinQuadTransformation(self.to_dim_times_two(bounds))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[...]\.venv\Lib\site-packages\cma\transformations.py", line 262, in __init__
  super(BoxConstraintsLinQuadTransformation, self).__init__(bounds)
File "[...]\.venv\Lib\site-packages\cma\transformations.py", line 123, in __init__
  self.initialize()
File "[...]\.venv\Lib\site-packages\cma\transformations.py", line 271, in initialize
  self._lb = array([self.bounds[min((i, max_i))][0]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Unable to avoid copy while creating an array as requested.
If using `np.array(obj, copy=False)` replace it with `np.asarray(obj)` to allow a copy when needed (no behavior change in NumPy 1.x).
For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.

I'm on Windows 11, with python 3.12 and with this pip environment :

Package         Version
--------------- -----------
about-time      4.2.1
alive-progress  3.1.5
autograd        1.7.0
cma             3.2.2
contourpy       1.3.0
cycler          0.12.1
Deprecated      1.2.14
dill            0.3.9
fonttools       4.54.1
grapheme        0.6.0
kiwisolver      1.4.7
matplotlib      3.9.2
networkx        3.4.1
numpy           2.1.2
packaging       24.1
pillow          11.0.0
pip             23.2.1
pygame          2.6.1
pymoo           0.6.1.3
pyparsing       3.2.0
python-dateutil 2.9.0.post0
scipy           1.14.1
six             1.16.0
wrapt           1.16.0

Is anyone can help me fixing this issue? Thanks in advance!

@jchahal-wiio jchahal-wiio changed the title CMA-ES Default example issue CMA-ES Default example has an issue Oct 21, 2024
@jchahal-wiio jchahal-wiio changed the title CMA-ES Default example has an issue CMA-ES The default example contains an issue. Oct 21, 2024
@blankjul blankjul self-assigned this Nov 5, 2024
@blankjul
Copy link
Collaborator

blankjul commented Nov 5, 2024

what version of cma are you using? did you install it coming along with the pymoo package?

@jchahal-wiio
Copy link
Author

Thank you for your feedback!
As shown in the pip list, the current cma version is 3.2.2, which is the default version included with the latest pymoo installation (0.6.1.3).
If you have any further questions, please don’t hesitate to reach out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants