Commit 3c13736c authored by Colm Talbot's avatar Colm Talbot
Browse files

add samplers to tests

parent 2ab9c1fe
......@@ -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:
......
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
......
from __future__ import absolute_import
from __future__ import absolute_import, print_function
from collections import OrderedDict
import inspect
......
......@@ -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()
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