Which numpy version is compatible with prospector?
Recently I updated my numpy installation to version 2.2.1 and now I get the following message when I import prospector:
A module that was compiled using NumPy 1.x cannot be run in NumPy 2.2.1 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 "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/home/csa/.local/lib/python3.10/site-packages/ipykernel_launcher.py", line 17, in
app.launch_new_instance() File "/home/csa/.local/lib/python3.10/site-packages/traitlets/config/application.py", line 1043, in launch_instance app.start() File "/home/csa/.local/lib/python3.10/site-packages/ipykernel/kernelapp.py", line 725, in start self.io_loop.start() File "/home/csa/.local/lib/python3.10/site-packages/tornado/platform/asyncio.py", line 215, in start self.asyncio_loop.run_forever() File "/usr/lib/python3.10/asyncio/base_events.py", line 600, in run_forever self._run_once() File "/usr/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once ... File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/home/csa/.local/lib/python3.10/site-packages/numexpr/init.py", line 24, in from numexpr.interpreter import MAX_THREADS, use_vml, BLOCK_SIZE1 Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
AttributeError Traceback (most recent call last) AttributeError: _ARRAY_API not found
Unfortunately, I didn't keep track of the numpy version I was using before I updated. Is there a version of numpy that is known to be compatible with Prospector?
I'm not sure how you installed; you might try reinstalling fsps and prospector via pip to a clean environment and seeing if the problem persists. The released version 1.4 has been updated to work with numpy >2.0, but if you still encounter issues with numpy 2.2.1 please do report here, and I will try to reproduce
Hi, i have a similar issue. My numpy and prospector versions:
In [1]: import numpy as np
In [2]: print(np.__version__)
2.2.4
In [3]: import prospect
In [4]: print(prospect.__version__)
1.4.0
I got this error while I was doing quickstart from running fitting_kwargs = dict(nlive_init=400, nested_method="rwalk", nested_target_n_effective=1000, nested_dlogz_init=0.05) output = fit_model(obs, model, sps, optimize=False, dynesty=True, lnprobfn=lnprobfn, noise=noise_model, **fitting_kwargs) result, duration = output["sampling"] in the "Run a fit" section:
Exception while calling loglikelihood function:
params: [ 1.78401711e+11 -1.79306019e+00 1.10590425e+00 1.03538261e+01
6.27079305e+00]
args: []
kwargs: {}
exception:
Traceback (most recent call last):
File "/usr/lib/python3.13/site-packages/dynesty/dynesty.py", line 913, in __call__
return self.func(np.asarray(x).copy(), *self.args, **self.kwargs)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/baris/.local/lib/python3.13/site-packages/prospect/fitting/fitting.py", line 90, in lnprobfn
lnnull = -np.infty
^^^^^^^^
File "/usr/lib/python3.13/site-packages/numpy/__init__.py", line 400, in __getattr__
raise AttributeError(
...<3 lines>...
)
AttributeError: `np.infty` was removed in the NumPy 2.0 release. Use `np.inf` instead.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[11], line 2
1 fitting_kwargs = dict(nlive_init=400, nested_method="rwalk", nested_target_n_effective=1000, nested_dlogz_init=0.05)
----> 2 output = fit_model(obs, model, sps, optimize=False, dynesty=True, lnprobfn=lnprobfn, noise=noise_model, **fitting_kwargs)
3 result, duration = output["sampling"]
File ~/.local/lib/python3.13/site-packages/prospect/fitting/fitting.py:259, in fit_model(obs, model, sps, noise, lnprobfn, optimize, emcee, dynesty, **kwargs)
256 else:
257 return output
--> 259 output["sampling"] = run_sampler(obs, model, sps, noise,
260 lnprobfn=lnprobfn, **kwargs)
261 return output
File ~/.local/lib/python3.13/site-packages/prospect/fitting/fitting.py:532, in run_dynesty(obs, model, sps, noise, lnprobfn, pool, nested_target_n_effective, **kwargs)
529 # Need to deal with postkwargs...
531 t = time.time()
--> 532 dynestyout = run_dynesty_sampler(lnp, model.prior_transform, model.ndim,
533 stop_function=stopping_function,
534 wt_function=weight_function,
535 nested_stop_kwargs=nested_stop_kwargs,
536 pool=pool, **kwargs)
537 ts = time.time() - t
539 return dynestyout, ts
File ~/.local/lib/python3.13/site-packages/prospect/fitting/nested.py:84, in run_dynesty_sampler(lnprobfn, prior_transform, ndim, verbose, nested_bound, nested_sample, nested_walks, nested_update_interval, nested_bootstrap, pool, use_pool, queue_size, nested_nlive_init, nested_dlogz_init, nested_maxiter_init, nested_maxcall_init, nested_live_points, nested_maxbatch, nested_nlive_batch, nested_maxiter_batch, nested_maxcall_batch, nested_use_stop, nested_maxcall, nested_maxiter, nested_first_update, stop_function, wt_function, nested_weight_kwargs, nested_stop_kwargs, nested_save_bounds, print_progress, **extras)
82 niter = [dsampler.it](http://dsampler.it/) - 1
83 tstart = time.time()
---> 84 for results in dsampler.sample_initial(nlive=nested_nlive_init,
85 dlogz=nested_dlogz_init,
86 maxcall=nested_maxcall_init,
87 maxiter=nested_maxiter_init,
88 live_points=nested_live_points):
90 try:
91 # dynesty >= 2.0
92 (worst, ustar, vstar, loglstar, logvol,
93 logwt, logz, logzvar, h, nc, worst_it,
94 propidx, propiter, eff, delta_logz, blob) = results
File /usr/lib/python3.13/site-packages/dynesty/dynamicsampler.py:1289, in DynamicSampler.sample_initial(self, nlive, update_interval, first_update, maxiter, maxcall, logl_max, dlogz, n_effective, live_points, save_samples, resume)
1284 if not resume:
1285 # Reset saved results to avoid any possible conflicts.
1286 self.reset()
1288 (self.live_u, self.live_v, self.live_logl,
-> 1289 blobs), logvol_init, init_ncalls = _initialize_live_points(
1290 live_points,
1291 self.prior_transform,
1292 self.loglikelihood,
1293 self.M,
1294 nlive=nlive,
1295 ndim=self.ndim,
1296 rstate=self.rstate,
1297 blob=self.blob,
1298 use_pool_ptform=self.use_pool_ptform)
1299 if self.blob:
1300 self.live_blobs = blobs
File /usr/lib/python3.13/site-packages/dynesty/dynamicsampler.py:438, in _initialize_live_points(live_points, prior_transform, loglikelihood, M, nlive, ndim, rstate, blob, use_pool_ptform)
436 cur_live_v = map(prior_transform, np.asarray(cur_live_u))
437 cur_live_v = np.array(list(cur_live_v))
--> 438 cur_live_logl = loglikelihood.map(np.asarray(cur_live_v))
439 if blob:
440 cur_live_blobs = np.array([_.blob for _ in cur_live_logl])
File /usr/lib/python3.13/site-packages/dynesty/utils.py:172, in LogLikelihood.map(self, pars)
162 """
163 Evaluate the likelihood function on the list of vectors
164 The pool is used if it was provided when the object was created
(...) 168 ret: The list of LoglOutput objects
169 """
170 if self.pool is None:
171 ret = list([
--> 172 LoglOutput(_, self.blob) for _ in map(self.loglikelihood, pars)
173 ])
174 else:
175 ret = [
176 LoglOutput(_, self.blob)
177 for _ in self.pool.map(self.loglikelihood, pars)
178 ]
File /usr/lib/python3.13/site-packages/dynesty/dynesty.py:913, in _function_wrapper.__call__(self, x)
905 def __call__(self, x):
906 try:
907 # IMPORTANT
908 # Here we make a copy if the input vector just to ensure
(...) 911 # This comes at performance cost, but it's worthwhile
912 # as it may lead to hard to diagnose weird behaviour
--> 913 return self.func(np.asarray(x).copy(), *self.args, **self.kwargs)
914 except: # noqa
915 print(f"Exception while calling {[self.name](http://self.name/)} function:")
File ~/.local/lib/python3.13/site-packages/prospect/fitting/fitting.py:90, in lnprobfn(theta, model, obs, sps, noise, residuals, nested, negative, verbose)
87 lnnull = np.zeros(obs["ndof"]) - 1e18 # np.infty
88 #lnnull = -np.infty
89 else:
---> 90 lnnull = -np.infty
92 # --- Calculate prior probability and exit if not within prior ---
93 lnp_prior = model.prior_product(theta, nested=nested)
File /usr/lib/python3.13/site-packages/numpy/__init__.py:400, in __getattr__(attr)
397 raise AttributeError(__former_attrs__[attr], name=None)
399 if attr in __expired_attributes__:
--> 400 raise AttributeError(
401 f"`np.{attr}` was removed in the NumPy 2.0 release. "
402 f"{__expired_attributes__[attr]}",
403 name=None
404 )
406 if attr == "chararray":
407 warnings.warn(
408 "`np.chararray` is deprecated and will be removed from "
409 "the main namespace in the future. Use an array with a string "
410 "or bytes dtype instead.", DeprecationWarning, stacklevel=2)
AttributeError: `np.infty` was removed in the NumPy 2.0 release. Use `np.inf` instead.
Thanks! I thought I'd caught all the numpy >= 2 incompatibilities, but it seems not. I think this will require a patch release, i.e. v1.4.1
Also upvoting the need for a numpy >=2 compatible release. I'd like to try prospector but this is a large hurdle to overcome.
If it's helpful, I was facing exactly the same issue, and created a branch which just fixed a couple of these minor numpy V2 compatibility issues: https://github.com/robertdstein/prospector/tree/v1.4.1
Not sure if there's a possibility to merge/deploy it to PyPi though given how far the main branch has diverged, but happy to open a PR if that's useful.
We can deploy a patched version to PyPI. It would be great to have a PR onto the v1.4 branch.
I note that np.trapz is also deprecated, so it might be good to address that now if it's an issue
PR #388 has been merged (which includes commit 8e6ebad), which should allow for full NumPy 2.0 compatibility. PR #390 officially drops support for NumPy 1.x since it's officially end-of-life (link), but is not merged yet.
I note that
np.trapzis also deprecated, so it might be good to address that now if it's an issue
I am now experiencing that issue.
I've released a v1.4.1 with a fix for this courtesy of @robertdstein. It still requires dynesty < 3 though.
I see, thanks!