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

Numpy breaking value from pyomo.environ #3340

Closed
systechusaIN1522 opened this issue Aug 12, 2024 · 4 comments
Closed

Numpy breaking value from pyomo.environ #3340

systechusaIN1522 opened this issue Aug 12, 2024 · 4 comments
Labels

Comments

@systechusaIN1522
Copy link

systechusaIN1522 commented Aug 12, 2024

Summary

Created fresh virtual environment in a cloned repo (known to be in a working state). In the code I have a statement like from pyomo.environ import value - but running the file throws error even before value is called.

Steps to reproduce the issue

Not sure, but I have a setup like below

$ # assuming we are in some safe directory and having access to glpsol
$ echo "from pyomo.environ import value" > test.py
$ python3 -m venv v
$ source v\bin\activate
$ pip install wheel
$ pip install pyomo pandas openpyxl
$ python test.py

Error Message

stacktrace:

(v) abc@computer:~/code/projectName$ python optimiser.py 
Traceback (most recent call last):
  File "/home/abc/code/projectName/optimiser.py", line 11, in <module>
    from pyomo.environ import value
  File "/home/abc/code/projectName/v/lib/python3.10/site-packages/pyomo/__init__.py", line 12, in <module>
    from . import common
  File "/home/abc/code/projectName/v/lib/python3.10/site-packages/pyomo/common/__init__.py", line 14, in <module>
    from . import log
  File "/home/abc/code/projectName/v/lib/python3.10/site-packages/pyomo/common/log.py", line 30, in <module>
    from pyomo.common.fileutils import PYOMO_ROOT_DIR
  File "/home/abc/code/projectName/v/lib/python3.10/site-packages/pyomo/common/fileutils.py", line 45, in <module>
    from .dependencies import ctypes
  File "/home/abc/code/projectName/v/lib/python3.10/site-packages/pyomo/common/dependencies.py", line 1049, in <module>
    numpy, numpy_available = attempt_import('numpy', callback=_finalize_numpy)
  File "/home/abc/code/projectName/v/lib/python3.10/site-packages/pyomo/common/dependencies.py", line 738, in attempt_import
    return _perform_import(
  File "/home/abc/code/projectName/v/lib/python3.10/site-packages/pyomo/common/dependencies.py", line 768, in _perform_import
    callback(module, True)
  File "/home/abc/code/projectName/v/lib/python3.10/site-packages/pyomo/common/dependencies.py", line 1002, in _finalize_numpy
    _floats = [np.float_, np.float16, np.float32, np.float64]
  File "/home/abc/code/projectName/v/lib/python3.10/site-packages/numpy/__init__.py", line 397, in __getattr__
    raise AttributeError(
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.10.12
Operating system: Linux computer 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
How Pyomo was installed (PyPI, conda, source): pip
Solver (if applicable): glpsol

@jsiirola
Copy link
Member

Duplicate of #3290; resolved by #3292

@systechusaIN1522
Copy link
Author

Thanks @jsiirola I searched for couple of terms but didn't find anything relevant.

What is the suggested quick fix or recommended workaround until we get review from Robbybp, blnicho, and michaelbynum

@systechusaIN1522
Copy link
Author

As suggested by the error message, I tried np.float_ = np.float16 in the code - that threw complex_ error, so I currently have

np.int_ = np.int16
np.float_ = np.float32
np.complex_ = np.complex64

I am using MILP with GLPK - so I added int even though it wasn't complained for - please let me know if this will adversely affect the results.

@mrmundt
Copy link
Contributor

mrmundt commented Aug 12, 2024

@systechusaIN1522 - You can clone main and the issue is resolved there. We are also planning on release a new pinned version of Pyomo within the next two weeks, so if you prefer to work from official releases, that will soon be an option.

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

No branches or pull requests

3 participants