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
......@@ -73,6 +73,18 @@ MCMC samplers
- zeus :code:`bilby.core.sampler.zeus.Zeus`
--------------------------
Listing available samplers
--------------------------
A list of available samplers can be produced using
:py:func:`bilby.core.sampler.get_implemented_samplers`.
This will list native bilby samplers and any samplers available via a plugin.
If a plugin provides a sampler that is also implemented in bilby, the bilby
implementation will be labeled with the prfix `bilby.` to distinguish it from
the plugin version. See `sampler plugins`_ for more details.
-------------------
Installing samplers
-------------------
......
......@@ -18,7 +18,7 @@ for letter in ["B", "I", "L", "Y"]:
img = 1 - io.imread("{}.png".format(letter), as_gray=True)[::-1, :]
x = np.arange(img.shape[0])
y = np.arange(img.shape[1])
interp = si.interpolate.interp2d(x, y, img.T)
interp = si.RectBivariateSpline(x, y, img, kx=1, ky=1)
likelihood = Likelihood(interp)
......
......@@ -4,7 +4,8 @@ emcee
corner
numpy
matplotlib
scipy>=1.5
# see https://github.com/healpy/healpy/pull/953
scipy>=1.5,<1.14
pandas
dill
tqdm
......
......@@ -84,23 +84,23 @@ setup(
"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",
"bilby.bilby_mcmc=bilby.bilby_mcmc.sampler:Bilby_MCMC",
"bilby.cpnest=bilby.core.sampler.cpnest:Cpnest",
"bilby.dnest4=bilby.core.sampler.dnest4:DNest4",
"bilby.dynesty=bilby.core.sampler.dynesty:Dynesty",
"bilby.dynamic_dynesty=bilby.core.sampler.dynamic_dynesty:DynamicDynesty",
"bilby.emcee=bilby.core.sampler.emcee:Emcee",
"bilby.kombine=bilby.core.sampler.kombine:Kombine",
"bilby.nessai=bilby.core.sampler.nessai:Nessai",
"bilby.nestle=bilby.core.sampler.nestle:Nestle",
"bilby.ptemcee=bilby.core.sampler.ptemcee:Ptemcee",
"bilby.ptmcmcsampler=bilby.core.sampler.ptmcmc:PTMCMCSampler",
"bilby.pymc=bilby.core.sampler.pymc:Pymc",
"bilby.pymultinest=bilby.core.sampler.pymultinest:Pymultinest",
"bilby.pypolychord=bilby.core.sampler.polychord:PyPolyChord",
"bilby.ultranest=bilby.core.sampler.ultranest:Ultranest",
"bilby.zeus=bilby.core.sampler.zeus:Zeus",
"bilby.fake_sampler=bilby.core.sampler.fake_sampler:FakeSampler",
],
},
classifiers=[
......
......@@ -85,5 +85,16 @@ class TestBilbyMCMCSampler(unittest.TestCase):
self.assertTrue(isinstance(sampler.samples, pd.DataFrame))
def test_get_expected_outputs():
label = "par0"
outdir = os.path.join("some", "bilby_pipe", "dir")
filenames, directories = Bilby_MCMC.get_expected_outputs(
outdir=outdir, label=label
)
assert len(filenames) == 1
assert len(directories) == 0
assert os.path.join(outdir, f"{label}_resume.pickle") in filenames
if __name__ == "__main__":
unittest.main()
......@@ -3,7 +3,7 @@
import re
import subprocess
special_cases = ["plasky", "thomas", "mj-will", "richard", "douglas"]
special_cases = ["plasky", "thomas", "mj-will", "richard", "douglas", "nixnyxnyx"]
AUTHORS_list = []
with open("AUTHORS.md", "r") as f:
AUTHORS_list = " ".join([line for line in f]).lower()
......
......@@ -148,6 +148,30 @@ class TestSampler(unittest.TestCase):
)
def test_get_expected_outputs():
outdir = os.path.join("some", "bilby_pipe", "dir")
label = "par0"
filenames, directories = bilby.core.sampler.Sampler.get_expected_outputs(
outdir=outdir, label=label
)
assert len(filenames) == 0
assert len(directories) == 1
assert directories[0] == os.path.join(outdir, f"sampler_{label}", "")
def test_get_expected_outputs_abbreviation():
outdir = os.path.join("some", "bilby_pipe", "dir")
label = "par0"
bilby.core.sampler.Sampler.abbreviation = "abbr"
filenames, directories = bilby.core.sampler.Sampler.get_expected_outputs(
outdir=outdir, label=label
)
assert len(filenames) == 0
assert len(directories) == 1
assert directories[0] == os.path.join(outdir, f"abbr_{label}", "")
bilby.core.sampler.Sampler.abbreviation = None
samplers = [
"bilby_mcmc",
"dynamic_dynesty",
......
......@@ -9,6 +9,7 @@ import bilby.core.sampler.dynesty
from bilby.core.sampler import dynesty_utils
from scipy.stats import gamma, ks_1samp, uniform, powerlaw
import shutil
import os
@define
......@@ -101,6 +102,18 @@ class TestDynesty(unittest.TestCase):
self.sampler._run_test()
def test_get_expected_outputs():
label = "par0"
outdir = os.path.join("some", "bilby_pipe", "dir")
filenames, directories = bilby.core.sampler.dynesty.Dynesty.get_expected_outputs(
outdir=outdir, label=label
)
assert len(filenames) == 2
assert len(directories) == 0
assert os.path.join(outdir, f"{label}_resume.pickle") in filenames
assert os.path.join(outdir, f"{label}_dynesty.pickle") in filenames
class ProposalsTest(unittest.TestCase):
def test_boundaries(self):
......@@ -203,7 +216,7 @@ class TestCustomSampler(unittest.TestCase):
self.sampler = cls(
loglikelihood=lambda x: 1,
prior_transform=lambda x: x,
npdim=4,
ndim=4,
live_points=(np.zeros((1000, 4)), np.zeros((1000, 4)), np.zeros(1000)),
update_interval=None,
first_update=dict(),
......
from bilby.core.sampler import IMPLEMENTED_SAMPLERS, ImplementedSamplers
import pytest
def test_singleton():
assert ImplementedSamplers() is IMPLEMENTED_SAMPLERS
def test_keys():
# The fake sampler should never have a plugin, so this should always work
assert "fake_sampler" in IMPLEMENTED_SAMPLERS.keys()
assert "bilby.fake_sampler" not in IMPLEMENTED_SAMPLERS.keys()
def test_allowed_keys():
# The fake sampler should never have a plugin, so this should always work
assert "fake_sampler" in IMPLEMENTED_SAMPLERS.valid_keys()
assert "bilby.fake_sampler" in IMPLEMENTED_SAMPLERS.valid_keys()
def test_values():
# Values and keys should have the same lengths
assert len(list(IMPLEMENTED_SAMPLERS.values())) \
== len(list(IMPLEMENTED_SAMPLERS.keys()))
assert len(list(IMPLEMENTED_SAMPLERS.values())) \
== len(list(IMPLEMENTED_SAMPLERS._samplers.values()))
def test_items():
keys, values = list(zip(*IMPLEMENTED_SAMPLERS.items()))
assert len(keys) == len(values)
# Keys and values should be the same as the individual methods
assert list(keys) == list(IMPLEMENTED_SAMPLERS.keys())
assert list(values) == list(IMPLEMENTED_SAMPLERS.values())
@pytest.mark.parametrize("sampler", ["fake_sampler", "bilby.fake_sampler"])
def test_in_operator(sampler):
assert sampler in IMPLEMENTED_SAMPLERS
......@@ -3,6 +3,7 @@ from unittest.mock import MagicMock, patch, mock_open
import bilby
import bilby.core.sampler.nessai
import os
class TestNessai(unittest.TestCase):
......@@ -84,5 +85,19 @@ class TestNessai(unittest.TestCase):
self.assertDictEqual(expected, self.sampler.kwargs)
def test_get_expected_outputs():
label = "par0"
outdir = os.path.join("some", "bilby_pipe", "dir")
filenames, directories = bilby.core.sampler.nessai.Nessai.get_expected_outputs(
outdir=outdir, label=label
)
assert len(filenames) == 0
assert len(directories) == 3
base_dir = os.path.join(outdir, f"{label}_nessai", "")
assert base_dir in directories
assert os.path.join(base_dir, "proposal", "") in directories
assert os.path.join(base_dir, "diagnostics", "") in directories
if __name__ == "__main__":
unittest.main()
......@@ -5,6 +5,7 @@ from bilby.core.prior import Uniform, PriorDict
from bilby.core.sampler.ptemcee import Ptemcee
from bilby.core.sampler.base_sampler import MCMCSampler
import numpy as np
import os
class TestPTEmcee(unittest.TestCase):
......@@ -89,5 +90,16 @@ class TestPTEmcee(unittest.TestCase):
self.assertEqual(old, new)
def test_get_expected_outputs():
label = "par0"
outdir = os.path.join("some", "bilby_pipe", "dir")
filenames, directories = Ptemcee.get_expected_outputs(
outdir=outdir, label=label
)
assert len(filenames) == 1
assert len(directories) == 0
assert os.path.join(outdir, f"{label}_checkpoint_resume.pickle") in filenames
if __name__ == "__main__":
unittest.main()
......@@ -320,7 +320,7 @@ class TestUnsortedInterp2d(unittest.TestCase):
self.xx = np.linspace(0, 1, 10)
self.yy = np.linspace(0, 1, 10)
self.zz = np.random.random((10, 10))
self.interpolant = bilby.core.utils.UnsortedInterp2d(self.xx, self.yy, self.zz)
self.interpolant = bilby.core.utils.BoundedRectBivariateSpline(self.xx, self.yy, self.zz)
def tearDown(self):
pass
......
......@@ -475,7 +475,7 @@ class TestGenerateAllParameters(unittest.TestCase):
def test_generate_bbh_parameters_with_likelihood(self):
priors = bilby.gw.prior.BBHPriorDict()
priors["geocent_time"] = bilby.core.prior.Uniform(0.4, 0.6)
ifos = bilby.gw.detector.InterferometerList(["H1"])
ifos = bilby.gw.detector.InterferometerList(["H1", "L1"])
ifos.set_strain_data_from_power_spectral_densities(duration=1, sampling_frequency=256)
wfg = bilby.gw.waveform_generator.WaveformGenerator(
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole
......@@ -501,6 +501,8 @@ class TestGenerateAllParameters(unittest.TestCase):
"phase",
"H1_optimal_snr",
"H1_matched_filter_snr",
"L1_optimal_snr",
"L1_matched_filter_snr",
"ra",
"dec",
]
......
......@@ -560,21 +560,92 @@ class TestInterferometerAntennaPatternAgainstLAL(unittest.TestCase):
class TestInterferometerWhitenedStrain(unittest.TestCase):
def setUp(self):
self.duration = 64
self.sampling_frequency = 4096
self.ifo = bilby.gw.detector.get_empty_interferometer('H1')
self.ifo.set_strain_data_from_power_spectral_density(
sampling_frequency=4096, duration=64)
sampling_frequency=self.sampling_frequency, duration=self.duration)
self.waveform_generator = bilby.gw.waveform_generator.WaveformGenerator(
duration=self.duration,
sampling_frequency=self.sampling_frequency,
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
waveform_arguments={
"waveform_approximant": "IMRPhenomXP"
})
self.parameters = {
'mass_1': 10,
'mass_2': 10,
'a_1': 0,
'a_2': 0,
'tilt_1': 0,
'tilt_2': 0,
'phi_12': 0,
'phi_jl': 0,
'theta_jn': 0,
'luminosity_distance': 40,
'phase': 0,
'ra': 0,
'dec': 0,
'geocent_time': 62,
'psi': 0
}
def tearDown(self):
del self.ifo
del self.waveform_generator
del self.parameters
del self.duration
del self.sampling_frequency
def test_whitened_strain(self):
mask = self.ifo.frequency_mask
white = self.ifo.whitened_frequency_domain_strain[mask]
std_real = np.std(white.real)
std_imag = np.std(white.imag)
def _check_frequency_series_whiteness(self, frequency_series):
std_real = np.std(frequency_series.real)
std_imag = np.std(frequency_series.imag)
self.assertAlmostEqual(std_real, 1, places=2)
self.assertAlmostEqual(std_imag, 1, places=2)
def _check_time_series_whiteness(self, time_series):
std = np.std(time_series)
self.assertAlmostEqual(std, 1, places=2)
if __name__ == "__main__":
unittest.main()
def test_frequency_domain_whitened_strain(self):
mask = self.ifo.frequency_mask
white = self.ifo.whitened_frequency_domain_strain[mask]
self._check_frequency_series_whiteness(white)
def test_time_domain_whitened_strain(self):
whitened_td = self.ifo.whitened_time_domain_strain
self._check_time_series_whiteness(whitened_td)
def test_frequency_domain_noise_and_signal_whitening(self):
# Inject some (loud) signal
self.ifo.inject_signal(waveform_generator=self.waveform_generator, parameters=self.parameters)
# Make the template separately
waveform_polarizations = self.waveform_generator.frequency_domain_strain(parameters=self.parameters)
signal_ifo = self.ifo.get_detector_response(
waveform_polarizations=waveform_polarizations,
parameters=self.parameters
)
# Whiten the template
whitened_signal_ifo = self.ifo.whiten_frequency_series(signal_ifo)
mask = self.ifo.frequency_mask
white = self.ifo.whitened_frequency_domain_strain[mask] - whitened_signal_ifo[mask]
self._check_frequency_series_whiteness(white)
def test_time_domain_noise_and_signal_whitening(self):
# Inject some (loud) signal
self.ifo.inject_signal(waveform_generator=self.waveform_generator, parameters=self.parameters)
# Make the template separately
waveform_polarizations = self.waveform_generator.frequency_domain_strain(parameters=self.parameters)
signal_ifo = self.ifo.get_detector_response(
waveform_polarizations=waveform_polarizations,
parameters=self.parameters
)
# Whiten the template in FD
whitened_signal_ifo_fd = self.ifo.whiten_frequency_series(signal_ifo)
# Get whitened template in TD
whitened_signal_ifo_td = self.ifo.get_whitened_time_series_from_whitened_frequency_series(
whitened_signal_ifo_fd
)
whitened_td = self.ifo.whitened_time_domain_strain - whitened_signal_ifo_td
self._check_time_series_whiteness(whitened_td)
......@@ -656,6 +656,80 @@ class TestROQLikelihoodHDF5(unittest.TestCase):
self.injection_parameters["geocent_time"] + 0.1
)
@parameterized.expand(
[(_path_to_basis, 20., 2048., 16),
(_path_to_basis, 10., 1024., 16),
(_path_to_basis, 20., 1024., 32),
(_path_to_basis_mb, 20., 2048., 16)]
)
def test_fails_with_frequency_duration_mismatch(
self, basis, minimum_frequency, maximum_frequency, duration
):
"""Test if likelihood fails as expected, when data frequency range is
not within the basis range or data duration does not match the basis
duration. The basis frequency range and duration are 20--1024Hz and
16s"""
self.priors["chirp_mass"].minimum = 8
self.priors["chirp_mass"].maximum = 9
interferometers = bilby.gw.detector.InterferometerList(["H1"])
interferometers.set_strain_data_from_power_spectral_densities(
sampling_frequency=2 * maximum_frequency,
duration=duration,
start_time=self.injection_parameters["geocent_time"] - duration + 1
)
for ifo in interferometers:
ifo.minimum_frequency = minimum_frequency
ifo.maximum_frequency = maximum_frequency
search_waveform_generator = bilby.gw.waveform_generator.WaveformGenerator(
duration=duration,
sampling_frequency=2 * maximum_frequency,
frequency_domain_source_model=bilby.gw.source.binary_black_hole_roq,
waveform_arguments=dict(
reference_frequency=self.reference_frequency,
waveform_approximant=self.waveform_approximant
)
)
with self.assertRaises(BilbyROQParamsRangeError):
bilby.gw.likelihood.ROQGravitationalWaveTransient(
interferometers=interferometers,
priors=self.priors,
waveform_generator=search_waveform_generator,
linear_matrix=basis,
quadratic_matrix=basis,
)
@parameterized.expand([(_path_to_basis, 7, 13), (_path_to_basis, 9, 15), (_path_to_basis, 16, 17)])
def test_fails_with_prior_mismatch(self, basis, chirp_mass_min, chirp_mass_max):
"""Test if likelihood fails as expected, when prior range is not within
the basis bounds. Basis chirp-mass range is 8Msun--14Msun."""
self.priors["chirp_mass"].minimum = chirp_mass_min
self.priors["chirp_mass"].maximum = chirp_mass_max
interferometers = bilby.gw.detector.InterferometerList(["H1"])
interferometers.set_strain_data_from_power_spectral_densities(
sampling_frequency=self.sampling_frequency,
duration=self.duration,
start_time=self.injection_parameters["geocent_time"] - self.duration + 1
)
for ifo in interferometers:
ifo.minimum_frequency = self.minimum_frequency
search_waveform_generator = bilby.gw.waveform_generator.WaveformGenerator(
duration=self.duration,
sampling_frequency=self.sampling_frequency,
frequency_domain_source_model=bilby.gw.source.binary_black_hole_roq,
waveform_arguments=dict(
reference_frequency=self.reference_frequency,
waveform_approximant=self.waveform_approximant
)
)
with self.assertRaises(BilbyROQParamsRangeError):
bilby.gw.likelihood.ROQGravitationalWaveTransient(
interferometers=interferometers,
priors=self.priors,
waveform_generator=search_waveform_generator,
linear_matrix=basis,
quadratic_matrix=basis,
)
@parameterized.expand(
product(
[_path_to_basis, _path_to_basis_mb],
......