Skip to content
Snippets Groups Projects
Commit 47d29e5a authored by Colm Talbot's avatar Colm Talbot
Browse files

Merge branch 'test_samplers' into 'master'

add samplers to tests

See merge request Monash/bilby!236
parents 2ab9c1fe 3c13736c
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,8 @@ python-2: ...@@ -18,6 +18,8 @@ python-2:
stage: test stage: test
image: bilbydev/test-suite-py2 image: bilbydev/test-suite-py2
before_script: before_script:
# Source the .bashrc for MultiNest
- source /root/.bashrc
# Install the dependencies specified in the Pipfile # Install the dependencies specified in the Pipfile
- pipenv install --two --python=/opt/conda/bin/python2 --system --deploy - pipenv install --two --python=/opt/conda/bin/python2 --system --deploy
script: script:
...@@ -30,6 +32,8 @@ python-3: ...@@ -30,6 +32,8 @@ python-3:
stage: test stage: test
image: bilbydev/test-suite-py3 image: bilbydev/test-suite-py3
before_script: before_script:
# Source the .bashrc for MultiNest
- source /root/.bashrc
# Install the dependencies specified in the Pipfile # Install the dependencies specified in the Pipfile
- pipenv install --three --python=/opt/conda/bin/python --system --deploy - pipenv install --three --python=/opt/conda/bin/python --system --deploy
script: script:
......
from __future__ import absolute_import from __future__ import absolute_import, print_function
import numpy as np import numpy as np
from pandas import DataFrame from pandas import DataFrame
from ..utils import logger, get_progress_bar from ..utils import logger, get_progress_bar
......
from __future__ import absolute_import from __future__ import absolute_import, print_function
from collections import OrderedDict from collections import OrderedDict
import inspect import inspect
......
...@@ -5,7 +5,6 @@ from bilby.core.result import Result ...@@ -5,7 +5,6 @@ from bilby.core.result import Result
import unittest import unittest
from mock import MagicMock from mock import MagicMock
import numpy as np import numpy as np
import inspect
import os import os
import copy import copy
...@@ -393,5 +392,63 @@ class TestPymultinest(unittest.TestCase): ...@@ -393,5 +392,63 @@ class TestPymultinest(unittest.TestCase):
self.assertDictEqual(expected, self.sampler.kwargs) 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__': if __name__ == '__main__':
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment