diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 65a54eb66cef71ea4552596cfab13ed3040a5690..f6ceb56370c370db095756dbc954cbdde6b791f4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,6 +18,8 @@ python-2: stage: test image: bilbydev/test-suite-py2 before_script: + # Source the .bashrc for MultiNest + - source /root/.bashrc # Install the dependencies specified in the Pipfile - pipenv install --two --python=/opt/conda/bin/python2 --system --deploy script: @@ -30,6 +32,8 @@ python-3: stage: test image: bilbydev/test-suite-py3 before_script: + # Source the .bashrc for MultiNest + - source /root/.bashrc # Install the dependencies specified in the Pipfile - pipenv install --three --python=/opt/conda/bin/python --system --deploy script: diff --git a/bilby/core/sampler/emcee.py b/bilby/core/sampler/emcee.py index a641586e250fa7d320a023373006217c0ddb42fb..190e8eec7df6ee915748d3c372de701551142102 100644 --- a/bilby/core/sampler/emcee.py +++ b/bilby/core/sampler/emcee.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import +from __future__ import absolute_import, print_function import numpy as np from pandas import DataFrame from ..utils import logger, get_progress_bar diff --git a/bilby/core/sampler/pymc3.py b/bilby/core/sampler/pymc3.py index ae713532529d55edeb2380b2781d98dd19b4f752..a797836f26617118acffa67915388d9cbd90fe29 100644 --- a/bilby/core/sampler/pymc3.py +++ b/bilby/core/sampler/pymc3.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import +from __future__ import absolute_import, print_function from collections import OrderedDict import inspect diff --git a/test/sampler_test.py b/test/sampler_test.py index 963813f007d32fa9c66214c36ed9a5f19a1207b0..d4cac1ae3e35cceb27284dd29b42738ea521d9ec 100644 --- a/test/sampler_test.py +++ b/test/sampler_test.py @@ -5,7 +5,6 @@ from bilby.core.result import Result import unittest from mock import MagicMock import numpy as np -import inspect import os import copy @@ -393,5 +392,63 @@ class TestPymultinest(unittest.TestCase): self.assertDictEqual(expected, self.sampler.kwargs) +class TestRunningSamplers(unittest.TestCase): + + def setUp(self): + np.random.seed(42) + bilby.core.utils.command_line_args.test = False + self.x = np.linspace(0, 1, 11) + self.model = lambda x, m, c: m * x + c + self.injection_parameters = dict(m=0.5, c=0.2) + self.sigma = 0.1 + self.y = self.model(self.x, **self.injection_parameters) +\ + np.random.normal(0, self.sigma, len(self.x)) + self.likelihood = bilby.likelihood.GaussianLikelihood( + self.x, self.y, self.model, self.sigma) + + self.priors = dict( + m=bilby.core.prior.Uniform(0, 5), c=bilby.core.prior.Uniform(-2, 2)) + + def tearDown(self): + del self.likelihood + del self.priors + bilby.core.utils.command_line_args.test = False + + def test_run_cpnest(self): + _ = bilby.run_sampler( + likelihood=self.likelihood, priors=self.priors, sampler='cpnest', + nlive=100, save=False) + + def test_run_dynesty(self): + _ = bilby.run_sampler( + likelihood=self.likelihood, priors=self.priors, sampler='dynesty', + nlive=100, save=False) + + def test_run_emcee(self): + _ = bilby.run_sampler( + likelihood=self.likelihood, priors=self.priors, sampler='emcee', + nsteps=1000, nwalkers=10, save=False) + + def test_run_nestle(self): + _ = bilby.run_sampler( + likelihood=self.likelihood, priors=self.priors, sampler='nestle', + nlive=100, save=False) + + def test_run_ptemcee(self): + _ = bilby.run_sampler( + likelihood=self.likelihood, priors=self.priors, sampler='ptemcee', + nsteps=1000, nwalkers=10, ntemps=10, save=False) + + def test_run_pymc3(self): + _ = bilby.run_sampler( + likelihood=self.likelihood, priors=self.priors, sampler='pymc3', + draws=50, tune=50, n_init=1000, save=False) + + def test_run_pymultinest(self): + _ = bilby.run_sampler( + likelihood=self.likelihood, priors=self.priors, + sampler='pymultinest', nlive=100, save=False) + + if __name__ == '__main__': unittest.main()