Skip to content

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

Closed
jtkmckenna wants to merge 1 commit intoPyomo:mainfrom
jtkmckenna:numpy_2.0
Closed

Fix pyomo import with NumPy v2.0 or greater#3291
jtkmckenna wants to merge 1 commit intoPyomo:mainfrom
jtkmckenna:numpy_2.0

Conversation

@jtkmckenna
Copy link
Copy Markdown

@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
Copy Markdown
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