JohannesBuchner / UltraNest

Fit and compare complex models reliably and rapidly. Advanced nested sampling.
https://johannesbuchner.github.io/UltraNest/
Other
142 stars 30 forks source link

[Docs] Outdated tutorial example #95

Closed JesusTorrado closed 1 year ago

JesusTorrado commented 1 year ago

Description

Trying to run this example, I get TypeError: ReactiveNestedSampler.run() got an unexpected keyword argument 'update_interval_iter_fraction' from line 51.

I assume update_interval_iter_fraction has been deprecated? (It's not in the main branch at least). What would be the equivalent one in the current version?

JohannesBuchner commented 1 year ago

Oh, thanks for noticing this!

It is called _update_interval_volumefraction.

Here is the API documentation: https://johannesbuchner.github.io/UltraNest/ultranest.html#ultranest.integrator.ReactiveNestedSampler.run

JesusTorrado commented 1 year ago

In case you want to give it a try, in Cobaya we do doctests to check for these kind of obsolescence, e.g. in https://cobaya.readthedocs.io/en/latest/example.html

We do it the following way, in this example:

  1. We put the source files in some folder: https://github.com/CobayaSampler/cobaya/tree/master/docs/src_examples/quickstart
  2. In the sphinx file, we use literalinclude to add them: https://raw.githubusercontent.com/CobayaSampler/cobaya/master/docs/example.rst
  3. We create a test that runs them using exec, and passing them some globals that are persistent between the different chunks of code: https://github.com/CobayaSampler/cobaya/blob/master/tests/test_docs_example_quickstart.py (alternatively, you may just want to run exec and not care about the result, just that it does not raise any exception.
JesusTorrado commented 1 year ago

Taking advantage of this thread, since it's about the same example: I have put a counter as a global inside the likelihood because it was apparently not receiving any vectorised call (with vectorized=True in run()), and after running it for dim=20, it only sends an input with more than one point twice out of 400k calls. It seems that the slice sampler cannot take advantage of a vectorised likelihood?

JohannesBuchner commented 1 year ago

In case you want to give it a try, in Cobaya we do doctests to check for these kind of obsolescence, e.g. in https://cobaya.readthedocs.io/en/latest/example.html

We do it the following way, in this example:

1. We put the source files in some folder: https://github.com/CobayaSampler/cobaya/tree/master/docs/src_examples/quickstart

2. In the sphinx file, we use `literalinclude` to add them: https://raw.githubusercontent.com/CobayaSampler/cobaya/master/docs/example.rst

3. We create a test that runs them using `exec`, and passing them some `globals` that are persistent between the different chunks of code: https://github.com/CobayaSampler/cobaya/blob/master/tests/test_docs_example_quickstart.py (alternatively, you may just want to run `exec` and not care about the result, just that it does not raise any exception.

Yes, that's a good point. I have done it in other projects (including portions of a script in sphinx, run the script as part of the CI), but I got lazy on this one. There is some computational cost attached to running all the (very extensive) unit and integration tests already, which I am conscious of.

JohannesBuchner commented 1 year ago

Taking advantage of this thread, since it's about the same example: I have put a counter as a global inside the likelihood because it was apparently not receiving any vectorised call (with vectorized=True in run()), and after running it for dim=20, it only sends an input with more than one point twice out of 400k calls. It seems that the slice sampler cannot take advantage of a vectorised likelihood?

That's right. There is an experimental vectorized step sampler (PopulationSliceSampler) which maintains a population of walkers. But it needs more development and debugging. It is briefly mentioned in issue #14 and #50, but probably we should create a new issue to explain the steps needed, if someone is motivated to take it on. Getting it in could be a major improvement for GPU-based and other machine-learning models.

JesusTorrado commented 1 year ago

I'll take a look at PopulationSliceSampler. I reckon AHARMSampler does not work yet? Is it hamiltonian (or can it take advantage of derivatives of the model w.r.t. the parameters? If so, I would be specially interested: for the project I mentioned on Tuesday in my talk re UltraNest, the ideal combination would be a hybrid MPI+vectorised sampler, using derivatives (since they are available).

JesusTorrado commented 1 year ago

There is some computational cost attached to running all the (very extensive) unit and integration tests already, which I am conscious of.

Just a dim=2 call under a try to check for deprecations should do the job and be cheap enough. But, of course, it's always people-time (actually implementing it) the limiting factor :)

JohannesBuchner commented 1 year ago

Docs are fixed, and the script is run as part of the CI now.