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

tregion argument is not supported by dychmc dychmc __next__ function #116

Closed odstrcilt closed 6 months ago

odstrcilt commented 7 months ago

I'm trying to use DynamicCHMCSampler, but it does not work in the current ultranest version

Here is the code:

from ultranest import ReactiveNestedSampler
sampler = ReactiveNestedSampler(paramnames,
                                loglike,
                                transform=transform,
                                log_dir=log_dir,
                                resume=True,
                                vectorized=True)
import ultranest.dychmc
from ultranest.utils import verify_gradient

stepsampler = ultranest.dychmc.DynamicCHMCSampler(
    scale=0.1 * ndim **0.5,    
    nsteps=args.slice_steps,
    adaptive_nsteps=adaptive_nsteps)
stepsampler.set_gradient(gradient)
sampler.stepsampler = stepsampler

sampler.run(frac_remain=0.5,
            min_num_live_points=args.num_live_points,
            max_num_improvement_loops=0)

It returns the following error:

Traceback (most recent call last):
  File "/home/odstrcilt/ida_lite/./test_ultranest.py", line 193, in <module>
    main(args)
  File "/home/odstrcilt/ida_lite/./test_ultranest.py", line 148, in main
    sampler.run(frac_remain=0.5,
  File "/fusion/ga/projects/ird/ida_ird/codes/conda_envs/ird_ida_env/lib/python3.10/site-packages/ultranest/integrator.py", line 2370, in run
    for result in self.run_iter(
  File "/fusion/ga/projects/ird/ida_ird/codes/conda_envs/ird_ida_env/lib/python3.10/site-packages/ultranest/integrator.py", line 2641, in run_iter
    u, p, L = self._create_point(Lmin=Lmin, ndraw=ndraw, active_u=active_u, active_values=active_values)
  File "/fusion/ga/projects/ird/ida_ird/codes/conda_envs/ird_ida_env/lib/python3.10/site-packages/ultranest/integrator.py", line 1878, in _create_point
    u, v, logl, nc = self.stepsampler.__next__(
TypeError: DynamicCHMCSampler.__next__() got an unexpected keyword argument 'tregion'

The issues is here, where the _next function of DynamicCHMCSampler is called with tregion argument https://github.com/JohannesBuchner/UltraNest/blob/77393bf69d5d4f34fbd6641ad22537b10b6e139d/ultranest/integrator.py#L1670

Can you fix it?

JohannesBuchner commented 7 months ago

I think you have to edit the __next__ function in ultranest.dychmc.DynamicCHMCSampler to add the keyword argument tregion=None

odstrcilt commented 7 months ago

This is precisely what I did, and it works. Can you just change it in DynamicCHMCSampler and DynamicHMCSampler source code in the repository?

JohannesBuchner commented 7 months ago

If you want to accelerate this, please create a pull request.

odstrcilt commented 7 months ago

I can only make a new branch with forking your project. Since it is so trivial change, it will be much faster if you just do it.

JohannesBuchner commented 6 months ago

As you can see, I am having trouble finding the time, please help