bilby-dev / bilby

A unified framework for stochastic sampling packages and gravitational-wave inference in Python.
https://bilby-dev.github.io/bilby/
MIT License
68 stars 75 forks source link

Issue when sampling using BasicGravitationalWaveTransient #454

Closed bilby-bot closed 1 month ago

bilby-bot commented 5 years ago

In GitLab by @git.ligo:jonathan.davies on Jul 23, 2019, 16:10

I've been trying to modify the bilby code so that uncertainty in the form of the PSD can be folded into the analysis i.e. multiple PSD files are loaded in and the indices of these are implemented as parameters to be fitted. The error shown below got thrown up in run_sampler, as I am using BasicGravitationalWaveTransient rather than GravitationalWaveTransient in bilby/bilby/gw/likelihood.py. It gets called like this:

result = bilby.run_sampler( likelihood, prior, outdir=outdir, label=label, sampler=sampler, npoints=npoints, use_ratio=False, injection_parameters=None, conversion_function=bilby.gw.conversion.generate_all_bbh_parameters, resume=False, n_check_point=5000)

It seems that the issue is that the generate_all_bbh_parameters function is expecting the likelihood to have the various marginalization flags as attributes, and it fails for the Basic version which doesn't have those options.

Traceback (most recent call last): File "GW150914_advanced.py", line 130, in conversion_function=bilby.gw.conversion.generate_all_bbh_parameters, resume=True, n_check_point=5000) File "/home/jonathan.davies/bilby/bilby/core/sampler/init.py", line 203, in run_sampler conversion_function=conversion_function) File "/home/jonathan.davies/bilby/bilby/core/result.py", line 1072, in samples_to_posterior data_frame = conversion_function(data_frame, likelihood, priors) File "/home/jonathan.davies/bilby/bilby/gw/conversion.py", line 703, in generate_all_bbh_parameters likelihood=likelihood, priors=priors) File "/home/jonathan.davies/bilby/bilby/gw/conversion.py", line 667, in _generate_all_cbc_parameters samples=output_sample, likelihood=likelihood) File "/home/jonathan.davies/bilby/bilby/gw/conversion.py", line 1015, in generate_posterior_samples_from_marginalized_likelihood if not any([likelihood.phase_marginalization, AttributeError: 'BasicGravitationalWaveTransient' object has no attribute 'phase_marginalization'

bilby-bot commented 5 years ago

In GitLab by @git.ligo:colm.talbot on Jul 23, 2019, 23:05

Hi @git.ligo:jonathan.davies thanks for flagging this. I guess we can make this a little more robust by replacing likelihood.phase_marginalization with getattr(likelihood, "phase_marginalization", False) in https://git.ligo.org/lscsoft/bilby/blob/master/bilby/gw/conversion.py#L1018 and similar. We may also want to put the whole function call in a try/except statement in https://git.ligo.org/lscsoft/bilby/blob/master/bilby/gw/conversion.py#L666

Also, you can wrap code fragments as follows to get nicer formatted output, there's a nice intro to markdown at https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet.

```python
Traceback (most recent call last): File "GW150914_advanced.py", line 130, in conversion_function=bilby.gw.conversion.generate_all_bbh_parameters, resume=True, n_check_point=5000) File "/home/jonathan.davies/bilby/bilby/core/sampler/**init**.py", line 203, in run_sampler conversion_function=conversion_function) File "/home/jonathan.davies/bilby/bilby/core/result.py", line 1072, in samples_to_posterior data_frame = conversion_function(data_frame, likelihood, priors) File "/home/jonathan.davies/bilby/bilby/gw/conversion.py", line 703, in generate_all_bbh_parameters likelihood=likelihood, priors=priors) File "/home/jonathan.davies/bilby/bilby/gw/conversion.py", line 667, in _generate_all_cbc_parameters samples=output_sample, likelihood=likelihood) File "/home/jonathan.davies/bilby/bilby/gw/conversion.py", line 1015, in generate_posterior_samples_from_marginalized_likelihood if not any(\[likelihood.phase_marginalization, AttributeError: 'BasicGravitationalWaveTransient' object has no attribute 'phase_marginalization'

```python
Traceback (most recent call last):
File "GW150914_advanced.py", line 130, in 
conversion_function=bilby.gw.conversion.generate_all_bbh_parameters, resume=True, n_check_point=5000)
File "/home/jonathan.davies/bilby/bilby/core/sampler/init.py", line 203, in run_sampler
conversion_function=conversion_function)
File "/home/jonathan.davies/bilby/bilby/core/result.py", line 1072, in samples_to_posterior
data_frame = conversion_function(data_frame, likelihood, priors)
File "/home/jonathan.davies/bilby/bilby/gw/conversion.py", line 703, in generate_all_bbh_parameters
likelihood=likelihood, priors=priors)
File "/home/jonathan.davies/bilby/bilby/gw/conversion.py", line 667, in _generate_all_cbc_parameters
samples=output_sample, likelihood=likelihood)
File "/home/jonathan.davies/bilby/bilby/gw/conversion.py", line 1015, in generate_posterior_samples_from_marginalized_likelihood
if not any([likelihood.phase_marginalization,
AttributeError: 'BasicGravitationalWaveTransient' object has no attribute 'phase_marginalization'
bilby-bot commented 5 years ago

In GitLab by @git.ligo:gregory.ashton on Jul 24, 2019, 05:52

@git.ligo:colm.talbot this seems like a straight forward MR, @git.ligo:jonathan.davies would that solve your immediate issue? If you have time, would you be able to generate a MR implementing those changes? Let us know if not and we can try to assign this to someone.

bilby-bot commented 5 years ago

In GitLab by @git.ligo:sylvia.biscoveanu on Jul 24, 2019, 15:27

Assigning to myself because I'm helping Jonathan with this and have a few other minor merge requests to submit from other small issues we've run into.

bilby-bot commented 5 years ago

In GitLab by @git.ligo:colm.talbot on Aug 6, 2019, 01:37

Ping @git.ligo:jonathan.davies @git.ligo:sylvia.biscoveanu

bilby-bot commented 5 years ago

In GitLab by @git.ligo:gregory.ashton on Aug 20, 2019, 01:56

closed via merge request !572

bilby-bot commented 5 years ago

In GitLab by @git.ligo:gregory.ashton on Aug 20, 2019, 01:56

mentioned in commit b96e42e4ebe683e9405c3c38dc2563d702fd7a3c

bilby-bot commented 1 month ago

In GitLab by @git.ligo:michael.williams on Oct 3, 2024, 17:55

unassigned @git.ligo:sylvia.biscoveanu