TuringLang / NestedSamplers.jl

Implementations of single and multi-ellipsoid nested sampling
https://turinglang.org/NestedSamplers.jl/stable/
MIT License
42 stars 8 forks source link

Progress bar #53

Closed adam-coogan closed 3 years ago

adam-coogan commented 3 years ago

Hi! Is there an easy way to add a progress bar to monitor sampling? If not, it would be great to add this using e.g. ProgressMeter.jl.

mileslucas commented 3 years ago

Believe it or not there is actually already a progress bar- it just doesn't work due to upstream issues (https://github.com/TuringLang/AbstractMCMC.jl/issues/24, https://github.com/JunoLab/ProgressLogging.jl/issues/27, https://github.com/JunoLab/ProgressLogging.jl/pull/32).

I am working on a better solution that also prints out convergence information as part of #46. For now, this is how I hook up a progress bar with ProgressMeter.jl using the callback interface

using ProgressMeter
using StatsFuns: logaddexp
function conv_callback(rng, m, sampler, t, iteration; pbar, dlogz=0.5, kwargs...)
    # Don't accidentally short-circuit
    iteration > 2 || return false
    logz_remain = maximum(sampler.active_logl) - (iteration - 1) / sampler.nactive
    dlogz_current = logaddexp(sampler.logz, logz_remain) - sampler.logz
    ProgressMeter.update!(pbar, dlogz_current)
    return dlogz_current < dlogz
end
ns = Nested(3, 500)
out = sample(model, ns, conv_callback; pbar=ProgressThresh(0.5, "ΔlnZ = "));
mileslucas commented 3 years ago

The newest release (v0.6.0) has a hand-written status output now, which works okay although I'd like to see a more refined solution in the future. Here is an example of what that looks like (in addition to the ProgressLogging.jl progress bar)- Screenshot 2021-04-12 003753

I'm going to go ahead and close this, but if you have any problems or want to reopen discussion, don't hesitate to open this back up!