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
Showing
with 255 additions and 403 deletions
# This dockerfile is written automatically and should not be modified by hand.
FROM continuumio/miniconda3
LABEL name="bilby Base miniconda3" \
maintainer="Gregory Ashton <gregory.ashton@ligo.org>" \
date="20191114"
maintainer="Gregory Ashton <gregory.ashton@ligo.org>"
RUN conda update -n base -c defaults conda
......@@ -35,13 +36,8 @@ RUN pip install sphinx numpydoc nbsphinx sphinx_rtd_theme sphinx-tabs autodoc
# Install dependencies and samplers
RUN pip install corner lalsuite theano healpy cython tables
RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 pymultinest kombine ultranest dnest4
# Install multinest
RUN git clone https://github.com/farhanferoz/MultiNest.git \
&& (cd MultiNest/MultiNest_v3.12_CMake/multinest && mkdir build && cd build && cmake .. && make)
ENV LD_LIBRARY_PATH $HOME/MultiNest/MultiNest_v3.12_CMake/multinest/lib:
RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 kombine dnest4
RUN conda install -n ${conda_env} -c conda-forge pymultinest ultranest
# Install Polychord
RUN git clone https://github.com/PolyChord/PolyChordLite.git \
......
# This dockerfile is written automatically and should not be modified by hand.
FROM continuumio/miniconda3
LABEL name="bilby Base miniconda3" \
maintainer="Gregory Ashton <gregory.ashton@ligo.org>" \
date="20191114"
maintainer="Gregory Ashton <gregory.ashton@ligo.org>"
RUN conda update -n base -c defaults conda
......@@ -35,13 +36,8 @@ RUN pip install sphinx numpydoc nbsphinx sphinx_rtd_theme sphinx-tabs autodoc
# Install dependencies and samplers
RUN pip install corner lalsuite theano healpy cython tables
RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 pymultinest kombine ultranest dnest4
# Install multinest
RUN git clone https://github.com/farhanferoz/MultiNest.git \
&& (cd MultiNest/MultiNest_v3.12_CMake/multinest && mkdir build && cd build && cmake .. && make)
ENV LD_LIBRARY_PATH $HOME/MultiNest/MultiNest_v3.12_CMake/multinest/lib:
RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 kombine dnest4
RUN conda install -n ${conda_env} -c conda-forge pymultinest ultranest
# Install Polychord
RUN git clone https://github.com/PolyChord/PolyChordLite.git \
......
# This dockerfile is written automatically and should not be modified by hand.
FROM continuumio/miniconda3
LABEL name="bilby Base miniconda3" \
maintainer="Gregory Ashton <gregory.ashton@ligo.org>" \
date="20191114"
maintainer="Gregory Ashton <gregory.ashton@ligo.org>"
RUN conda update -n base -c defaults conda
......@@ -35,13 +36,8 @@ RUN pip install sphinx numpydoc nbsphinx sphinx_rtd_theme sphinx-tabs autodoc
# Install dependencies and samplers
RUN pip install corner lalsuite theano healpy cython tables
RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 pymultinest kombine ultranest dnest4
# Install multinest
RUN git clone https://github.com/farhanferoz/MultiNest.git \
&& (cd MultiNest/MultiNest_v3.12_CMake/multinest && mkdir build && cd build && cmake .. && make)
ENV LD_LIBRARY_PATH $HOME/MultiNest/MultiNest_v3.12_CMake/multinest/lib:
RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 kombine dnest4
RUN conda install -n ${conda_env} -c conda-forge pymultinest ultranest
# Install Polychord
RUN git clone https://github.com/PolyChord/PolyChordLite.git \
......
# This dockerfile is written automatically and should not be modified by hand.
FROM continuumio/miniconda3
LABEL name="bilby Base miniconda3" \
maintainer="Gregory Ashton <gregory.ashton@ligo.org>" \
date="20191114"
maintainer="Gregory Ashton <gregory.ashton@ligo.org>"
RUN conda update -n base -c defaults conda
......@@ -35,13 +36,8 @@ RUN pip install sphinx numpydoc nbsphinx sphinx_rtd_theme sphinx-tabs autodoc
# Install dependencies and samplers
RUN pip install corner lalsuite theano healpy cython tables
RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 pymultinest kombine ultranest dnest4
# Install multinest
RUN git clone https://github.com/farhanferoz/MultiNest.git \
&& (cd MultiNest/MultiNest_v3.12_CMake/multinest && mkdir build && cd build && cmake .. && make)
ENV LD_LIBRARY_PATH $HOME/MultiNest/MultiNest_v3.12_CMake/multinest/lib:
RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 kombine dnest4
RUN conda install -n ${conda_env} -c conda-forge pymultinest ultranest
# Install Polychord
RUN git clone https://github.com/PolyChord/PolyChordLite.git \
......
from datetime import date
with open("dockerfile-template", "r") as ff:
template = ff.read()
python_versions = [(3, 5), (3, 6), (3, 7), (3, 8)]
today = date.today().strftime("%Y%m%d")
for python_major_version, python_minor_version in python_versions:
with open(
"v2-dockerfile-test-suite-python"
f"{python_major_version}{python_minor_version}",
"w"
) as ff:
ff.write(
"# This dockerfile is written automatically and should not be "
"modified by hand.\n\n"
)
ff.write(template.format(
date=today,
python_major_version=python_major_version,
python_minor_version=python_minor_version
))
......@@ -5,12 +5,11 @@ ignore = E129 W503 W504 W605 E203 E402
[tool:pytest]
addopts =
--ignore test/gw/other_test.py
--ignore test/gw/example_test.py
--ignore test/core/example_test.py
--ignore test/gw/sample_from_the_prior_test.py
--ignore test/integration/other_test.py
--ignore test/integration/example_test.py
--ignore test/integration/sample_from_the_prior_test.py
--ignore test/gw/plot_test.py
--ignore test/core/sampler/sampler_run_test.py
--ignore test/integration/sampler_run_test.py
[metadata]
license_file = LICENSE.md
......@@ -64,7 +64,7 @@ def readfile(filename):
return filecontents
VERSION = '1.0.1'
VERSION = '1.0.2'
version_file = write_version_file(VERSION)
long_description = get_long_description()
......
from __future__ import absolute_import
import matplotlib
matplotlib.use("Agg")
import unittest
import os
import shutil
import logging
# Required to run the tests
from past.builtins import execfile
import bilby.core.utils
# Imported to ensure the examples run
import numpy as np # noqa: F401
import inspect # noqa: F401
bilby.core.utils.command_line_args.bilby_test_mode = True
class Test(unittest.TestCase):
outdir = "outdir"
dir_path = os.path.dirname(os.path.realpath(__file__))
dir_path = os.path.abspath(os.path.join(dir_path, os.path.pardir))
@classmethod
def setUpClass(self):
if os.path.isdir(self.outdir):
try:
shutil.rmtree(self.outdir)
except OSError:
logging.warning("{} not removed prior to tests".format(self.outdir))
@classmethod
def tearDownClass(self):
if os.path.isdir(self.outdir):
try:
shutil.rmtree(self.outdir)
except OSError:
logging.warning("{} not removed prior to tests".format(self.outdir))
def test_examples(self):
""" Loop over examples to check they run """
examples = [
"examples/core_examples/linear_regression.py",
"examples/core_examples/linear_regression_unknown_noise.py",
]
for filename in examples:
print("Testing {}".format(filename))
execfile(filename)
if __name__ == "__main__":
unittest.main()
from __future__ import absolute_import, division
import unittest
import numpy as np
import shutil
......@@ -107,65 +105,42 @@ class TestGrid(unittest.TestCase):
self.grid.marginalize_posterior(parameters="jkgsd")
def test_parameter_names(self):
assert list(self.priors.keys()) == self.grid.parameter_names
assert self.grid.n_dims == 2
self.assertListEqual(list(self.priors.keys()), self.grid.parameter_names)
self.assertEqual(2, self.grid.n_dims)
def test_no_marginalization(self):
# test arrays are the same if no parameters are given to marginalize
# over
assert np.array_equal(
self.assertTrue(np.array_equal(
self.grid.ln_likelihood,
self.grid.marginalize_ln_likelihood(
not_parameters=self.grid.parameter_names
),
)
self.grid.marginalize_ln_likelihood(not_parameters=self.grid.parameter_names)))
def test_marginalization_shapes(self):
assert len(self.grid.marginalize_ln_likelihood().shape) == 0
marg1 = self.grid.marginalize_ln_likelihood(
parameters=self.grid.parameter_names[0]
)
assert marg1.shape == (self.grid_size,)
marg2 = self.grid.marginalize_ln_likelihood(
parameters=self.grid.parameter_names[1]
)
assert marg2.shape == (self.grid_size,)
assert self.grid.ln_likelihood.shape == (self.grid_size, self.grid_size)
assert self.grid.ln_posterior.shape == (self.grid_size, self.grid_size)
self.assertEqual(0, len(self.grid.marginalize_ln_likelihood().shape))
marg1 = self.grid.marginalize_ln_likelihood(parameters=self.grid.parameter_names[0])
marg2 = self.grid.marginalize_ln_likelihood(parameters=self.grid.parameter_names[1])
self.assertTupleEqual((self.grid_size,), marg1.shape)
self.assertTupleEqual((self.grid_size,), marg2.shape)
self.assertTupleEqual((self.grid_size, self.grid_size), self.grid.ln_likelihood.shape)
self.assertTupleEqual((self.grid_size, self.grid_size), self.grid.ln_posterior.shape)
def test_marginalization_opposite(self):
assert np.array_equal(
self.grid.marginalize_ln_likelihood(
parameters=self.grid.parameter_names[0]
),
self.grid.marginalize_ln_likelihood(
not_parameters=self.grid.parameter_names[1]
),
)
assert np.array_equal(
self.grid.marginalize_ln_likelihood(
parameters=self.grid.parameter_names[1]
),
self.grid.marginalize_ln_likelihood(
not_parameters=self.grid.parameter_names[0]
),
)
self.assertTrue(np.array_equal(
self.grid.marginalize_ln_likelihood(parameters=self.grid.parameter_names[0]),
self.grid.marginalize_ln_likelihood(not_parameters=self.grid.parameter_names[1])))
self.assertTrue(np.array_equal(
self.grid.marginalize_ln_likelihood(parameters=self.grid.parameter_names[1]),
self.grid.marginalize_ln_likelihood(not_parameters=self.grid.parameter_names[0])))
def test_max_marginalized_likelihood(self):
# marginalised likelihoods should have max values of 1 (as they are not
# properly normalised)
assert (
self.grid.marginalize_likelihood(self.grid.parameter_names[0]).max() == 1.0
)
assert (
self.grid.marginalize_likelihood(self.grid.parameter_names[1]).max() == 1.0
)
self.assertEqual(1.0, self.grid.marginalize_likelihood(self.grid.parameter_names[0]).max())
self.assertEqual(1.0, self.grid.marginalize_likelihood(self.grid.parameter_names[1]).max())
def test_ln_evidence(self):
assert np.isclose(self.grid.ln_evidence, self.expected_ln_evidence)
self.assertAlmostEqual(self.expected_ln_evidence, self.grid.ln_evidence, places=5)
def test_fail_grid_size(self):
with self.assertRaises(TypeError):
......@@ -179,156 +154,100 @@ class TestGrid(unittest.TestCase):
)
def test_mesh_grid(self):
assert self.grid.mesh_grid[0].shape == (self.grid_size, self.grid_size)
assert (
self.grid.mesh_grid[0][0, 0]
== self.priors[self.grid.parameter_names[0]].minimum
)
assert (
self.grid.mesh_grid[0][-1, -1]
== self.priors[self.grid.parameter_names[1]].maximum
)
def test_different_grids(self):
npoints = [10, 20]
self.assertTupleEqual((self.grid_size, self.grid_size), self.grid.mesh_grid[0].shape)
self.assertEqual(self.priors[self.grid.parameter_names[0]].minimum, self.grid.mesh_grid[0][0, 0])
self.assertEqual(self.priors[self.grid.parameter_names[1]].maximum, self.grid.mesh_grid[0][-1, -1])
def test_grid_integer_points(self):
n_points = [10, 20]
grid = bilby.core.grid.Grid(
label="label",
outdir="outdir",
priors=self.priors,
grid_size=npoints,
likelihood=self.likelihood,
grid_size=n_points,
likelihood=self.likelihood
)
assert grid.mesh_grid[0].shape == tuple(npoints)
assert (
grid.mesh_grid[0][0, 0] == self.priors[self.grid.parameter_names[0]].minimum
)
assert (
grid.mesh_grid[0][-1, -1]
== self.priors[self.grid.parameter_names[1]].maximum
)
del grid
npoints = {"x0": 15, "x1": 18}
self.assertTupleEqual(tuple(n_points), grid.mesh_grid[0].shape)
self.assertEqual(grid.mesh_grid[0][0, 0], self.priors[self.grid.parameter_names[0]].minimum)
self.assertEqual(grid.mesh_grid[0][-1, -1], self.priors[self.grid.parameter_names[1]].maximum)
def test_grid_dict_points(self):
n_points = {"x0": 15, "x1": 18}
grid = bilby.core.grid.Grid(
label="label",
outdir="outdir",
priors=self.priors,
grid_size=npoints,
likelihood=self.likelihood,
grid_size=n_points,
likelihood=self.likelihood
)
self.assertTupleEqual((n_points["x0"], n_points["x1"]), grid.mesh_grid[0].shape)
self.assertEqual(grid.mesh_grid[0][0, 0], self.priors[self.grid.parameter_names[0]].minimum)
self.assertEqual(grid.mesh_grid[0][-1, -1], self.priors[self.grid.parameter_names[1]].maximum)
assert grid.mesh_grid[0].shape == (npoints["x0"], npoints["x1"])
assert (
grid.mesh_grid[0][0, 0] == self.priors[self.grid.parameter_names[0]].minimum
)
assert (
grid.mesh_grid[0][-1, -1]
== self.priors[self.grid.parameter_names[1]].maximum
)
del grid
def test_grid_from_array(self):
x0s = np.linspace(self.priors["x0"].minimum, self.priors["x0"].maximum, 13)
x1s = np.linspace(self.priors["x0"].minimum, self.priors["x0"].maximum, 14)
npoints = {"x0": x0s, "x1": x1s}
n_points = {"x0": x0s, "x1": x1s}
grid = bilby.core.grid.Grid(
label="label",
outdir="outdir",
priors=self.priors,
grid_size=npoints,
grid_size=n_points,
likelihood=self.likelihood,
)
assert grid.mesh_grid[0].shape == (len(x0s), len(x1s))
assert (
grid.mesh_grid[0][0, 0] == self.priors[self.grid.parameter_names[0]].minimum
)
assert (
grid.mesh_grid[0][-1, -1]
== self.priors[self.grid.parameter_names[1]].maximum
)
assert np.array_equal(grid.sample_points["x0"], x0s)
assert np.array_equal(grid.sample_points["x1"], x1s)
self.assertTupleEqual((len(x0s), len(x1s)), grid.mesh_grid[0].shape)
self.assertEqual(grid.mesh_grid[0][0, 0], self.priors[self.grid.parameter_names[0]].minimum)
self.assertEqual(grid.mesh_grid[0][-1, -1], self.priors[self.grid.parameter_names[1]].maximum)
def test_save_and_load(self):
filename = os.path.join("outdir", "test_output.json")
self.assertTrue(np.array_equal(grid.sample_points["x0"], x0s))
self.assertTrue(np.array_equal(grid.sample_points["x1"], x1s))
def test_save_and_load_from_filename(self):
filename = os.path.join("outdir", "test_output.json")
self.grid.save_to_file(filename=filename)
# load file
newgrid = bilby.core.grid.Grid.read(filename=filename)
assert newgrid.parameter_names == self.grid.parameter_names
assert newgrid.n_dims == self.grid.n_dims
assert np.array_equal(newgrid.mesh_grid[0], self.grid.mesh_grid[0])
for par in newgrid.parameter_names:
assert np.array_equal(
newgrid.sample_points[par], self.grid.sample_points[par]
)
assert newgrid.ln_evidence == self.grid.ln_evidence
assert np.array_equal(newgrid.ln_likelihood, self.grid.ln_likelihood)
assert np.array_equal(newgrid.ln_posterior, self.grid.ln_posterior)
del newgrid
new_grid = bilby.core.grid.Grid.read(filename=filename)
self.assertListEqual(new_grid.parameter_names, self.grid.parameter_names)
self.assertEqual(new_grid.n_dims, self.grid.n_dims)
self.assertTrue(np.array_equal(new_grid.mesh_grid[0], self.grid.mesh_grid[0]))
for par in new_grid.parameter_names:
self.assertTrue(np.array_equal(new_grid.sample_points[par], self.grid.sample_points[par]))
self.assertEqual(new_grid.ln_evidence, self.grid.ln_evidence)
self.assertTrue(np.array_equal(new_grid.ln_likelihood, self.grid.ln_likelihood))
self.assertTrue(np.array_equal(new_grid.ln_posterior, self.grid.ln_posterior))
def test_save_and_load_from_outdir_label(self):
self.grid.save_to_file(overwrite=True, outdir="outdir")
# load file
newgrid = bilby.core.grid.Grid.read(outdir="outdir", label="label")
assert newgrid.parameter_names == self.grid.parameter_names
assert newgrid.n_dims == self.grid.n_dims
assert np.array_equal(newgrid.mesh_grid[0], self.grid.mesh_grid[0])
for par in newgrid.parameter_names:
assert np.array_equal(
newgrid.sample_points[par], self.grid.sample_points[par]
new_grid = bilby.core.grid.Grid.read(outdir="outdir", label="label")
self.assertListEqual(self.grid.parameter_names, new_grid.parameter_names)
self.assertEqual(self.grid.n_dims, new_grid.n_dims)
self.assertTrue(np.array_equal(new_grid.mesh_grid[0], self.grid.mesh_grid[0]))
for par in new_grid.parameter_names:
self.assertTrue(np.array_equal(
new_grid.sample_points[par], self.grid.sample_points[par])
)
assert newgrid.ln_evidence == self.grid.ln_evidence
assert np.array_equal(newgrid.ln_likelihood, self.grid.ln_likelihood)
assert np.array_equal(newgrid.ln_posterior, self.grid.ln_posterior)
del newgrid
self.assertEqual(self.grid.ln_evidence, new_grid.ln_evidence)
self.assertTrue(np.array_equal(self.grid.ln_likelihood, new_grid.ln_likelihood))
self.assertTrue(np.array_equal(self.grid.ln_posterior, new_grid.ln_posterior))
del new_grid
def test_save_and_load_gzip(self):
filename = os.path.join("outdir", "test_output.json.gz")
self.grid.save_to_file(filename=filename)
new_grid = bilby.core.grid.Grid.read(filename=filename)
# load file
newgrid = bilby.core.grid.Grid.read(filename=filename)
assert newgrid.parameter_names == self.grid.parameter_names
assert newgrid.n_dims == self.grid.n_dims
assert np.array_equal(newgrid.mesh_grid[0], self.grid.mesh_grid[0])
for par in newgrid.parameter_names:
assert np.array_equal(
newgrid.sample_points[par], self.grid.sample_points[par]
)
assert newgrid.ln_evidence == self.grid.ln_evidence
assert np.array_equal(newgrid.ln_likelihood, self.grid.ln_likelihood)
assert np.array_equal(newgrid.ln_posterior, self.grid.ln_posterior)
del newgrid
self.assertListEqual(self.grid.parameter_names, new_grid.parameter_names)
self.assertEqual(self.grid.n_dims, new_grid.n_dims)
self.assertTrue(np.array_equal(self.grid.mesh_grid[0], new_grid.mesh_grid[0]))
for par in new_grid.parameter_names:
self.assertTrue(np.array_equal(self.grid.sample_points[par], new_grid.sample_points[par]))
self.assertEqual(self.grid.ln_evidence, new_grid.ln_evidence)
self.assertTrue(np.array_equal(self.grid.ln_likelihood, new_grid.ln_likelihood))
self.assertTrue(np.array_equal(self.grid.ln_posterior, new_grid.ln_posterior))
self.grid.save_to_file(overwrite=True, outdir="outdir", gzip=True)
# load file
newgrid = bilby.core.grid.Grid.read(outdir="outdir", label="label", gzip=True)
assert newgrid.parameter_names == self.grid.parameter_names
assert newgrid.n_dims == self.grid.n_dims
assert np.array_equal(newgrid.mesh_grid[0], self.grid.mesh_grid[0])
for par in newgrid.parameter_names:
assert np.array_equal(
newgrid.sample_points[par], self.grid.sample_points[par]
)
assert newgrid.ln_evidence == self.grid.ln_evidence
assert np.array_equal(newgrid.ln_likelihood, self.grid.ln_likelihood)
assert np.array_equal(newgrid.ln_posterior, self.grid.ln_posterior)
del newgrid
_ = bilby.core.grid.Grid.read(outdir="outdir", label="label", gzip=True)
from __future__ import absolute_import
# import bilby
import unittest
from mock import MagicMock
import mock
......
......@@ -77,29 +77,21 @@ class TestPriorInstantiationWithoutOptionalPriors(unittest.TestCase):
self.assertIsNone(self.prior.boundary)
class TestPriorName(unittest.TestCase):
class TestPrior(unittest.TestCase):
def setUp(self):
self.test_name = "test_name"
self.prior = bilby.core.prior.Prior(self.test_name)
self.boundary = None
self.prior = bilby.core.prior.Prior(name=self.test_name, boundary=self.boundary)
def tearDown(self):
del self.prior
del self.test_name
del self.boundary
del self.prior
def test_name_assignment(self):
self.prior.name = "other_name"
self.assertEqual(self.prior.name, "other_name")
class TestPriorLatexLabel(unittest.TestCase):
def setUp(self):
self.test_name = "test_name"
self.prior = bilby.core.prior.Prior(self.test_name)
def tearDown(self):
del self.test_name
del self.prior
def test_label_assignment(self):
test_label = "test_label"
self.prior.latex_label = "test_label"
......@@ -113,15 +105,7 @@ class TestPriorLatexLabel(unittest.TestCase):
def test_default_label_assignment_default(self):
self.assertTrue(self.prior.latex_label, self.prior.name)
class TestPriorIsFixed(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
del self.prior
def test_is_fixed_parent_class(self):
def test_is_fixed_base_class(self):
self.prior = bilby.core.prior.Prior()
self.assertFalse(self.prior.is_fixed)
......@@ -129,25 +113,60 @@ class TestPriorIsFixed(unittest.TestCase):
self.prior = bilby.core.prior.DeltaFunction(peak=0)
self.assertTrue(self.prior.is_fixed)
def test_is_fixed_uniform_class(self):
self.prior = bilby.core.prior.Uniform(minimum=0, maximum=10)
self.assertFalse(self.prior.is_fixed)
def test_set_boundary_valid(self):
self.prior.boundary = "periodic"
self.assertEqual(self.prior.boundary, "periodic")
def test_set_boundary_invalid(self):
with self.assertRaises(ValueError):
self.prior.boundary = "else"
class TestPriorBoundary(unittest.TestCase):
class TestConstraint(unittest.TestCase):
def setUp(self):
self.prior = bilby.core.prior.Prior(boundary=None)
self.prior = bilby.core.prior.Constraint(minimum=0, maximum=1)
def tearDown(self):
del self.prior
def test_set_boundary_valid(self):
self.prior.boundary = "periodic"
self.assertEqual(self.prior.boundary, "periodic")
def test_is_fixed_constraint(self):
self.assertTrue(self.prior.is_fixed)
def test_set_boundary_invalid(self):
with self.assertRaises(ValueError):
self.prior.boundary = "else"
def test_prob_outside(self):
self.assertEqual(0, self.prior.prob(-0.5))
def test_prob_inside(self):
self.assertEqual(1, self.prior.prob(0.5))
class TestConstraintPriorNormalisation(unittest.TestCase):
def setUp(self):
self.priors = dict(
a=bilby.core.prior.Uniform(name="a", minimum=5, maximum=10),
b=bilby.core.prior.Uniform(name="b", minimum=5, maximum=10),
c=bilby.core.prior.Constraint(name="c", minimum=0, maximum=1),
)
def conversion_func(parameters):
return dict(a=parameters["a"], b=parameters["b"], c=parameters["a"] / parameters["b"])
self.priors = bilby.core.prior.PriorDict(self.priors, conversion_function=conversion_func)
def test_prob_integrate_to_one(self):
keys = ["a", "b", "c"]
n_samples = 1000000
samples = self.priors.sample_subset(keys=keys, size=n_samples)
prob = self.priors.prob(samples, axis=0)
dm1 = self.priors["a"].maximum - self.priors["a"].minimum
dm2 = self.priors["b"].maximum - self.priors["b"].minimum
prior_volume = (dm1 * dm2)
n_accepted = np.sum(prob)
integral = prior_volume * n_accepted / n_samples
# binomial random distribution
p, q = 0.5, 0.5
sigma = np.sqrt(0.5 * n_samples * p * q)
sigma_integral = prior_volume * sigma / n_samples
# Test will only fail every 390682215445 executions for 7 sigma tolerance
self.assertAlmostEqual(1, integral, delta=7 * sigma_integral)
if __name__ == "__main__":
......
......@@ -2,6 +2,7 @@ import os
import unittest
import numpy as np
from mock import Mock
import bilby
......@@ -454,5 +455,77 @@ class TestLoadPrior(unittest.TestCase):
self.assertTrue(isinstance(prior["logA"], bilby.core.prior.Uniform))
class TestCreateDefaultPrior(unittest.TestCase):
def test_none_behaviour(self):
self.assertIsNone(
bilby.core.prior.create_default_prior(name="name", default_priors_file=None)
)
def test_bbh_params(self):
prior_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"prior_files/precessing_spins_bbh.prior",
)
prior_set = bilby.core.prior.PriorDict(filename=prior_file)
for prior in prior_set:
self.assertEqual(
prior_set[prior],
bilby.core.prior.create_default_prior(
name=prior, default_priors_file=prior_file
),
)
def test_unknown_prior(self):
prior_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"prior_files/precessing_spins_bbh.prior",
)
self.assertIsNone(
bilby.core.prior.create_default_prior(
name="name", default_priors_file=prior_file
)
)
class TestFillPrior(unittest.TestCase):
def setUp(self):
self.likelihood = Mock()
self.likelihood.parameters = dict(a=0, b=0, c=0, d=0, asdf=0, ra=1)
self.likelihood.non_standard_sampling_parameter_keys = dict(t=8)
self.priors = dict(a=1, b=1.1, c="string", d=bilby.core.prior.Uniform(0, 1))
self.priors = bilby.core.prior.PriorDict(dictionary=self.priors)
self.default_prior_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"prior_files/precessing_spins_bbh.prior",
)
self.priors.fill_priors(self.likelihood, self.default_prior_file)
def tearDown(self):
del self.likelihood
del self.priors
def test_prior_instances_are_not_changed_by_parsing(self):
self.assertIsInstance(self.priors["d"], bilby.core.prior.Uniform)
def test_parsing_ints_to_delta_priors_class(self):
self.assertIsInstance(self.priors["a"], bilby.core.prior.DeltaFunction)
def test_parsing_ints_to_delta_priors_with_right_value(self):
self.assertEqual(self.priors["a"].peak, 1)
def test_parsing_floats_to_delta_priors_class(self):
self.assertIsInstance(self.priors["b"], bilby.core.prior.DeltaFunction)
def test_parsing_floats_to_delta_priors_with_right_value(self):
self.assertAlmostEqual(self.priors["b"].peak, 1.1, 1e-8)
def test_without_available_default_priors_no_prior_is_set(self):
with self.assertRaises(KeyError):
print(self.priors["asdf"])
def test_with_available_default_priors_a_default_prior_is_set(self):
self.assertIsInstance(self.priors["ra"], bilby.core.prior.Uniform)
if __name__ == "__main__":
unittest.main()
from __future__ import absolute_import, division
import bilby
import unittest
from mock import Mock
import numpy as np
import os
import scipy.stats as ss
......@@ -751,103 +750,5 @@ class TestPriorClasses(unittest.TestCase):
self.assertTrue(min(prior.sample(10000)) > prior.minimum)
class TestConstraintPriorNormalisation(unittest.TestCase):
def setUp(self):
self.priors = dict(
mass_1=bilby.core.prior.Uniform(
name="mass_1", minimum=5, maximum=10, unit="$M_{\odot}$", boundary=None
),
mass_2=bilby.core.prior.Uniform(
name="mass_2", minimum=5, maximum=10, unit="$M_{\odot}$", boundary=None
),
mass_ratio=bilby.core.prior.Constraint(
name="mass_ratio", minimum=0, maximum=1
),
)
self.priors = bilby.core.prior.PriorDict(self.priors)
def test_prob_integrate_to_one(self):
keys = ["mass_1", "mass_2", "mass_ratio"]
n = 5000
samples = self.priors.sample_subset(keys=keys, size=n)
prob = self.priors.prob(samples, axis=0)
dm1 = self.priors["mass_1"].maximum - self.priors["mass_1"].minimum
dm2 = self.priors["mass_2"].maximum - self.priors["mass_2"].minimum
integral = np.sum(prob * (dm1 * dm2)) / len(samples["mass_1"])
self.assertAlmostEqual(1, integral, 5)
class TestFillPrior(unittest.TestCase):
def setUp(self):
self.likelihood = Mock()
self.likelihood.parameters = dict(a=0, b=0, c=0, d=0, asdf=0, ra=1)
self.likelihood.non_standard_sampling_parameter_keys = dict(t=8)
self.priors = dict(a=1, b=1.1, c="string", d=bilby.core.prior.Uniform(0, 1))
self.priors = bilby.core.prior.PriorDict(dictionary=self.priors)
self.default_prior_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"prior_files/precessing_spins_bbh.prior",
)
self.priors.fill_priors(self.likelihood, self.default_prior_file)
def tearDown(self):
del self.likelihood
del self.priors
def test_prior_instances_are_not_changed_by_parsing(self):
self.assertIsInstance(self.priors["d"], bilby.core.prior.Uniform)
def test_parsing_ints_to_delta_priors_class(self):
self.assertIsInstance(self.priors["a"], bilby.core.prior.DeltaFunction)
def test_parsing_ints_to_delta_priors_with_right_value(self):
self.assertEqual(self.priors["a"].peak, 1)
def test_parsing_floats_to_delta_priors_class(self):
self.assertIsInstance(self.priors["b"], bilby.core.prior.DeltaFunction)
def test_parsing_floats_to_delta_priors_with_right_value(self):
self.assertAlmostEqual(self.priors["b"].peak, 1.1, 1e-8)
def test_without_available_default_priors_no_prior_is_set(self):
with self.assertRaises(KeyError):
print(self.priors["asdf"])
def test_with_available_default_priors_a_default_prior_is_set(self):
self.assertIsInstance(self.priors["ra"], bilby.core.prior.Uniform)
class TestCreateDefaultPrior(unittest.TestCase):
def test_none_behaviour(self):
self.assertIsNone(
bilby.core.prior.create_default_prior(name="name", default_priors_file=None)
)
def test_bbh_params(self):
prior_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"prior_files/precessing_spins_bbh.prior",
)
prior_set = bilby.core.prior.PriorDict(filename=prior_file)
for prior in prior_set:
self.assertEqual(
prior_set[prior],
bilby.core.prior.create_default_prior(
name=prior, default_priors_file=prior_file
),
)
def test_unknown_prior(self):
prior_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"prior_files/precessing_spins_bbh.prior",
)
self.assertIsNone(
bilby.core.prior.create_default_prior(
name="name", default_priors_file=prior_file
)
)
if __name__ == "__main__":
unittest.main()
from __future__ import absolute_import, division
import unittest
import numpy as np
import pandas as pd
......
from __future__ import absolute_import
import bilby
import unittest
import numpy as np
......
from __future__ import absolute_import
import unittest
import numpy as np
......
from __future__ import absolute_import, division
import unittest
import os
......
from __future__ import division, absolute_import
import unittest
import numpy as np
......
from __future__ import division, absolute_import
import unittest
from astropy.cosmology import WMAP9, Planck15
......
from __future__ import division, absolute_import
import unittest
import numpy
import lalsimulation as lalsim
......