JohannesBuchner / UltraNest

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

AttributeError: 'ReactiveNestedSampler' object has no attribute 'logger' #1

Closed ajdittmann closed 4 years ago

ajdittmann commented 4 years ago

Description

I attempted to apply UltraNest to a test problem, using MPI. After a warning message that UltraNest was unable to update a region, as well as numpy singular matrix errors associated with ultranest/integrator.py, I received the message:

During handling of the above exception, another exception occurred:
/anaconda3/lib/python3.7/site-packages/ultranest/integrator.py", line 1519, in _update_region
    self.logger.warning("not updating region", exc_info=True)
AttributeError: 'ReactiveNestedSampler' object has no attribute 'logger'

after which the job stalled until I interrupted it. A full traceback is attached. This occurred after about 46,000 iterations. ultranest_error_log.txt

JohannesBuchner commented 4 years ago

Thank you for testing UltraNest and reporting a detailed bug report. I see the issue, there should be a "if self.log:" there. I pushed a patch to the repository, could you test it? You should be able to resume if you wrote to disk (log_dir, resume=True).

ajdittmann commented 4 years ago

The error reported here seems to be fixed, it did not occur again. Thank you for the quick action. The sampler still seems to stall at a similar place, but I will investigate this more since no errors were reported.

JohannesBuchner commented 4 years ago

If you have left viz_callback, show_status at their defaults, then you should see where the live points are currently distributed.

In my experience, this issue can occur when the current live points are linearly correlated, i.e., they have collapsed to a <d dimensional surface. UltraNest conservatively does not update the region in those cases, because it would induce biases. However, this can make sampling slow. Collapse to a sub-surface can happen either: a) because the loglikelihood is misdefined (e.g., parameter2=parameter1, otherwise likelihood is extreme). You can diagnose this with the output telling you "parameter 2 is perfectly correlated with parameter 1" (before showing the live point distribution). b) You are using a step sampler that is poorly converging (too few steps).

What dimensionality is your problem and do you use a step sampler?

ajdittmann commented 4 years ago

Where can I see the live point distribution? I haven't specified anything for viz_callback or show_status. I see that points.hdf5 in results is updated over the course of a run, but nothing is added to the plots directory until a run finishes. I've tested this using the gauss.py example you provided on github.io/UltraNest.

I am using ReactiveNestedSampler, and the problem is 12-dimensional. Based off of my knowledge of the posterior, the live points should end up clustered along the edge of the prior in 1 out of the 12 dimensions, but the others should be fairly well behaved.

JohannesBuchner commented 4 years ago

You should see it in the stdout.

ajdittmann commented 4 years ago

Ah, so you mean the ASCII outputs? I have fixed the error (a typo in my prior) and am trying the test again.

However, I would like to clarify how UltraNest works: Let's say I am testing two models, with 2 parameters and 4, and if the additional parameters in the second model are both 0, the second model reduces to the first. I would like to compare these models. If nonzero 3rd and 4th parameters decrease the likelihood, I would expect the live points to cluster near 0 in both parameters. Will UltraNest be able to sample this? Will it continue sampling, just without updating the region?

JohannesBuchner commented 4 years ago

Yes, it's explained here https://johannesbuchner.github.io/UltraNest/issues.html under "What does the live point display mean?"

Yes, it should sample such problems fine. Given that you only have 4 parameters, the efficiency should be very high with UltraNest.

andrewfowlie commented 4 years ago

I get similar errors when run with mpirun

  File "/usr/local/lib/python3.6/dist-packages/ultranest/integrator.py", line 1714, in run
    viz_callback=viz_callback,
  File "/usr/local/lib/python3.6/dist-packages/ultranest/integrator.py", line 2035, in run_iter
    (Llo_Z, Lhi_Z), (Llo_KL, Lhi_KL), (Llo_ess, Lhi_ess) = self._find_strategy(saved_logl, main_iterator, dlogz=dlogz, dKL=dKL, min_ess=min_ess)
  File "/usr/local/lib/python3.6/dist-packages/ultranest/integrator.py", line 1126, in _find_strategy
    self.logger.info('  logZ error budget: single: %.2f bs:%.2f tail:%.2f total:%.2f required:<%.2f',
AttributeError: 'ReactiveNestedSampler' object has no attribute 'logger'
JohannesBuchner commented 4 years ago

@andrewfowlie please try with the latest commit in master.

andrewfowlie commented 4 years ago

Will check later, but I think this line should be indebted to be inside the elif statement

https://github.com/JohannesBuchner/UltraNest/blob/90c7987c31ae8c83490e4453b3fa19ddb605c7ba/ultranest/integrator.py#L1126

JohannesBuchner commented 4 years ago

Hi @andrewfowlie & @ajdittmann,

How is ultranest working for you so far?

alexkolo commented 4 years ago

So, I'm having the same problem with version 2.0.0, which only occurs when using MPI. When I execute it inline (within in ipython), where I only can use one core, i don't get this error message. Unfortunately, each run takes 10min (or longer). So, it's very annoying to test. How can I set up parameters in a way, that it makes a very quick run? I'm already using only 100 min_num_live_points.

alexkolo commented 4 years ago

Ok. I downloaded the version 2.0.3 directly from git and trying it with this one.

JohannesBuchner commented 4 years ago

2.0.3 is also available through PyPI

alexkolo commented 4 years ago

So, after manually downloading and installing the 2.0.3 version it worked. But again my question, how can I make a quick run, other than setting min_num_live_points to 100 or lower?

JohannesBuchner commented 4 years ago

ultranest tries hard to be reliable ... making a quick and dirty run is not so easy -- you can decrease min_num_live_points to 100, set the per_cluster live points to zero, and perhaps use a step sampler with only one step. However, at that point you may as well use a optimizer to find the best fit.

alexkolo commented 4 years ago

Thanks. That's what I need. (and sorry for derailing) It's not about having a quick way of getting best-fit values (in fact, for this i'm using scipy_leastsq ). it's just about quickly testing my code, when using ultranest. BTW, so far it works great.

andrewfowlie commented 4 years ago

@JohannesBuchner I haven’t had a good look yet. I was doing some comparisons of a few NS implementations. I’ll share the results sometime soon.

Do you have a paper describing the MLFriends part of the algorithm? I could only find descriptions of RadFriends and SupFriends on the arXiv.

JohannesBuchner commented 4 years ago

It is briefly mentioned in the https://arxiv.org/abs/1707.04476 paper -- basically it is RadFriends, but the metric is the Mahalanobis metric.

In the utlranest implementation, the metric is iteratively learned and refined by clustering with the MLFriends radius. Additionally, region updates are only accepted when the region shrinks. This avoids region expansions when a distant mode separates out or starts to vanish.

ajdittmann commented 4 years ago

@JohannesBuchner My exploration of UltraNest has been put on hold by cluster upgrades/administration. I'll let you know if I run into any issues.

adipol-ph commented 1 year ago

I also got this problem when I tried to run a script with mpiexec. It seems that self.logger.debug in self._widen_roots_beyond_initial_plateau needs if self.log:.

  File "/packages/spidersoft/python/3.10.11/virtualenvs/spiders/lib/python3.10/site-packages/ultranest/integrator.py", line 2369, in run
    for result in self.run_iter(
  File "/packages/spidersoft/python/3.10.11/virtualenvs/spiders/lib/python3.10/site-packages/ultranest/integrator.py", line 2468, in run_iter
    self._widen_roots_beyond_initial_plateau(
  File "/packages/spidersoft/python/3.10.11/virtualenvs/spiders/lib/python3.10/site-packages/ultranest/integrator.py", line 1447, in _widen_roots_beyond_initial_plateau
    self.logger.debug(
AttributeError: 'ReactiveNestedSampler' object has no attribute   'logger'
JohannesBuchner commented 1 year ago

Yes, that's a bug @adipol-ph. Could you please make a pull request with a fix?

JohannesBuchner commented 1 year ago

see https://github.com/JohannesBuchner/UltraNest/issues/107 , please update to ultranest 3.6.3