Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • john-veitch/bilby
  • duncanmmacleod/bilby
  • colm.talbot/bilby
  • lscsoft/bilby
  • matthew-pitkin/bilby
  • salvatore-vitale/tupak
  • charlie.hoy/bilby
  • bfarr/bilby
  • virginia.demilio/bilby
  • vivien/bilby
  • eric-howell/bilby
  • sebastian-khan/bilby
  • rhys.green/bilby
  • moritz.huebner/bilby
  • joseph.mills/bilby
  • scott.coughlin/bilby
  • matthew.carney/bilby
  • hyungwon.lee/bilby
  • monica.rizzo/bilby
  • christopher-berry/bilby
  • lindsay.demarchi/bilby
  • kaushik.rao/bilby
  • charles.kimball/bilby
  • andrew.matas/bilby
  • juan.calderonbustillo/bilby
  • patrick-meyers/bilby
  • hannah.middleton/bilby
  • eve.chase/bilby
  • grant.meadors/bilby
  • khun.phukon/bilby
  • sumeet.kulkarni/bilby
  • daniel.reardon/bilby
  • cjhaster/bilby
  • sylvia.biscoveanu/bilby
  • james-clark/bilby
  • meg.millhouse/bilby
  • joshua.willis/bilby
  • nikhil.sarin/bilby
  • paul.easter/bilby
  • youngmin/bilby
  • daniel-williams/bilby
  • shanika.galaudage/bilby
  • bruce.edelman/bilby
  • avi.vajpeyi/bilby
  • isobel.romero-shaw/bilby
  • andrew.kim/bilby
  • dominika.zieba/bilby
  • jonathan.davies/bilby
  • marc.arene/bilby
  • srishti.tiwari/bilby-tidal-heating-eccentric
  • aditya.vijaykumar/bilby
  • michael.williams/bilby
  • cecilio.garcia-quiros/bilby
  • rory-smith/bilby
  • maite.mateu-lucena/bilby
  • wushichao/bilby
  • kaylee.desoto/bilby
  • brandon.piotrzkowski/bilby
  • rossella.gamba/bilby
  • hunter.gabbard/bilby
  • deep.chatterjee/bilby
  • tathagata.ghosh/bilby
  • arunava.mukherjee/bilby
  • philip.relton/bilby
  • reed.essick/bilby
  • pawan.gupta/bilby
  • francisco.hernandez/bilby
  • rhiannon.udall/bilby
  • leo.tsukada/bilby
  • will-farr/bilby
  • vijay.varma/bilby
  • jeremy.baier/bilby
  • joshua.brandt/bilby
  • ethan.payne/bilby
  • ka-lok.lo/bilby
  • antoni.ramos-buades/bilby
  • oliviastephany.wilk/bilby
  • jack.heinzel/bilby
  • samson.leong/bilby-psi4
  • viviana.caceres/bilby
  • nadia.qutob/bilby
  • michael-coughlin/bilby
  • hemantakumar.phurailatpam/bilby
  • boris.goncharov/bilby
  • sama.al-shammari/bilby
  • siqi.zhong/bilby
  • jocelyn-read/bilby
  • marc.penuliar/bilby
  • stephanie.letourneau/bilby
  • alexandresebastien.goettel/bilby
  • alec.gunny/bilby
  • serguei.ossokine/bilby
  • pratyusava.baral/bilby
  • sophie.hourihane/bilby
  • eunsub/bilby
  • james.hart/bilby
  • pratyusava.baral/bilby-tg
  • zhaozc/bilby
  • pratyusava.baral/bilby_SoG
  • tomasz.baka/bilby
  • nicogerardo.bers/bilby
  • soumen.roy/bilby
  • isaac.mcmahon/healpix-redundancy
  • asamakai.baker/bilby-frequency-dependent-antenna-pattern-functions
  • anna.puecher/bilby
  • pratyusava.baral/bilby-x-g
  • thibeau.wouters/bilby
  • christian.adamcewicz/bilby
  • raffi.enficiaud/bilby
109 results
Show changes
Commits on Source (11)
Showing
with 364 additions and 97 deletions
......@@ -84,7 +84,7 @@ basic-3.11:
script:
- python -m pip install .
- *list-env
- python test/test_samplers_import.py
- pytest test/test_samplers_import.py -v
import-samplers-3.9:
<<: *test-samplers-import
......
......@@ -11,6 +11,7 @@ Andrew Miller
Antoni Ramos-Buades
Apratim Ganguly
Avi Vajpeyi
Ben Patterson
Bruce Edelman
Carl-Johan Haster
Cecilio Garcia-Quiros
......@@ -73,6 +74,7 @@ Roberto Cotesta
Rory Smith
S. H. Oh
Sacha Husa
Sama Al-Shammari
Samson Leong
Scott Coughlin
Serguei Ossokine
......@@ -98,3 +100,4 @@ Andrew Fowlie
Martin White
Peter Tsun-Ho Pang
Alexandre Sebastien Goettel
Ann-Kristin Malz
......@@ -69,7 +69,11 @@ def result_file_name(outdir, label, extension='json', gzip=False):
def _determine_file_name(filename, outdir, label, extension, gzip):
""" Helper method to determine the filename """
if filename is not None:
return filename
if isinstance(filename, os.PathLike):
# convert PathLike object to string
return str(filename)
else:
return filename
else:
if (outdir is None) and (label is None):
raise ValueError("No information given to load file")
......@@ -1795,7 +1799,7 @@ class ResultList(list):
if isinstance(result, Result):
super(ResultList, self).append(result)
elif isinstance(result, str):
elif isinstance(result, (str, os.PathLike)):
super(ResultList, self).append(read_in_result(result))
else:
raise TypeError("Could not append a non-Result type")
......@@ -2057,7 +2061,7 @@ def plot_multiple(results, filename=None, labels=None, colours=None,
hist_kwargs['color'] = c
hist_kwargs["linestyle"] = linestyle
kwargs["hist_kwargs"] = hist_kwargs
fig = result.plot_corner(fig=fig, save=False, color=c, contour_kwargs={"linestyle": linestyle}, **kwargs)
fig = result.plot_corner(fig=fig, save=False, color=c, contour_kwargs={"linestyles": linestyle}, **kwargs)
default_filename += '_{}'.format(result.label)
lines.append(mpllines.Line2D([0], [0], color=c, linestyle=linestyle))
default_labels.append(result.label)
......
......@@ -2,54 +2,69 @@ import datetime
import inspect
import sys
import bilby
from bilby.bilby_mcmc import Bilby_MCMC
from ..prior import DeltaFunction, PriorDict
from ..utils import command_line_args, env_package_list, loaded_modules_dict, logger
from ..utils import (
command_line_args,
env_package_list,
get_entry_points,
loaded_modules_dict,
logger,
)
from . import proposal
from .base_sampler import Sampler, SamplingMarginalisedParameterError
from .cpnest import Cpnest
from .dnest4 import DNest4
from .dynamic_dynesty import DynamicDynesty
from .dynesty import Dynesty
from .emcee import Emcee
from .fake_sampler import FakeSampler
from .kombine import Kombine
from .nessai import Nessai
from .nestle import Nestle
from .polychord import PyPolyChord
from .ptemcee import Ptemcee
from .ptmcmc import PTMCMCSampler
from .pymc import Pymc
from .pymultinest import Pymultinest
from .ultranest import Ultranest
from .zeus import Zeus
IMPLEMENTED_SAMPLERS = {
"bilby_mcmc": Bilby_MCMC,
"cpnest": Cpnest,
"dnest4": DNest4,
"dynamic_dynesty": DynamicDynesty,
"dynesty": Dynesty,
"emcee": Emcee,
"kombine": Kombine,
"nessai": Nessai,
"nestle": Nestle,
"ptemcee": Ptemcee,
"ptmcmcsampler": PTMCMCSampler,
"pymc": Pymc,
"pymultinest": Pymultinest,
"pypolychord": PyPolyChord,
"ultranest": Ultranest,
"zeus": Zeus,
"fake_sampler": FakeSampler,
}
IMPLEMENTED_SAMPLERS = get_entry_points("bilby.samplers")
def get_implemented_samplers():
"""Get a list of the names of the implemented samplers.
This includes natively supported samplers (e.g. dynesty) and any additional
samplers that are supported through the sampler plugins.
Returns
-------
list
The list of implemented samplers.
"""
return list(IMPLEMENTED_SAMPLERS.keys())
def get_sampler_class(sampler):
"""Get the class for a sampler from its name.
This includes natively supported samplers (e.g. dynesty) and any additional
samplers that are supported through the sampler plugins.
Parameters
----------
sampler : str
The name of the sampler.
Returns
-------
Sampler
The sampler class.
Raises
------
ValueError
Raised if the sampler is not implemented.
"""
sampler = sampler.lower()
if sampler in IMPLEMENTED_SAMPLERS:
return IMPLEMENTED_SAMPLERS[sampler].load()
else:
raise ValueError(
f"Sampler {sampler} not yet implemented. "
f"The available samplers are: {get_implemented_samplers()}"
)
if command_line_args.sampler_help:
sampler = command_line_args.sampler_help
if sampler in IMPLEMENTED_SAMPLERS:
sampler_class = IMPLEMENTED_SAMPLERS[sampler]
sampler_class = IMPLEMENTED_SAMPLERS[sampler].load()
print(f'Help for sampler "{sampler}":')
print(sampler_class.__doc__)
else:
......@@ -60,7 +75,7 @@ if command_line_args.sampler_help:
)
else:
print(f"Requested sampler {sampler} not implemented")
print(f"Available samplers = {IMPLEMENTED_SAMPLERS}")
print(f"Available samplers = {get_implemented_samplers()}")
sys.exit()
......@@ -185,24 +200,20 @@ def run_sampler(
if isinstance(sampler, Sampler):
pass
elif isinstance(sampler, str):
if sampler.lower() in IMPLEMENTED_SAMPLERS:
sampler_class = IMPLEMENTED_SAMPLERS[sampler.lower()]
sampler = sampler_class(
likelihood,
priors=priors,
outdir=outdir,
label=label,
injection_parameters=injection_parameters,
meta_data=meta_data,
use_ratio=use_ratio,
plot=plot,
result_class=result_class,
npool=npool,
**kwargs,
)
else:
print(IMPLEMENTED_SAMPLERS)
raise ValueError(f"Sampler {sampler} not yet implemented")
sampler_class = get_sampler_class(sampler)
sampler = sampler_class(
likelihood,
priors=priors,
outdir=outdir,
label=label,
injection_parameters=injection_parameters,
meta_data=meta_data,
use_ratio=use_ratio,
plot=plot,
result_class=result_class,
npool=npool,
**kwargs,
)
elif inspect.isclass(sampler):
sampler = sampler.__init__(
likelihood,
......@@ -219,7 +230,7 @@ def run_sampler(
else:
raise ValueError(
"Provided sampler should be a Sampler object or name of a known "
f"sampler: {', '.join(IMPLEMENTED_SAMPLERS.keys())}."
f"sampler: {get_implemented_samplers()}."
)
if sampler.cached_result:
......
......@@ -248,9 +248,10 @@ class Sampler(object):
self.exit_code = exit_code
self._log_likelihood_eval_time = np.nan
if not soft_init:
self._verify_parameters()
self._time_likelihood()
self._log_likelihood_eval_time = self._time_likelihood()
self._verify_use_ratio()
self.kwargs = kwargs
......@@ -433,6 +434,10 @@ class Sampler(object):
n_evaluations: int
The number of evaluations to estimate the evaluation time from
Returns
=======
log_likelihood_eval_time: float
The time (in s) it took for one likelihood evaluation
"""
t1 = datetime.datetime.now()
......@@ -442,15 +447,16 @@ class Sampler(object):
)[:, 0]
self.log_likelihood(theta)
total_time = (datetime.datetime.now() - t1).total_seconds()
self._log_likelihood_eval_time = total_time / n_evaluations
log_likelihood_eval_time = total_time / n_evaluations
if self._log_likelihood_eval_time == 0:
self._log_likelihood_eval_time = np.nan
if log_likelihood_eval_time == 0:
log_likelihood_eval_time = np.nan
logger.info("Unable to measure single likelihood time")
else:
logger.info(
f"Single likelihood evaluation took {self._log_likelihood_eval_time:.3e} s"
)
return log_likelihood_eval_time
def _verify_use_ratio(self):
"""
......
......@@ -239,8 +239,12 @@ class Dynesty(NestedSampler):
self.nestcheck = nestcheck
if self.n_check_point is None:
self.n_check_point = max(
int(check_point_delta_t / self._log_likelihood_eval_time / 10), 10
self.n_check_point = (
10
if np.isnan(self._log_likelihood_eval_time)
else max(
int(check_point_delta_t / self._log_likelihood_eval_time / 10), 10
)
)
self.check_point_delta_t = check_point_delta_t
logger.info(f"Checkpoint every check_point_delta_t = {check_point_delta_t}s")
......
......@@ -300,6 +300,8 @@ class ACTTrackingRWalk:
)
reject += nfail
blob = {"accept": accept, "reject": reject, "scale": args.scale}
iact = int(np.ceil(self.act))
thin = self.thin * iact
if accept == 0:
logger.debug(
......@@ -314,11 +316,9 @@ class ACTTrackingRWalk:
"Unable to find a new point using walk: try increasing maxmcmc"
)
self._cache.append((current_u, current_v, logl, ncall, blob))
elif self.thin == -1:
elif (self.thin == -1) or (len(u_list) <= thin):
self._cache.append((current_u, current_v, logl, ncall, blob))
else:
iact = int(np.ceil(self.act))
thin = self.thin * iact
u_list = u_list[thin::thin]
v_list = v_list[thin::thin]
logl_list = logl_list[thin::thin]
......
......@@ -6,6 +6,7 @@ from .constants import *
from .conversion import *
from .counter import *
from .docs import *
from .entry_points import *
from .introspection import *
from .io import *
from .log import *
......
import sys
if sys.version_info < (3, 10):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points
def get_entry_points(group):
"""Return a dictionary of entry points for a given group
Parameters
----------
group: str
Entry points you wish to query
"""
return {
custom.name: custom for custom in entry_points(group=group)
}
......@@ -239,7 +239,7 @@ def load_data_from_cache_file(
An initialised interferometer object with strain data set to the
appropriate data in the cache file and a PSD.
"""
import lal
data_set = False
psd_set = False
......
=======================================
Acknowledging/Citing Bilby
=======================================
If you have used Bilby in your scientific work, please acknowledge us in your papers/proposals.
.. code:: bibtex
@article{bilby_paper,
author = "Ashton, Gregory and others",
title = "{BILBY: A user-friendly Bayesian inference library for gravitational-wave astronomy}",
eprint = "1811.02042",
archivePrefix = "arXiv",
primaryClass = "astro-ph.IM",
doi = "10.3847/1538-4365/ab06fc",
journal = "Astrophys. J. Suppl.",
volume = "241",
number = "2",
pages = "27",
year = "2019"
}
Additionally, if you used `bilby_pipe` or `parallel_bilby`, please cite appropriate papers mentioned below"
.. code:: bibtex
@article{bilby_pipe_paper,
author = "Romero-Shaw, I. M. and others",
title = "{Bayesian inference for compact binary coalescences with bilby: validation and application to the first LIGO\textendash{}Virgo gravitational-wave transient catalogue}",
eprint = "2006.00714",
archivePrefix = "arXiv",
primaryClass = "astro-ph.IM",
doi = "10.1093/mnras/staa2850",
journal = "Mon. Not. Roy. Astron. Soc.",
volume = "499",
number = "3",
pages = "3295--3319",
year = "2020"
}
@article{pbilby_paper,
author = "Smith, Rory J. E. and Ashton, Gregory and Vajpeyi, Avi and Talbot, Colm",
title = "{Massively parallel Bayesian inference for transient gravitational-wave astronomy}",
eprint = "1909.11873",
archivePrefix = "arXiv",
primaryClass = "gr-qc",
reportNumber = "LIGO Document P1900255-v1",
doi = "10.1093/mnras/staa2483",
journal = "Mon. Not. Roy. Astron. Soc.",
volume = "498",
number = "3",
pages = "4492--4502",
year = "2020"
}
If you use any of the accelerated likelihoods like `ROQGravitationalWaveTransient`, `MBGravitationalWaveTransient`, `RelativeBinningGravitationalWaveTransient` etc., please cite the following papers in addition to the above.
- `ROQGravitationalWaveTransient`
.. code:: bibtex
@article{roq_paper,
author = {Smith, Rory and Field, Scott E. and Blackburn, Kent and Haster, Carl-Johan and P\"urrer, Michael and Raymond, Vivien and Schmidt, Patricia},
title = "{Fast and accurate inference on gravitational waves from precessing compact binaries}",
eprint = "1604.08253",
archivePrefix = "arXiv",
primaryClass = "gr-qc",
reportNumber = "LIGO-DOCUMENT-NUMBER-P1600096, LIGO-P1600096",
doi = "10.1103/PhysRevD.94.044031",
journal = "Phys. Rev. D",
volume = "94",
number = "4",
pages = "044031",
year = "2016"
}
- `MBGravitationalWaveTransient`
.. code:: bibtex
@article{mb_paper,
author = "Morisaki, Soichiro",
title = "{Accelerating parameter estimation of gravitational waves from compact binary coalescence using adaptive frequency resolutions}",
eprint = "2104.07813",
archivePrefix = "arXiv",
primaryClass = "gr-qc",
doi = "10.1103/PhysRevD.104.044062",
journal = "Phys. Rev. D",
volume = "104",
number = "4",
pages = "044062",
year = "2021"
}
- `RelativeBinningGravitationalWaveTransient`
.. code:: bibtex
@article{relbin_paper,
author = "Cornish, Neil J.",
title = "{Fast Fisher Matrices and Lazy Likelihoods}",
eprint = "1007.4820",
archivePrefix = "arXiv",
primaryClass = "gr-qc",
month = "7",
year = "2010"
}
Please also ensure that you appropriately cite the following:
- The sampler(s) used for your analysis
- Any additional package(s) that you use to generate waveforms e.g. `lalsuite` (https://doi.org/10.7935/GT1W-FZ16)
as well as the original scientific papers for each waveform.
......@@ -38,8 +38,9 @@ new point from the constrained prior. These can be specified using the
results, however, in some cases, a larger value may be required.
2. :code:`sample="acceptance-walk"`: with this method, at each iteration all MCMC chains
are set to the same length. The specific length evolves during the run to yield an
average of :code:`naccept` accepted jumps during each chain. This method is well
are set to the same length. The specific length evolves during the run so that the
number of accepted steps follows a Poisson distribution with mean :code:`naccept`
during each chain. This method is well
suited to parallelised applications, as each MCMC chain will run for the same
amount of time. The value of :code:`naccept` should be tuned based on the
application. For example, one could run a single analysis with
......@@ -62,7 +63,9 @@ There are a number of keyword arguments that influence these sampling methods:
for consistency with other codes. Default is 5000. If this limit is reached,
a warning will be printed during sampling.
#. :code:`proposals`: a list of the desired proposals. The allowed values are
#. :code:`proposals`: a list of the desired proposals.
Each of these proposals can be used with any of the sampling methods described
above. The allowed values are
* :code:`diff`: `ter Braak + (2006) <https://doi.org/10.1007/s11222-006-8769-1>`_
differential evolution. This is the default for :code:`bound="live"` and
......@@ -70,7 +73,9 @@ There are a number of keyword arguments that influence these sampling methods:
* :code:`volumetric`: sample from an ellipsoid centered on the current point.
This is the proposal distribution implemented in :code:`dynesty` and the
default for all other :code:`bound` options.
default for all other :code:`bound` options. This was the default proposal
distribution for :code:`Bilby<2`, however, in many applications it leads to
longer autocorrelation times and struggles to explore multi-modal distributions.
Finally, we implement two custom :code:`dynesty.sampler.Sampler` classes to
facilitate the differential evolution proposal and average acceptance tracking.
......
=========================
Frequency Asked Questions
=========================
==========================
Frequently Asked Questions
==========================
Plotting questions
------------------
......
......@@ -9,6 +9,7 @@ Welcome to bilby's documentation!
:caption: Contents:
installation
citing-bilby
code-overview
examples
basics-of-parameter-estimation
......@@ -17,6 +18,7 @@ Welcome to bilby's documentation!
samplers
dynesty-guide
bilby-mcmc-guide
plugins
bilby-output
compact-binary-coalescence-parameter-estimation
transient-gw-data
......
=======
Plugins
=======
----------------
Defining plugins
----------------
:code:`bilby` allows for additional customizations/extra features via plugins.
This allows users to add new functionality without the need to modify the main
:code:`bilby` codebase, for example to add a new sampler.
To make your plugins discoverable to :code:`bilby`, you need to specify a plugin
group (which :code:`bilby` knows to search for), a name for the plugin, and the
python path to your function/class within your package metadata, see `here
<https://packaging.python.org/en/latest/guides/creating-and-discovering-plugins/#using-package-metadata>`_
for details. For example, if you have a package called :code:`mypackage` and
you wish to add a plugin called :code:`my_awesome_plugin` within the group
:code:`bilby.plugin`, you would specify the following in your `pyproject.toml
<https://packaging.python.org/en/latest/guides/writing-pyproject-toml/>`_
file::
[project.entry-points."bilby.plugin"]
my_awesome_plugin = "mypackage.plugin"
Currently :code:`bilby` allows for the following plugin groups:
- :code:`"bilby.samplers"`: group for adding samplers to :code:`bilby`. See :ref:`Sampler plugins` for more details.
---------------
Sampler plugins
---------------
Sampler plugins can specified via the :code:`"bilby.samplers"` group and these
are automatically added to the 'known' samplers in :code:`bilby`.
This allows users to add support for new samplers without having to modify the
core :code:`bilby` codebase.
Sampler plugins should implement a sampler class that in inherits from one of
the following classes:
- :py:class:`bilby.core.sampler.base_sampler.Sampler`
- :py:class:`bilby.core.sampler.base_sampler.NestedSampler`
- :py:class:`bilby.core.sampler.base_sampler.MCMCSampler`
We provide a `template <https://github.com/bilby-plugins/sampler-template>`_
for creating sampler plugins on GitHub.
.. note::
When implementing a new sampler plugin, please avoid using a generic name for
the plugin (e.g. 'nest', 'mcmc') as this may lead to naming conflicts.
Sampler plugin library
----------------------
This is a list of known sampler plugins. if you don't see your plugin listed
here, we encourage you to open a
`merge request <https://git.ligo.org/lscsoft/bilby/-/merge_requests/new>`_ to add it.
- This could be your sampler
--------------------------------
Information for bilby developers
--------------------------------
Using plugins within bilby
--------------------------
Within :code:`bilby`, plugins are discovered with the
:py:func:`bilby.core.utils.get_entry_points` function,
and can be used throughout the :code:`bilby` infrastructure.
Adding a new plugin group
-------------------------
If you want to add support for a new plugin group, please
`open an issue <https://git.ligo.org/lscsoft/bilby/-/issues/new>`_
to discuss the details with other developers.
......@@ -12,6 +12,7 @@ import bilby
import matplotlib.pyplot as plt
import numpy as np
import pymc as pm
from bilby.core.sampler.pymc import Pymc
# A few simple setup steps
label = "linear_regression_pymc_custom_likelihood"
......@@ -76,13 +77,11 @@ class GaussianLikelihoodPyMC(bilby.core.likelihood.GaussianLikelihood):
----------
sampler: :class:`bilby.core.sampler.Pymc`
A Sampler object must be passed containing the prior distributions
and PyMC3 :class:`~pymc3.Model` to use as a context manager.
and PyMC :class:`~pymc.Model` to use as a context manager.
If this is not passed, the super class is called and the regular
likelihood is evaluated.
"""
from bilby.core.sampler import Pymc
if not isinstance(sampler, Pymc):
return super(GaussianLikelihoodPyMC, self).log_likelihood()
......@@ -116,15 +115,12 @@ class PyMCUniformPrior(bilby.core.prior.Uniform):
def ln_prob(self, sampler=None):
"""
Change ln_prob method to take in a Sampler and return a PyMC3
Change ln_prob method to take in a Sampler and return a PyMC
distribution.
If the passed argument is not a `Pymc3` sampler, assume that it is a
If the passed argument is not a `Pymc` sampler, assume that it is a
float or array to be passed to the superclass.
"""
from bilby.core.sampler import Pymc
if not isinstance(sampler, Pymc):
return super(PyMCUniformPrior, self).ln_prob(sampler)
......
......@@ -10,3 +10,4 @@ dill
tqdm
h5py
attrs
importlib-metadata>=3.6; python_version < '3.10'
......@@ -82,7 +82,26 @@ setup(
"console_scripts": [
"bilby_plot=cli_bilby.plot_multiple_posteriors:main",
"bilby_result=cli_bilby.bilby_result:main",
]
],
"bilby.samplers": [
"bilby_mcmc=bilby.bilby_mcmc.sampler:Bilby_MCMC",
"cpnest=bilby.core.sampler.cpnest:Cpnest",
"dnest4=bilby.core.sampler.dnest4:DNest4",
"dynesty=bilby.core.sampler.dynesty:Dynesty",
"dynamic_dynesty=bilby.core.sampler.dynamic_dynesty:DynamicDynesty",
"emcee=bilby.core.sampler.emcee:Emcee",
"kombine=bilby.core.sampler.kombine:Kombine",
"nessai=bilby.core.sampler.nessai:Nessai",
"nestle=bilby.core.sampler.nestle:Nestle",
"ptemcee=bilby.core.sampler.ptemcee:Ptemcee",
"ptmcmcsampler=bilby.core.sampler.ptmcmc:PTMCMCSampler",
"pymc=bilby.core.sampler.pymc:Pymc",
"pymultinest=bilby.core.sampler.pymultinest:Pymultinest",
"pypolychord=bilby.core.sampler.polychord:PyPolyChord",
"ultranest=bilby.core.sampler.ultranest:Ultranest",
"zeus=bilby.core.sampler.zeus:Zeus",
"fake_sampler=bilby.core.sampler.fake_sampler:FakeSampler",
],
},
classifiers=[
"Programming Language :: Python :: 3.9",
......
......@@ -10,9 +10,11 @@ import numpy as np
import bilby
from bilby.core import prior
loaded_samplers = {k: v.load() for k, v in bilby.core.sampler.IMPLEMENTED_SAMPLERS.items()}
class TestSampler(unittest.TestCase):
def setUp(self):
def setUp(self, soft_init=False):
likelihood = bilby.core.likelihood.Likelihood()
likelihood.parameters = dict(a=1, b=2, c=3)
delta_prior = prior.DeltaFunction(peak=0)
......@@ -36,11 +38,16 @@ class TestSampler(unittest.TestCase):
outdir=test_directory,
use_ratio=False,
skip_import_verification=True,
soft_init=soft_init
)
def tearDown(self):
del self.sampler
def test_softinit(self):
self.setUp(soft_init=True)
self.assertTrue(hasattr(self.sampler, "_log_likelihood_eval_time"))
def test_search_parameter_keys(self):
expected_search_parameter_keys = ["c"]
self.assertListEqual(
......@@ -165,9 +172,7 @@ class GenericSamplerTest(unittest.TestCase):
@parameterized.expand(samplers)
def test_pool_creates_properly_no_pool(self, sampler_name):
sampler = bilby.core.sampler.IMPLEMENTED_SAMPLERS[sampler_name](
self.likelihood, self.priors
)
sampler = loaded_samplers[sampler_name](self.likelihood, self.priors)
sampler._setup_pool()
if sampler_name == "kombine":
from kombine import SerialPool
......@@ -179,7 +184,7 @@ class GenericSamplerTest(unittest.TestCase):
@parameterized.expand(samplers)
def test_pool_creates_properly_pool(self, sampler):
sampler = bilby.core.sampler.IMPLEMENTED_SAMPLERS[sampler](
sampler = loaded_samplers[sampler](
self.likelihood, self.priors, npool=2
)
sampler._setup_pool()
......
......@@ -2,6 +2,7 @@ import unittest
from unittest.mock import MagicMock
import bilby
import bilby.core.sampler.cpnest
class TestCPNest(unittest.TestCase):
......@@ -10,7 +11,7 @@ class TestCPNest(unittest.TestCase):
self.priors = bilby.core.prior.PriorDict(
dict(a=bilby.core.prior.Uniform(0, 1), b=bilby.core.prior.Uniform(0, 1))
)
self.sampler = bilby.core.sampler.Cpnest(
self.sampler = bilby.core.sampler.cpnest.Cpnest(
self.likelihood,
self.priors,
outdir="outdir",
......