Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Buffer has wrong number of dimensions (expected 2, got 0) #85

Open
pietroleonardi opened this issue Jan 31, 2023 · 1 comment

Comments

@pietroleonardi
Copy link

  • UltraNest version: 3.5.7
  • Python version: 3.9.15
  • Operating System: Linux Mint 20.1

Description

I am using UltraNest to try to reproduce a injection retrieval example from Pandora, a open-source exomoon transit detection algorithm. However I am trying to fit the synthetic data with the model produced by the code Gefera, a generic code for light curves of two bodies mutually transiting a star.

My scrypt is extremely similar to the one found here, I just changed the likelihood function in order to create the model using gefera and modified the parameters.

After a few seconds of running, this is the error that I get:

Traceback (most recent call last):-3917.31 [-53114.9584..-5841.1897] | it/evals=14/18559 eff=0.0797% N=1000  
  File "/home/pietro/Desktop/PhD/Work/gefera/ultranest+ge.py", line 233, in <module>
    result_planet_moon = sampler.run(min_num_live_points=1000)
  File "/home/pietro/anaconda3/envs/pandora_env/lib/python3.9/site-packages/ultranest/integrator.py", line 2311, in run
    for result in self.run_iter(
  File "/home/pietro/anaconda3/envs/pandora_env/lib/python3.9/site-packages/ultranest/integrator.py", line 2527, in run_iter
    region_fresh = self._update_region(
  File "/home/pietro/anaconda3/envs/pandora_env/lib/python3.9/site-packages/ultranest/integrator.py", line 1961, in _update_region
    _update_region_bootstrap(self.region, nbootstraps, minvol, self.comm if self.use_mpi else None, self.mpi_size)
  File "/home/pietro/anaconda3/envs/pandora_env/lib/python3.9/site-packages/ultranest/integrator.py", line 369, in _update_region_bootstrap
    r, f = region.compute_enlargement(
  File "ultranest/mlfriends.pyx", line 855, in ultranest.mlfriends.MLFriends.compute_enlargement
  File "ultranest/mlfriends.pyx", line 388, in ultranest.mlfriends.bounding_ellipsoid
  File "ultranest/mlfriends.pyx", line 303, in ultranest.mlfriends.make_eigvals_positive
ValueError: Buffer has wrong number of dimensions (expected 2, got 0)

What I Did

I start my scrypt by simulating my timing data, with the algorithm Pandora. Then I define the prior_transform function and the log_likelihood function:

def prior_transform(cube):
    p     = cube.copy()
    #Planet
    p[0]  = cube[0] * 10 + 360.25    # Period_planet [days]
    p[1]  = cube[1] * 300 + 1        # Semi major axis planet [R_star]
    p[2]  = cube[2] * 360            # Mean anomaly [0..360] [deg]
    p[3]  = cube[3] * 1 + 89         # Inclination planet [0..90] [deg]
    #Moon 
    p[4]  = cube[4] * 1 + 0.005      # Semi major axis moon [R_star]
    p[5]  = cube[5] * 1              # Time of pericenter passage tau_moon normalized by the period [0..1]
    p[6]  = cube[6] * 50             # Period moon [days]
    p[7]  = cube[7] * np.pi          # Longitude of the ascending node moon [rad]
    p[8]  = cube[8] * np.pi          # Inclination omoon [0...pi] [rad]
    p[9]  = cube[9] * 1              # Moon/Planet mass ratio [0..1]
    #Other parameters
    p[10] = cube[10] * 0.04 + 0.09   # Planet radius [R_star]
    p[11] = cube[11] * 0.06 + 0.01   # Moon radius [R_star]
    p[12] = cube[12]                 # LD q1 [0..1]
    p[13] = cube[13]                 # LD q2 [0..1]
    return p
def log_likelihood(p):
    # Convert q priors to u LDs (Kipping 2013)
    q1 = p[12]
    q2 = p[13]
    u1, u2 = ld_convert(q1, q2)
    ap=p[1]
    tp=p[0] * p[2] / 360
    ep=0
    pp = p[0]
    wp=90 * np.pi / 180
    ip=p[3] * np.pi / 180 
    am=p[4]
    tm=p[5] * p[6]
    em=0
    pm=p[6]
    om=p[7]
    wm=-90 * np.pi / 180
    im=p[8]
    mm=p[9]
    rp=p[10]
    rm=p[11]
    po = gf.orbits.PrimaryOrbit(ap, tp, ep, pp, wp, ip)
    mo = gf.orbits.SatelliteOrbit(am, tm, em, pm, om, wm, im, mm)
    sys = gf.systems.HierarchicalSystem(po, mo)
    flux= sys.lightcurve(time, u1, u2, rp, rm, grad=False) + 1
    sigma = 500e-6
    loglike = -0.5 * np.nansum(((flux - testdata) / sigma)**2)
    return loglike
parameters = [
    'Period_p', 
    'a_planet', 
    'Mean Anomaly', 
    'Inclination',
    'a_moon',
    'tau_moon',
    'Period_moon',
    'Omega_moon',
    'inclination_moon',
    'Mm/Mp',
    'Radius_p',
    'Radius_m',
    'q1',
    'q2'
    ]

These are the sampler and step.sampler:

sampler = ReactiveNestedSampler(
            parameters,
            log_likelihood, 
            prior_transform,
            wrapped_params=wrapped_params,
            log_dir="results_injection_retrieval_planet_moon"
            )

sampler.stepsampler = ultranest.stepsampler.RegionSliceSampler(
    nsteps=4000,
    adaptive_nsteps='move-distance',
    )

result_planet_moon = sampler.run(min_num_live_points=1000)

I am attaching the debug.log

@JohannesBuchner
Copy link
Owner

JohannesBuchner commented Jan 31, 2023

Hmm, this is rather strange.

Can it be that you run out of live points?

According to the debug.log, you have a likelihood plateau, interestingly not at the beginning of the run but after a few iterations.

Maybe you want to check why all the points then return loglike=-5841.19.

That said, this error message is not very helpful, and it should be handled better. But I don't quite understand how this occurs.

Maybe putting a few prints in these lines could help debug:

  "/home/pietro/anaconda3/envs/pandora_env/lib/python3.9/site-packages/ultranest/integrator.py", line 369
  File "ultranest/mlfriends.pyx", line 855, in ultranest.mlfriends.MLFriends.compute_enlargement
  File "ultranest/mlfriends.pyx", line 388, in ultranest.mlfriends.bounding_ellipsoid
  File "ultranest/mlfriends.pyx", line 303, in ultranest.mlfriends.make_eigvals_positive

In particular: Is the list of live points empty? What is the highest level loop where this occurs?
In integrator.py, perhaps the integration should stop when the live points cannot be replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants