Error when running bilby.run_sampler on a simple exercise
Hi, starting from the notebook https://github.com/gw-odw/odw-2022/blob/main/Tutorials/Day_3/Tuto_3.2_Parameter_estimation_for_compact_object_mergers.ipynb I am trying to find a way to change the prior is such a way that most of the parameters are described by functions and not with fixed numbers. More specifically, if in the list of priors defined in cell [15] I change just the priors on
prior['ra'] = Uniform(name='ra', minimum=0, maximum=2 * np.pi, boundary='periodic')
prior['luminosity_distance'] = bilby.core.prior.PowerLaw(alpha=2., minimum=50., maximum=800., name='luminosity_distance')
and then I use as options for the sampler
result_long = bilby.run_sampler( likelihood, prior, sampler='dynesty', outdir='long', label="GW150914", conversion_function=bilby.gw.conversion.generate_all_bbh_parameters, sample="rwalk", nact=1, walks=1, nlive=500, dlogz=3)
I get the output copied at the end. I am using igwn-py39 on a local mac with bilby=1.1.2. I tried to run a similar code on google colab (installing the version of the packages at the top of the notebook) and I still have errors even if not exactly the same to what I have locally. I am sure I am doing something silly without realising it.
Agata
17:05 bilby INFO : Running for label 'GW150914', output will be saved to 'long'
17:05 bilby INFO : Using lal version 7.1.7
17:05 bilby INFO : Using lal git version Branch: None;Tag: lal-v7.1.7;Id: c0930b69d9f2ad7151d1cadea5df72633ec47e67;;Builder: Adam Mercer <adam.mercer@ligo.org>;Repository status: CLEAN: All modifications committed
17:05 bilby INFO : Using lalsimulation version 3.1.2
17:05 bilby INFO : Using lalsimulation git version Branch: None;Tag: lalsimulation-v3.1.2;Id: 8c3a6977aa553c9a2019ec287a61dc5ee92087b4;;Builder: Adam Mercer <adam.mercer@ligo.org>;Repository status: CLEAN: All modifications committed
17:05 bilby INFO : Search parameters:
17:05 bilby INFO : chirp_mass = Uniform(minimum=30.0, maximum=32.5, name='chirp_mass', latex_label='$\\mathcal{M}$', unit=None, boundary=None)
17:05 bilby INFO : mass_ratio = Uniform(minimum=0.5, maximum=1, name='mass_ratio', latex_label='$q$', unit=None, boundary=None)
17:05 bilby INFO : ra = Uniform(minimum=0, maximum=6.283185307179586, name='ra', latex_label='$\\mathrm{RA}$', unit=None, boundary='periodic')
17:05 bilby INFO : luminosity_distance = PowerLaw(alpha=2.0, minimum=50.0, maximum=800.0, name='luminosity_distance', latex_label='$d_L$', unit=None, boundary=None)
17:05 bilby INFO : time_jitter = Uniform(minimum=-0.000244140625, maximum=0.000244140625, name='time_jitter', latex_label='$t_j$', unit=None, boundary='periodic')
17:05 bilby INFO : phase = 0.0
17:05 bilby INFO : geocent_time = 1126259460.3999023
17:05 bilby INFO : a_1 = 0.0
17:05 bilby INFO : a_2 = 0.0
17:05 bilby INFO : tilt_1 = 0.0
17:05 bilby INFO : tilt_2 = 0.0
17:05 bilby INFO : phi_12 = 0.0
17:05 bilby INFO : phi_jl = 0.0
17:05 bilby INFO : dec = -1.2232
17:05 bilby INFO : theta_jn = 1.89694
17:05 bilby INFO : psi = 0.532268
17:05 bilby INFO : Single likelihood evaluation took 3.394e-03 s
0/? [00:00<?, ?it/s]
17:05 bilby INFO : Using sampler Dynesty with kwargs {'bound': 'multi', 'sample': 'rwalk', 'verbose': True, 'periodic': None, 'reflective': None, 'check_point_delta_t': 1800, 'nlive': 500, 'first_update': None, 'walks': 1, 'npdim': None, 'rstate': None, 'queue_size': 1, 'pool': None, 'use_pool': None, 'live_points': None, 'logl_args': None, 'logl_kwargs': None, 'ptform_args': None, 'ptform_kwargs': None, 'enlarge': 1.5, 'bootstrap': None, 'vol_dec': 0.5, 'vol_check': 8.0, 'facc': 0.2, 'slices': 5, 'update_interval': 300, 'print_func': <bound method Dynesty._print_func of <bilby.core.sampler.dynesty.Dynesty object at 0x1732db8e0>>, 'dlogz': 3, 'maxiter': None, 'maxcall': None, 'logl_max': inf, 'add_live': True, 'print_progress': True, 'save_bounds': False, 'n_effective': None, 'maxmcmc': 5000, 'nact': 1}
17:05 bilby INFO : Checkpoint every check_point_delta_t = 600s
17:05 bilby INFO : Using dynesty version 1.0.1
17:05 bilby INFO : Using the bilby-implemented rwalk sample method with ACT estimated walks
17:05 bilby INFO : Reading resume file long/GW150914_resume.pickle
17:05 bilby INFO : Resume file successfully loaded.
Exception while calling loglikelihood function:
params: [ 31.11693379 0.73938086 2.95148322 251.51943348]
args: []
kwargs: {}
exception:
Traceback (most recent call last):
File "/Users/agata/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/dynesty/dynesty.py", line 939, in __call__
return self.func(x, *self.args, **self.kwargs)
File "/Users/agata/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/bilby/core/sampler/dynesty.py", line 50, in _log_likelihood_wrapper
if _priors.evaluate_constraints({
File "/Users/agata/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/bilby/core/sampler/dynesty.py", line 51, in <dictcomp>
key: theta[ii] for ii, key in enumerate(_search_parameter_keys)
IndexError: index 4 is out of bounds for axis 0 with size 4
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Input In [20], in <cell line: 1>()
----> 1 result_long = bilby.run_sampler(
2 likelihood, prior, sampler='dynesty', outdir='long', label="GW150914",
3 conversion_function=bilby.gw.conversion.generate_all_bbh_parameters,
4 sample="rwalk", nact=1, walks=1, nlive=500, dlogz=3)
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/bilby/core/sampler/__init__.py:185, in run_sampler(likelihood, priors, label, outdir, sampler, use_ratio, injection_parameters, conversion_function, plot, default_priors_file, clean, meta_data, save, gzip, result_class, npool, **kwargs)
183 result = sampler._run_test()
184 else:
--> 185 result = sampler.run_sampler()
186 end_time = datetime.datetime.now()
188 # Some samplers calculate the sampling time internally
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/bilby/core/sampler/dynesty.py:359, in Dynesty.run_sampler(self)
352 self.sampler = dynesty.NestedSampler(
353 loglikelihood=_log_likelihood_wrapper,
354 prior_transform=_prior_transform_wrapper,
355 ndim=self.ndim, **self.sampler_init_kwargs
356 )
358 if self.check_point:
--> 359 out = self._run_external_sampler_with_checkpointing()
360 else:
361 out = self._run_external_sampler_without_checkpointing()
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/bilby/core/sampler/dynesty.py:434, in Dynesty._run_external_sampler_with_checkpointing(self)
432 self.start_time = datetime.datetime.now()
433 while True:
--> 434 self._run_nested_wrapper(sampler_kwargs)
435 if self.sampler.ncall == old_ncall:
436 break
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/bilby/core/sampler/dynesty.py:415, in Dynesty._run_nested_wrapper(self, kwargs)
412 logger.debug("Calling run_nested with sampler_function_kwargs {}"
413 .format(kwargs))
414 try:
--> 415 self.sampler.run_nested(**kwargs)
416 except TypeError:
417 kwargs.pop("n_effective")
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/dynesty/sampler.py:921, in Sampler.run_nested(self, maxiter, maxcall, dlogz, logl_max, n_effective, add_live, print_progress, print_func, save_bounds)
919 try:
920 ncall = self.ncall
--> 921 for it, results in enumerate(self.sample(maxiter=maxiter,
922 maxcall=maxcall,
923 dlogz=dlogz,
924 logl_max=logl_max,
925 save_bounds=save_bounds,
926 save_samples=True,
927 n_effective=n_effective,
928 add_live=add_live)):
929 (worst, ustar, vstar, loglstar, logvol, logwt,
930 logz, logzvar, h, nc, worst_it, boundidx, bounditer,
931 eff, delta_logz) = results
932 ncall += nc
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/dynesty/sampler.py:782, in Sampler.sample(self, maxiter, maxcall, dlogz, logl_max, n_effective, add_live, save_bounds, save_samples)
777 logwt = np.logaddexp(loglstar_new, loglstar) + logdvol # ln(wt)
779 # Sample a new live point from within the likelihood constraint
780 # `logl > loglstar` using the bounding distribution and sampling
781 # method from our sampler.
--> 782 u, v, logl, nc = self._new_point(loglstar_new, logvol)
783 ncall += nc
784 self.ncall += nc
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/dynesty/sampler.py:380, in Sampler._new_point(self, loglstar, logvol)
377 ncall, nupdate = 0, 0
378 while True:
379 # Get the next point from the queue
--> 380 u, v, logl, nc, blob = self._get_point_value(loglstar)
381 ncall += nc
383 # Bounding checks.
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/dynesty/sampler.py:364, in Sampler._get_point_value(self, loglstar)
362 # If the queue is empty, refill it.
363 if self.nqueue <= 0:
--> 364 self._fill_queue(loglstar)
366 # Grab the earliest entry.
367 u, v, logl, nc, blob = self.queue.pop(0)
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/dynesty/sampler.py:353, in Sampler._fill_queue(self, loglstar)
348 args = zip(point_queue, loglstars, axes_queue,
349 scales, ptforms, logls, kwargs)
351 if self.use_pool_evolve:
352 # Use the pool to propose ("evolve") a new live point.
--> 353 self.queue = list(self.M(evolve_point, args))
354 else:
355 # Propose ("evolve") a new live point using the default `map`
356 # function.
357 self.queue = list(map(evolve_point, args))
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/dynesty/sampling.py:90, in sample_unif(args)
88 # Evaluate.
89 v = prior_transform(np.array(u))
---> 90 logl = loglikelihood(np.array(v))
91 nc = 1
92 blob = None
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/dynesty/dynesty.py:939, in _function_wrapper.__call__(self, x)
937 def __call__(self, x):
938 try:
--> 939 return self.func(x, *self.args, **self.kwargs)
940 except:
941 import traceback
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/bilby/core/sampler/dynesty.py:50, in _log_likelihood_wrapper(theta)
48 def _log_likelihood_wrapper(theta):
49 """Wrapper to the log likelihood. Needed for multiprocessing."""
---> 50 if _priors.evaluate_constraints({
51 key: theta[ii] for ii, key in enumerate(_search_parameter_keys)
52 }):
53 params = {key: t for key, t in zip(_search_parameter_keys, theta)}
54 _likelihood.parameters.update(params)
File ~/miniconda3/envs/igwn-py39/lib/python3.9/site-packages/bilby/core/sampler/dynesty.py:51, in <dictcomp>(.0)
48 def _log_likelihood_wrapper(theta):
49 """Wrapper to the log likelihood. Needed for multiprocessing."""
50 if _priors.evaluate_constraints({
---> 51 key: theta[ii] for ii, key in enumerate(_search_parameter_keys)
52 }):
53 params = {key: t for key, t in zip(_search_parameter_keys, theta)}
54 _likelihood.parameters.update(params)
IndexError: index 4 is out of bounds for axis 0 with size 4