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

Increase speed by reducing overhead #47

Closed hippke closed 2 years ago

hippke commented 2 years ago

Thank you for UltraNest, which I really like!

I have a question regarding speed. I have a model with 13 free parameters. It is quite simple, and coded in Python / numba for speed. In a simple loop, I can execute 100,000 likelihood evaluations per second on a single core.

When I run the UltraNest ReactiveNestedSampler with this model, I see in the log it/evals=4857/97721 after the first minute. So, UltraNest makes 100,000 function calls per minute. In other words, only ~1% of the time is spent in making model evaluations, and 99% in UltraNest.

I also tried a vectorized version, but it is almost exactly the same: 99% is UltraNest-time, not model-time.

Is there anything I'm missing? Or are 100k evaluations per minute just normal and can't be improved? Is something wrong with my setup? I'd appreciate a baseline from your experience: How many evals per minute can be expected for a fast model with 13 parameters?

JohannesBuchner commented 2 years ago

If you have a easy problem with high proposal efficiency and quick model evaluation, UltraNest internal computation is all that is left. This typically changes later in the run when the efficiency goes down. You can control with ndraw_min and ndraw_max parameters if you want more vectorization (and thus fewer loops in ultranest) in favor of more model evaluations.

UltraNest has to compute new proposal regions. You could change how often it does that (update_interval_volume_fraction or update_interval_ncall).

You can also speed up by disabling callbacks/visualisations (viz_callback=None, show_status=False).

100,000 function calls per minute sounds not unusual, for the moment, but with the above arguments you may be able to improve that.

If these tips do not help, please profile (cProfile & snakeviz) and let me know where it spends most time.