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

Incompatible with numpy 2.0.0rc1 #509

Closed
MuellerSeb opened this issue Apr 4, 2024 · 3 comments
Closed

Incompatible with numpy 2.0.0rc1 #509

MuellerSeb opened this issue Apr 4, 2024 · 3 comments

Comments

@MuellerSeb
Copy link
Contributor

Numpy 2 is around the corner with having its first release candidate: https://pypi.org/project/numpy/2.0.0rc1

emcee at least uses VisibleDeprecationWarning from numpy that will be removed with numpy 2: https://numpy.org/devdocs/release/2.0.0-notes.html

Warnings and exceptions present in numpy.exceptions (e.g, ComplexWarning, VisibleDeprecationWarning) are no longer exposed in the main namespace.

So with the release of numpy 2, emcee will run into some troubles.

@MuellerSeb
Copy link
Contributor Author

Was introduced here: #361

@MuellerSeb
Copy link
Contributor Author

But even doing from numpy.exceptions import VisibleDeprecationWarning and replacing np.VisibleDeprecationWarning with VisibleDeprecationWarning in ensemble.py, I run into the following error:

File ~/AtWork/Cloud/GIT/GitHub/GeoStat/GSTools/src/gstools/random/rng.py:92, in RNG.sample_ln_pdf(self, ln_pdf, size, sample_around, nwalkers, burn_in, oversampling_factor)
     90 initial_state = State(init_guess, copy=True)
     91 initial_state.random_state = self.random.get_state()
---> 92 burn_in_state = sampler.run_mcmc(
     93     initial_state=initial_state, nsteps=burn_in
     94 )
     95 # reset after burn_in
     96 sampler.reset()

File ~/mambaforge/envs/gstools_np2/lib/python3.12/site-packages/emcee/ensemble.py:444, in EnsembleSampler.run_mcmc(self, initial_state, nsteps, **kwargs)
    441     initial_state = self._previous_state
    443 results = None
--> 444 for results in self.sample(initial_state, iterations=nsteps, **kwargs):
    445     pass
    447 # Store so that the ``initial_state=None`` case will work

File ~/mambaforge/envs/gstools_np2/lib/python3.12/site-packages/emcee/ensemble.py:411, in EnsembleSampler.sample(self, initial_state, log_prob0, rstate0, blobs0, iterations, tune, skip_initial_state_check, thin_by, thin, store, progress, progress_kwargs)
    409 # Save the new step
    410 if store and (i + 1) % checkpoint_step == 0:
--> 411     self.backend.save_step(state, accepted)
    413 pbar.update(1)
    414 i += 1

File ~/mambaforge/envs/gstools_np2/lib/python3.12/site-packages/emcee/backends/backend.py:228, in Backend.save_step(self, state, accepted)
    226 self.log_prob[self.iteration, :] = state.log_prob
    227 if state.blobs is not None:
--> 228     self.blobs[self.iteration, :] = state.blobs
    229 self.accepted += accepted
    230 self.random_state = state.random_state

ValueError: could not broadcast input array from shape (50,0) into shape (50,)

So there is more to it...

@dfm
Copy link
Owner

dfm commented Apr 4, 2024

Thanks for bringing this up! I've been meaning to look into this, but I'm not 100% sure how much capacity I'll have. If you or anyone else wants to start looking into this and opening up a PR that would be very much appreciated!!

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

No branches or pull requests

2 participants