A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File "/users/5/my_redacted_username/PyGRANSO/test_cuda.py", line 1, in <module>
import torch
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/__init__.py", line 629, in <module>
from .functional import * # noqa: F403
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/functional.py", line 6, in <module>
import torch.nn.functional as F
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/nn/__init__.py", line 1, in <module>
from .modules import * # noqa: F403
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/nn/modules/__init__.py", line 2, in <module>
from .linear import Identity, Linear, Bilinear, LazyLinear
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/nn/modules/linear.py", line 6, in <module>
from .. import functional as F
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/nn/functional.py", line 11, in <module>
from .._jit_internal import boolean_dispatch, _overload, BroadcastingList1, BroadcastingList2, BroadcastingList3
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/_jit_internal.py", line 26, in <module>
import torch.package._mangling as package_mangling
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/package/__init__.py", line 12, in <module>
from .package_importer import PackageImporter
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/package/package_importer.py", line 26, in <module>
from ._mock_zipreader import MockZipReader
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/package/_mock_zipreader.py", line 17, in <module>
_dtype_to_storage = {data_type(0).dtype: data_type for data_type in _storages}
File "/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/package/_mock_zipreader.py", line 17, in <dictcomp>
_dtype_to_storage = {data_type(0).dtype: data_type for data_type in _storages}
/users/5/my_redacted_username/PyGRANSO/.venv/lib/python3.9/site-packages/torch/package/_mock_zipreader.py:17: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at /pytorch/torch/csrc/utils/tensor_numpy.cpp:67.)
_dtype_to_storage = {data_type(0).dtype: data_type for data_type in _storages}
Testing may take several minutes. Thank you for your patience.
Traceback (most recent call last):
File "/users/5/my_redacted_username/PyGRANSO/pygranso/pygranso.py", line 509, in pygranso
info = bfgssqp_obj.bfgssqp(penaltyfn_obj,bfgs_hess_inv_obj,opts,printer, torch_device)
File "/users/5/my_redacted_username/PyGRANSO/pygranso/private/bfgssqp.py", line 249, in bfgssqp
[stat_vec,self.stat_val,qps_solved, _, _] = self.computeApproxStationarityVector()
File "/users/5/my_redacted_username/PyGRANSO/pygranso/private/bfgssqp.py", line 598, in computeApproxStationarityVector
[grad_samples,dist_evals] = self.get_nearby_grads_fn()
File "/users/5/my_redacted_username/PyGRANSO/pygranso/private/bfgssqp.py", line 247, in <lambda>
self.get_nearby_grads_fn = lambda : getNearbyGradients( self.penaltyfn_obj, get_nbd_grads_fn)
File "/users/5/my_redacted_username/PyGRANSO/pygranso/private/bfgssqp.py", line 698, in getNearbyGradients
[*_,grads_ret,dist_evals] = grad_nbd_fn(penaltyfn_obj.getX(), grads)
File "/users/5/my_redacted_username/PyGRANSO/pygranso/private/neighborhoodCache.py", line 98, in <lambda>
get_neighborhood_fn = lambda x,x_data: self.getCachedNeighborhoodAbout(x,x_data)
File "/users/5/my_redacted_username/PyGRANSO/pygranso/private/neighborhoodCache.py", line 158, in getCachedNeighborhoodAbout
indx = (self.distances <= self.radius).cpu().numpy()
RuntimeError: Numpy is not available
Test 1 fail, please carefully read the instructions on https://ncvx.org/ for installation
Traceback (most recent call last):
File "/users/5/my_redacted_username/PyGRANSO/test_cuda.py", line 403, in <module>
rosenbrock()
File "/users/5/my_redacted_username/PyGRANSO/test_cuda.py", line 98, in rosenbrock
soln = pygranso(var_spec= var_in, combined_fn = comb_fn, user_opts = opts)
File "/users/5/my_redacted_username/PyGRANSO/pygranso/pygranso.py", line 523, in pygranso
soln.termination_code = info.termination_code
UnboundLocalError: local variable 'info' referenced before assignment
Summary
Since the last update of PyGRANSO, numpy 2 has released with breaking changes. The old
requirements.txtfiles did not need to specifynumpy<2in the past, but now this is needed (seemingly at least for cuda functionality).Minimal steps to reproduce:
1. repo setup
2a.
test_cuda.pyfails withrequirements.txtbut passes once we requirenumpy<2On a cuda-enabled machine, we can try
uv pip install -r requirements.txt -f https://download.pytorch.org/whl/cu111/torch_stable.html # ^ or `pip install -r requirements.txt -f https://download.pytorch.org/whl/cu111/torch_stable.html` python test_cuda.pywhich yields
(expand) error message
with package state
(expand) `pip freeze` result
Adding
numpy<2to the reqs file allowstest_cuda.pyto run correctly.i.e. change line:
numpy >= 1.20.3->numpy >= 1.20.3, < 2python test_cuda.pythen yields(expand) passing test output
2b.
test_cpu.pypasses withrequirements_cpu.txteven fornumpy==2.0.2First, we actually need to add
gurobipytorequirements_cpu.txt. Then, with a fresh venv, we can trywhich runs and passes the tests, even with
numpy>2(expand) passing test output
with package state
(expand) `pip freeze` result
I briefly attempted to test this with
requirements_linux_cpu.txt, but I had issues finding the specified torch version, so I decided it wasn't worth the effort to test.Possible action?
Would it make sense to patch the
requirements.txtfiles to includenumpy<2or otherwise record this requirement?Minor: additional info about the original error I experienced
In my particular (non-minimal example) case, I was actually getting a slightly different error involving
ImportError: cannot import name 'Inf' from 'numpy.core.numeric' (/users/5/my_redacted_username/.conda/envs/my_redacted_env_name/lib/python3.9/site-packages/numpy/core/numeric.py), perhaps because I had mixed numpy versions? Idk, conda weirdness.I was able to blame to find the exact numpy commit responsible for my error, which was in the
numpy.core.numericAPI at commit numpy/numpy@67d8d2c. In this commit,Infwas renamed toinfamong other changes. I switched from conda to uv, then tried addingnumpy<2to myrequirements.txt, and this fixed the error. I did not investigate any further, and there very well could be other spots broken bynumpy>=2.