Skip to content

amax parameter of iid_spin model missing for conversion_function on bilby sampler initialization #85

@mdmould

Description

@mdmould

Running bilby.run_sampler with the gwpopulation.hyperpe.HyperparameterLikelihood fails with the iid_spin model when sampling in parameters that require the gwpopulation.conversions.convert_to_beta_parameters conversion function.

This may be an issue with how bilby interacts with fixed parameters rather than an issue with gwpopulation itself, but I'll post the issue here with a reproducible example below.

Versions are bilby==2.2.3 and gwpopulation==1.0.0rc2.dev1+g37f1b4c (pip install git+https://github.com/ColmTalbot/gwpopulation, but the issue also occurs with gwpopulation==0.10.0).

import numpy as np
import pandas
import bilby
from gwpopulation.hyperpe import HyperparameterLikelihood
from gwpopulation.models.spin import iid_spin
from gwpopulation.conversions import convert_to_beta_parameters

posterior = pandas.DataFrame()
for key in 'a_1', 'a_2', 'cos_tilt_1', 'cos_tilt_2':
    posterior[key] = np.ones(1)

priors = bilby.prior.PriorDict(conversion_function = lambda args: convert_to_beta_parameters(args)[0])
priors['mu_chi'] = bilby.prior.Uniform(0, 1)
priors['sigma_chi'] = bilby.prior.Uniform(0, 1)
priors['xi_spin'] = bilby.prior.Uniform(0, 1)
priors['sigma_spin'] = bilby.prior.Uniform(0, 1)
priors['amax'] = 1

likelihood = HyperparameterLikelihood(
    posteriors = [posterior],
    hyper_prior = iid_spin,
    conversion_function = convert_to_beta_parameters,
    cupy = False,
)

result = bilby.run_sampler(likelihood, priors = priors)

This results in a key error for amax.

Following the traceback, the error is caused when the sampler is initialized and the _verify_parameters method runs, which tries to evaluate the likelihood but on only the set of parameters stored in search_parameter_keys. Looking at _initialise_parameters, it seems this does not contain parameters with delta function priors, and so the parameters for this initial likelihood call do not include amax. The error is ultimately triggered when these parameters are passed to the sampling routines in PriorDict, which attempt to call PriorDict.conversion_function, but the amax parameter for convert_to_beta_parameters is missing.

You can verify the issue is with the delta function by changing to, e.g., priors['amax'] = bilby.prior.Uniform(0, 1), which works fine.

A workaround is provided by gwpopulation_pipe.utils.prior_conversion when given as the conversion_function for the PriorDict above, as it manually populates amax* parameters to prevent this error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions