pymoo
pymoo copied to clipboard
Numpy 2.0.0 breaks pymoo 0.6.1.1
Installing pymoo from PyPI, i.e. 0.6.1.1, results in an AttributeError when importing ElementwiseProblem. The problem seems to be numpy version 2.0.0. Downgrading numpy to 1.26.4 resolves the issue.
MWE
- Create venv (python3 -m venv venv)
- Activate venv
- Install pymoo (python3 -m pip install pymoo)
- Run python
- import ElementwiseProblem (from pymoo.core.problem import ElementwiseProblem)
Error Message
Traceback (most recent call last):
File "
Additional Info
Tested with python version 3.11.6
Packages in venv
about-time 4.2.1 alive-progress 3.1.5 autograd 1.6.2 cma 3.2.2 contourpy 1.2.1 cycler 0.12.1 Deprecated 1.2.14 dill 0.3.8 fonttools 4.53.0 future 1.0.0 grapheme 0.6.0 kiwisolver 1.4.5 matplotlib 3.9.0 numpy 2.0.0 packaging 24.1 pillow 10.3.0 pip 23.2 pymoo 0.6.1.1 pyparsing 3.1.2 python-dateutil 2.9.0.post0 scipy 1.13.1 setuptools 68.1.2 six 1.16.0 wrapt 1.16.0
Issue is autograd is no longer maintained and will not support numpy v2. This project should move to JAX.
In the meantime, I think you can try to monkeypatch it...
import jax.numpy as jnp
with unittest.mock.patch("pymoo.gradient.toolbox", new=jnp):
import pymoo
What in black magic programming is happening with pymoo.toolbox module resolution?!
I've also encountered this problem, and resolved it with monkeypatching the TOOLBOX string which checks for JAX / autograd:
import unittest.mock
with unittest.mock.patch("pymoo.gradient.TOOLBOX", new='jax.numpy'):
import pymoo
Sorry for the spam. :sweat_smile:
Until this is fixed, I propose pinning the numpy dependency in the setup.py file.
https://github.com/anyoptimization/pymoo/blob/dca843afaa8406829547bf117a72cf2b2a4ec84a/setup.py#L36
I have released a new version and taken out the line using autograd by default.
Can someone check if this issue is fixed now?
I have released a new version and taken out the line using autograd by default.
Can someone check if this issue is fixed now?
Hi @blankjul ,
thanks for the release. With the release 0.6.1.3, it's not crashing now and triggering the version warning printing.
Great! I will close this issue then.