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

integrator.py index error #19

Closed ellot closed 3 years ago

ellot commented 3 years ago

I run BXA in pyxspec, sometimes I got the following errors. It seems that the size of self.region is smaller than self.region_nodes.

"integrator.py", line 2494, in run_iter self.region.u[worst] = u IndexError: index 495 is out of bounds for axis 0 with size 484

JohannesBuchner commented 3 years ago

Could you please check if the problem goes away with the latest version?

ellot commented 3 years ago

I can't find UltraNest 4.0.

JohannesBuchner commented 3 years ago

Sorry, I got confused. You are using BXA v4.0?

JohannesBuchner commented 3 years ago

The line number makes me think a older UltraNest version is getting in between, because I have that command at line 2391. Can you try uninstalling and reinstalling ultranest?

ellot commented 3 years ago

Sorry, the line with this reported error is 2391. I use BXA version is 4.0.2, the ultranest version is 3.2. I can't find where to download ultranest 4.0. I have tried pip install and git clone methods, they both provide version 3.2.

JohannesBuchner commented 3 years ago

Somehow self.region_nodes and self.region.u become of different length, but I don't understand how.

                    worst = np.where(self.region_nodes == node.id)[0]
                    self.region_nodes[worst] = child.id
                    # if we keep the region informed about the new live points
                    # then the region follows the live points even if maxradius is not updated
                    self.region.u[worst] = u

They should only be simultaneously modified in _update_region, I think.

Can you try to reproduce the bug and put some prints / asserts in the ultranest code?

ellot commented 3 years ago

In some cases, the condition "good_region and (need_accept or nextregion.estimate_volume()<= self.region.estimate_volume()) and sensible_clustering" is False, so "self.region_nodes = active_node_ids.copy()" is skipped. I find this is the reason why self.region.u and self.region_nodes have different length.

JohannesBuchner commented 3 years ago

In that case self.region should still be the old value and self.region_nodes as well, and they should be in sync.

Maybe the problem is in this line: https://github.com/JohannesBuchner/UltraNest/blob/master/ultranest/integrator.py#L1799 Can you try adding there:

        self.region_nodes = active_node_ids.copy()
ellot commented 3 years ago

Thank you. This solution works well so far.

JohannesBuchner commented 3 years ago

Fixed as part of commit 9edb8150b0101ea61bcad23e72cbfc2de5d63fc2. Thanks!