Commit 92979104 authored by Michael Williams's avatar Michael Williams
Browse files

Merge branch 'master' of git.ligo.org:michael.williams/bilby into add-nessai-sampler

parents c29a8c3a 833f1256
Pipeline #196435 passed with stages
in 43 minutes and 55 seconds
......@@ -12,6 +12,7 @@
stages:
- initial
- test
- docs
- deploy
.test-python: &test-python
......@@ -47,6 +48,8 @@ python-3.7:
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script:
- python -m pip install .
# temporary fix for broken astropy version
- pip install pyerfa==1.7.1.1
# Run pyflakes
- flake8 .
......@@ -62,12 +65,14 @@ python-3.7:
- htmlcov/
docs:
stage: initial
stage: docs
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script:
# Make the documentation
- apt-get -yqq install pandoc
- python -m pip install .
# temporary fix for broken astropy version
- pip install pyerfa==1.7.1.1
- cd docs
- pip install ipykernel ipython jupyter
- cp ../examples/tutorials/*.ipynb ./
......@@ -88,6 +93,8 @@ python-3.8:
image: quay.io/bilbydev/v2-dockerfile-test-suite-python38
script:
- python -m pip install .
# temporary fix for broken astropy version
- pip install pyerfa==1.7.1.1
- pytest
......@@ -97,6 +104,8 @@ python-3.6:
image: quay.io/bilbydev/v2-dockerfile-test-suite-python36
script:
- python -m pip install .
# temporary fix for broken astropy version
- pip install pyerfa==1.7.1.1
- pytest
......@@ -106,6 +115,8 @@ python-3.7-samplers:
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script:
- python -m pip install .
# temporary fix for broken astropy version
- pip install pyerfa==1.7.1.1
- pytest test/integration/sampler_run_test.py --durations 10
- pytest test/integration/sample_from_the_prior_test.py
......@@ -116,6 +127,8 @@ python-3.6-samplers:
image: quay.io/bilbydev/v2-dockerfile-test-suite-python36
script:
- python -m pip install .
# temporary fix for broken astropy version
- pip install pyerfa==1.7.1.1
- pytest test/integration/sampler_run_test.py
......@@ -138,6 +151,8 @@ scheduled-python-3.7:
- schedules
script:
- python -m pip install .
# temporary fix for broken astropy version
- pip install pyerfa==1.7.1.1
# Run tests which are only done on schedule
- pytest test/integration/example_test.py
......
......@@ -12,6 +12,7 @@ import types
import subprocess
import multiprocessing
from importlib import import_module
from numbers import Number
import json
import warnings
......@@ -953,34 +954,44 @@ class UnsortedInterp2d(interp2d):
"""
from scipy.interpolate.dfitpack import bispeu
x, y = self._sanitize_inputs(x, y)
out_of_bounds_x = (x < self.x_min) | (x > self.x_max)
out_of_bounds_y = (y < self.y_min) | (y > self.y_max)
bad = out_of_bounds_x | out_of_bounds_y
if isinstance(x, float) and isinstance(y, float):
if isinstance(x, Number) and isinstance(y, Number):
if bad:
output = self.fill_value
ier = 0
else:
output, ier = bispeu(*self.tck, x, y)
output = float(output)
else:
if isinstance(x, np.ndarray):
output = np.zeros_like(x)
x_ = x[~bad]
else:
x_ = x * np.ones_like(y)
if isinstance(y, np.ndarray):
output = np.zeros_like(y)
y_ = y[~bad]
else:
y_ = y * np.ones_like(x)
output = np.empty_like(x)
output[bad] = self.fill_value
output[~bad], ier = bispeu(*self.tck, x_, y_)
output[~bad], ier = bispeu(*self.tck, x[~bad], y[~bad])
if ier == 10:
raise ValueError("Invalid input data")
elif ier:
raise TypeError("An error occurred")
return output
@staticmethod
def _sanitize_inputs(x, y):
if isinstance(x, np.ndarray) and x.size == 1:
x = float(x)
if isinstance(y, np.ndarray) and y.size == 1:
y = float(y)
if isinstance(x, np.ndarray) and isinstance(y, np.ndarray):
if x.shape != y.shape:
raise ValueError(
"UnsortedInterp2d received unequally shaped arrays"
)
elif isinstance(x, np.ndarray) and not isinstance(y, np.ndarray):
y = y * np.ones_like(x)
elif not isinstance(x, np.ndarray) and isinstance(y, np.ndarray):
x = x * np.ones_like(y)
return x, y
# Instantiate the default argument parser at runtime
command_line_args, command_line_parser = set_up_command_line_arguments()
......@@ -1211,7 +1222,7 @@ def latex_plot_format(func):
if bilby_mathdefault == 1:
logger.debug("Setting mathdefault in the rcParams")
rcParams['text.latex.preamble'] = r'\newcommand{\mathdefault}[1][]{}'
rcParams['text.latex.preamble'] = r'\providecommand{\mathdefault}[1][]{}'
logger.debug("Using BILBY_STYLE={}".format(bilby_style))
if bilby_style.lower() == "none":
......
......@@ -21,7 +21,7 @@ for line in lines:
for element in line.split()[1:]:
element = element.lower()
if element not in AUTHORS_list and element not in special_cases:
print("Failure: {} not in AUTHOR.md".format(element))
print(f"Failure: {element} not in AUTHOR.md")
fail_test += True
if fail_test:
......
import unittest
import pytest
import sys
from mock import MagicMock
import bilby
@pytest.mark.skipif(sys.version_info[1] <= 6, reason="pymc3 is broken in py36")
class TestPyMC3(unittest.TestCase):
def setUp(self):
self.likelihood = MagicMock()
......
......@@ -312,5 +312,50 @@ class TestLatexPlotFormat(unittest.TestCase):
self.assertTrue(os.path.isfile(self.filename))
class TestUnsortedInterp2d(unittest.TestCase):
def setUp(self):
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
)
def tearDown(self):
pass
def test_returns_float_for_floats(self):
self.assertIsInstance(self.interpolant(0.5, 0.5), float)
def test_returns_none_for_floats_outside_range(self):
self.assertIsNone(self.interpolant(0.5, -0.5))
self.assertIsNone(self.interpolant(-0.5, 0.5))
def test_returns_float_for_float_and_array(self):
self.assertIsInstance(
self.interpolant(0.5, np.random.random(10)), np.ndarray
)
self.assertIsInstance(
self.interpolant(np.random.random(10), 0.5), np.ndarray
)
self.assertIsInstance(
self.interpolant(np.random.random(10), np.random.random(10)),
np.ndarray
)
def test_raises_for_mismatched_arrays(self):
with self.assertRaises(ValueError):
self.interpolant(
np.random.random(10), np.random.random(20)
)
def test_returns_fill_in_correct_place(self):
x_data = np.random.random(10)
y_data = np.random.random(10)
x_data[3] = -1
self.assertTrue(np.isnan(self.interpolant(x_data, y_data)[3]))
if __name__ == "__main__":
unittest.main()
import bilby
import unittest
import numpy as np
import pytest
import shutil
import sys
import bilby
import numpy as np
class TestRunningSamplers(unittest.TestCase):
......@@ -114,6 +117,7 @@ class TestRunningSamplers(unittest.TestCase):
)
def test_run_pypolychord(self):
pytest.importorskip("pypolychord")
_ = bilby.run_sampler(
likelihood=self.likelihood,
priors=self.priors,
......@@ -135,6 +139,7 @@ class TestRunningSamplers(unittest.TestCase):
save=False,
)
@pytest.mark.skipif(sys.version_info[1] <= 6, reason="pymc3 is broken in py36")
def test_run_pymc3(self):
_ = bilby.run_sampler(
likelihood=self.likelihood,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment