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

Fix pyomo import with NumPy v2.0 or greater #3291

Closed
wants to merge 1 commit into from

Conversation

jtkmckenna
Copy link

@jtkmckenna jtkmckenna commented Jun 17, 2024

Fixes #3290

import pyomo with NumPy 2.0

Summary/Motivation:

NumPy 2.0 has removed np.float_ and np.complex_

Error demonstration (with NumPy 2.0):

import numpy as np
import pyomo
AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead.. Did you mean: 'float16'?

Changes proposed in this PR:

Here I set a version check before including them

Per the release notes: https://numpy.org/devdocs/release/2.0.0-notes.html

  • Alias np.float_ has been removed. Use np.float64 instead.
  • Alias np.complex_ has been removed. Use np.complex128 instead.

Now

import numpy as np
import pyomo

Does not raise any errors

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@mrmundt
Copy link
Contributor

mrmundt commented Jun 17, 2024

Thanks, @jtkmckenna , but I actually already have a branch for this - it has some extra fixes / test changes. I've just been waiting for NumPy 2 to fully release.

@mrmundt mrmundt closed this Jun 17, 2024
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

Successfully merging this pull request may close these issues.

Pyomo is not compatible with Numpy 2.0.0
2 participants