-
Notifications
You must be signed in to change notification settings - Fork 57
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
[BUG] Completely broken on numpy 2.x (wrong vector sent to fitness()) #177
Comments
CanNOT reproduce on osx (M1 arch): py313 numpy 2.2.0 ... this env: all looks fine, code behaves as expected
Here is the output of the code above from @samimia-swks:
|
I was driving myself crazy trying to debug my problem, but it turned out I was facing the same issue. On my complex UDP the decision vector printed from the fitness function was always all zeros even though when I print the population it has values within the box-bounds. Reproducing the example shown, here, using uv inline dependencies so it's easy to reproduce: # /// script
# requires-python = ">=3.11"
# dependencies = [
# "numpy==1.26.4",
# "pygmo>=2.19.5",
# ]
# ///
import pygmo as pg
class sphere_function:
def fitness(self, x):
cost = sum(x * x)
print(f"FITNESS EVAL: x = {x}, cost = {cost}")
return [cost]
def get_bounds(self):
return ([-1] * 3, [1] * 3)
prob = pg.problem(sphere_function())
pop = pg.population(prob, 5)
print(pop) Output numpy==1.26.4:
Output with numpy==2.2.1
Steps to reproduce:
|
To add on this, I think it's due to how the package is installed, by using conda I also can't reproduce the bug, but did (as my previous comment shows) on the pip version. When using conda, if the channel is not conda-forge (but pip), the package also behaves erratically. In my case it's completely broken, I spent some days trying to debug why when I run any algorithm implemented in C++ it just hangs and blocks the thread until the process is killed. After a lot of debugging, with my specific problem, I pinned it down to the |
@juan11iguel generally speaking, mixing together conda and pip packages is not supported. The pip packages at this point are quite old and what is probably happening is that the pybind11 version that was used to produce the wheels does not support numpy 2 correctly. @juan11iguel @samimia-swks can you confirm that within a conda environment everything is working correctly? |
The conda version works as expected |
With numpy 2.x, the fitness function is called with the wrong values in the decision vector x.
The example above results in the following. Notice how the population member #0 is [-0.504554, 0.87294, 0.639481] but the fitness function gets [-0.50455375 -0.50455375 -0.50455375].
On numpy 1.x, we get :
The text was updated successfully, but these errors were encountered: