gwastro / PyCBC-Tutorials

Learn how to use PyCBC to analyze gravitational-wave data and do parameter inference.
116 stars 49 forks source link

Add custom models tutorial #26

Closed cdcapano closed 2 years ago

cdcapano commented 2 years ago

Adds a tutorial explaining how to add custom models for inference

ahnitz commented 2 years ago

Very cool!

It might be good to add link from the pycbc inference docs and on this page as well when you get the chance.

https://pycbc.org/pycbc/latest/html/extend.html

ahnitz commented 2 years ago

@cdcapano Woops, I think there is a problem. I just tried the google colab tutorial and it runs into an error.

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[<ipython-input-24-0f212eef32fc>](https://localhost:8080/#) in <module>()
      2 from pycbc.inference.sampler import load_from_config as load_sampler_from_config
      3 
----> 4 sampler = load_sampler_from_config(cp, model, output_file='poisson.hdf')
      5 sampler.run()
      6 sampler.finalize()

[/usr/local/lib/python3.7/dist-packages/pycbc/inference/sampler/__init__.py](https://localhost:8080/#) in load_from_config(cp, model, **kwargs)
     83     """
     84     name = cp.get('sampler', 'name')
---> 85     return samplers[name].from_config(cp, model, **kwargs)

KeyError: 'epsie'

Did this run for you on google colab? Did you have a different epsie version perhaps?

ahnitz commented 2 years ago

@cdcapano The issue is that you require emcee to be installed for epsie to run and in particular you require emcee < 3.0. The latter is going to be an issue longer term. For the tutorial, you'll need to add emcee to the install list, but can we remove this link between epsie and emcee?

ModuleNotFoundError                       Traceback (most recent call last)
[<ipython-input-17-94b8b7f5336e>](https://localhost:8080/#) in <module>()
----> 1 from pycbc.inference.sampler.epsie import *

[/usr/local/lib/python3.7/dist-packages/pycbc/inference/sampler/epsie.py](https://localhost:8080/#) in <module>()
     24 
     25 # we'll use emcee_pt's default beta ladder for temperature levels
---> 26 from emcee.ptsampler import default_beta_ladder
     27 
     28 from pycbc.pool import choose_pool

ModuleNotFoundError: No module named 'emcee'
cdcapano commented 2 years ago

@ahnitz Whoops, sorry. I had only tested on my laptop, not on Google colab. I've added the install; will fill out another PR. Yeah, that connection needs to be broken. It was just to get the function that constructs the default temperature ladder code that's in ptemcee. I wasn't sure if just copying would break the ptemcee license, so I added an import instead, but given the dead state of ptemcee, best to move away from this.