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

Pyomo is not compatible with Numpy 2.0.0 #3290

Closed
JeanWi opened this issue Jun 17, 2024 · 7 comments · Fixed by #3292
Closed

Pyomo is not compatible with Numpy 2.0.0 #3290

JeanWi opened this issue Jun 17, 2024 · 7 comments · Fixed by #3292
Labels

Comments

@JeanWi
Copy link

JeanWi commented Jun 17, 2024

Summary

Pyomo is not compatible with numpy 2.0.0 as np.float_ was removed.
From the numpy release note: Alias np.float_ has been removed. Use np.float64 instead. (https://github.com/numpy/numpy/releases/tag/v2.0.0)

Steps to reproduce the issue

Installing the latest numpy (2.0.0) and using pyomo leads to the following error:
AttributeError: np.float_ was removed in the NumPy 2.0 release. Use np.float64 instead.. Did you mean: 'float16'?

The problem is caused in: pyomo\common\dependencies.py:1002

Error Message

C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\pyomo\common\dependencies.py:475: in exec_module
deferred.resolve()
C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\pyomo\common\dependencies.py:334: in resolve
self._module, self._available = _perform_import(
C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\pyomo\common\dependencies.py:768: in _perform_import
callback(module, True)
C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\pyomo\common\dependencies.py:1002: in finalize_numpy
floats = [np.float, np.float16, np.float32, np.float64]
C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\numpy_init
.py:411: in getattr
raise AttributeError(
E AttributeError: np.float_ was removed in the NumPy 2.0 release. Use np.float64 instead.. Did you mean: 'float16'?


### Information on your system

Pyomo version: 6.7.3
Python version: 3.12
Operating system: Windows 11
How Pyomo was installed (PyPI, conda, source): PyPI
Solver (if applicable): gurobi, but not applicable


### Additional information

None
@jasonmbray-p66
Copy link

Thanks for working on this!

My conda environment just broke yesterday when I rebuilt my environment and it picked up numpy 2 automatically. However, I'm working from a pinned version of pyomo due to conflicts with other packages in my project and won't be able to take advantage of this fix in the latest pyomo version when it is released. I can pin numpy manually in my requirements, but to help others avoid the same issue, is it possible to also update the dependency version requirements of past pyomo versions so that conda, pip, and other package managers know that previous versions of pyomo require numpy<2?

@mrmundt
Copy link
Contributor

mrmundt commented Jun 18, 2024

Hi, @jasonmbray-p66 - A couple of notes:

  1. Some of our offerings still won't be numpy>=2.0.0 compatible for a while. For example, the solver xpress is not compatible. Our efforts are to make base Pyomo compatible - but can't guarantee widespread compatibility!
  2. We did pin numpy<2.0.0 for the two most recent releases (6.7.3, 6.7.2). We will discuss doing so for previous versions at our next dev team call.

@jasonmbray-p66
Copy link

Just my luck that my current project is pinned to <= 6.7.1, so I just barely missed the updated pins! Thanks for considering my request.

@p-snft
Copy link

p-snft commented Jun 19, 2024

Hi, @jasonmbray-p66 - A couple of notes:
2. We did pin numpy<2.0.0 for the two most recent releases (6.7.3, 6.7.2). We will discuss doing so for previous versions at our next dev team call.

I just installed the latest version of Pyomo and it pulled numpy 2.0 (Numpy without any pinned version was needed a package that also needs .) So, pinning did not seem to work.

I have a theory about this. Citing setup.py of the most recent release, you find (a lot of lines omitted)

setup_kwargs = dict(
    python_requires='>=3.8',
    install_requires=['ply'],
    extras_require={
        'optional': [
            'numpy<2.0.0',
        ],
    },
)

that it declares "numpy<2.0.0" as an optional dependency. So, if another package has install_requires=['numpy'] listed as a mandatory requirement, will it still install "numpy>=2.0.0" because the optional dependency of pyomo is just ignored? At the moment, I assume so. (An example showing this in can be found in the oemof.solph test pipeline at https://github.com/oemof/oemof-solph/actions/runs/9577740874/job/26406541517#step:6:23. Note that this pipeline is exclusively using pip for package management, so unlike watertap, it cannot be because of conda.)

maurerle added a commit to assume-framework/assume that referenced this issue Jun 20, 2024
for now, pyomo does not work with numpy 2 and its optional linking dependency is not enforced.

See here: Pyomo/pyomo#3290 (comment)
nick-harder pushed a commit to assume-framework/assume that referenced this issue Jun 20, 2024
for now, pyomo does not work with numpy 2 and its optional linking
dependency is not enforced.

See here:
Pyomo/pyomo#3290 (comment)
@mrmundt
Copy link
Contributor

mrmundt commented Jun 25, 2024

Note for all tracking this:

  • We will not be pinning numpy<2.0.0 for releases older than <6.7.2 - we do not have the capacity to re-release all of the old versions
  • numpy has always been an optional dependency and will continue to be so. This is causing the issue noted by @p-snft and is intended behavior.

@dagoberto-escobar
Copy link

I got the same issue while using Numpy v2.0.1 along with the most recent release v6.7.3, and got to circumvent the issue by adding the lines below

import numpy as np
np.float_ = np.float64
np.complex_=np.complex128

before importing Pyomo

@mrmundt
Copy link
Contributor

mrmundt commented Aug 7, 2024

The next release (6.7.4) will have this issue resolved.

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