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

Merge changes from master and move test

parents 1980ba15 762568df
Pipeline #192292 failed with stage
in 61 minutes and 5 seconds
...@@ -43,7 +43,7 @@ basic-3.7: ...@@ -43,7 +43,7 @@ basic-3.7:
# test example on python 3.7 # test example on python 3.7
python-3.7: python-3.7:
stage: test stage: test
image: bilbydev/v2-dockerfile-test-suite-python37 image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script: script:
- python -m pip install . - python -m pip install .
...@@ -69,7 +69,7 @@ python-3.7: ...@@ -69,7 +69,7 @@ python-3.7:
# test example on python 3.8 # test example on python 3.8
python-3.8: python-3.8:
stage: test stage: test
image: bilbydev/v2-dockerfile-test-suite-python38 image: quay.io/bilbydev/v2-dockerfile-test-suite-python38
script: script:
- python -m pip install . - python -m pip install .
...@@ -78,7 +78,7 @@ python-3.8: ...@@ -78,7 +78,7 @@ python-3.8:
# test example on python 3.6 # test example on python 3.6
python-3.6: python-3.6:
stage: test stage: test
image: bilbydev/v2-dockerfile-test-suite-python36 image: quay.io/bilbydev/v2-dockerfile-test-suite-python36
script: script:
- python -m pip install . - python -m pip install .
...@@ -87,7 +87,7 @@ python-3.6: ...@@ -87,7 +87,7 @@ python-3.6:
# test samplers on python 3.7 # test samplers on python 3.7
python-3.7-samplers: python-3.7-samplers:
stage: test stage: test
image: bilbydev/v2-dockerfile-test-suite-python37 image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script: script:
- python -m pip install . - python -m pip install .
...@@ -97,7 +97,7 @@ python-3.7-samplers: ...@@ -97,7 +97,7 @@ python-3.7-samplers:
# test samplers on python 3.6 # test samplers on python 3.6
python-3.6-samplers: python-3.6-samplers:
stage: test stage: test
image: bilbydev/v2-dockerfile-test-suite-python36 image: quay.io/bilbydev/v2-dockerfile-test-suite-python36
script: script:
- python -m pip install . - python -m pip install .
...@@ -106,7 +106,7 @@ python-3.6-samplers: ...@@ -106,7 +106,7 @@ python-3.6-samplers:
# Test containers are up to date # Test containers are up to date
containers: containers:
stage: test stage: test
image: bilbydev/v2-dockerfile-test-suite-python37 image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script: script:
- cd containers - cd containers
- python write_dockerfiles.py - python write_dockerfiles.py
...@@ -117,7 +117,7 @@ containers: ...@@ -117,7 +117,7 @@ containers:
# Tests run at a fixed schedule rather than on push # Tests run at a fixed schedule rather than on push
scheduled-python-3.7: scheduled-python-3.7:
stage: test stage: test
image: bilbydev/v2-dockerfile-test-suite-python37 image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
only: only:
- schedules - schedules
script: script:
...@@ -129,7 +129,7 @@ scheduled-python-3.7: ...@@ -129,7 +129,7 @@ scheduled-python-3.7:
plotting: plotting:
stage: test stage: test
image: bilbydev/bilby-test-suite-python37 image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
only: only:
- schedules - schedules
script: script:
...@@ -140,7 +140,7 @@ plotting: ...@@ -140,7 +140,7 @@ plotting:
authors: authors:
stage: test stage: test
image: bilbydev/bilby-test-suite-python37 image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script: script:
- python test/check_author_list.py - python test/check_author_list.py
...@@ -162,7 +162,7 @@ pages: ...@@ -162,7 +162,7 @@ pages:
deploy_release: deploy_release:
stage: deploy stage: deploy
image: bilbydev/v2-dockerfile-test-suite-python37 image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
variables: variables:
TWINE_USERNAME: $PYPI_USERNAME TWINE_USERNAME: $PYPI_USERNAME
TWINE_PASSWORD: $PYPI_PASSWORD TWINE_PASSWORD: $PYPI_PASSWORD
...@@ -177,7 +177,7 @@ deploy_release: ...@@ -177,7 +177,7 @@ deploy_release:
precommits-py3.7: precommits-py3.7:
stage: test stage: test
image: bilbydev/v2-dockerfile-test-suite-python37 image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script: script:
- source activate python37 - source activate python37
- mkdir -p .pip37 - mkdir -p .pip37
......
# All notable changes will be documented in this file # All notable changes will be documented in this file
## [1.0.3] 2020-11-23
Version 1.0.4 release of bilby
### Added
- Added a chirp-mass and mass-ratio prior which are uniform in component masses (!891)
### Changes
- Fixed issue in the CI
## [1.0.3] 2020-10-23 ## [1.0.3] 2020-10-23
Version 1.0.3 release of bilby Version 1.0.3 release of bilby
......
...@@ -16,7 +16,6 @@ https://lscsoft.docs.ligo.org/bilby/installation.html. ...@@ -16,7 +16,6 @@ https://lscsoft.docs.ligo.org/bilby/installation.html.
""" """
from __future__ import absolute_import
import sys import sys
from . import core, gw, hyper from . import core, gw, hyper
......
from __future__ import absolute_import
from . import grid, likelihood, prior, result, sampler, series, utils from . import grid, likelihood, prior, result, sampler, series, utils
from __future__ import division
import numpy as np import numpy as np
import os import os
import json import json
......
from __future__ import division, print_function
import copy import copy
import numpy as np import numpy as np
......
...@@ -370,8 +370,8 @@ class SymmetricLogUniform(Prior): ...@@ -370,8 +370,8 @@ class SymmetricLogUniform(Prior):
class Cosine(Prior): class Cosine(Prior):
def __init__(self, name=None, latex_label=None, unit=None, def __init__(self, minimum=-np.pi / 2, maximum=np.pi / 2, name=None,
minimum=-np.pi / 2, maximum=np.pi / 2, boundary=None): latex_label=None, unit=None, boundary=None):
"""Cosine prior with bounds """Cosine prior with bounds
Parameters Parameters
...@@ -389,8 +389,8 @@ class Cosine(Prior): ...@@ -389,8 +389,8 @@ class Cosine(Prior):
boundary: str boundary: str
See superclass See superclass
""" """
super(Cosine, self).__init__(name=name, latex_label=latex_label, unit=unit, super(Cosine, self).__init__(minimum=minimum, maximum=maximum, name=name,
minimum=minimum, maximum=maximum, boundary=boundary) latex_label=latex_label, unit=unit, boundary=boundary)
def rescale(self, val): def rescale(self, val):
""" """
...@@ -425,8 +425,8 @@ class Cosine(Prior): ...@@ -425,8 +425,8 @@ class Cosine(Prior):
class Sine(Prior): class Sine(Prior):
def __init__(self, name=None, latex_label=None, unit=None, minimum=0, def __init__(self, minimum=0, maximum=np.pi, name=None,
maximum=np.pi, boundary=None): latex_label=None, unit=None, boundary=None):
"""Sine prior with bounds """Sine prior with bounds
Parameters Parameters
...@@ -444,8 +444,8 @@ class Sine(Prior): ...@@ -444,8 +444,8 @@ class Sine(Prior):
boundary: str boundary: str
See superclass See superclass
""" """
super(Sine, self).__init__(name=name, latex_label=latex_label, unit=unit, super(Sine, self).__init__(minimum=minimum, maximum=maximum, name=name,
minimum=minimum, maximum=maximum, boundary=boundary) latex_label=latex_label, unit=unit, boundary=boundary)
def rescale(self, val): def rescale(self, val):
""" """
......
...@@ -3,7 +3,6 @@ from io import open as ioopen ...@@ -3,7 +3,6 @@ from io import open as ioopen
import json import json
import os import os
from future.utils import iteritems
from matplotlib.cbook import flatten from matplotlib.cbook import flatten
import numpy as np import numpy as np
...@@ -185,7 +184,7 @@ class PriorDict(dict): ...@@ -185,7 +184,7 @@ class PriorDict(dict):
def from_dictionary(self, dictionary): def from_dictionary(self, dictionary):
eval_dict = dict(inf=np.inf) eval_dict = dict(inf=np.inf)
for key, val in iteritems(dictionary): for key, val in dictionary.items():
if isinstance(val, Prior): if isinstance(val, Prior):
continue continue
elif isinstance(val, (int, float)): elif isinstance(val, (int, float)):
...@@ -391,6 +390,7 @@ class PriorDict(dict): ...@@ -391,6 +390,7 @@ class PriorDict(dict):
samples = self.sample_subset(keys=keys, size=sampling_chunk) samples = self.sample_subset(keys=keys, size=sampling_chunk)
keep = np.atleast_1d(self.evaluate_constraints(samples)) keep = np.atleast_1d(self.evaluate_constraints(samples))
if len(keep) == 1: if len(keep) == 1:
self._cached_normalizations[keys] = 1
return 1 return 1
all_samples = {key: np.array([]) for key in keys} all_samples = {key: np.array([]) for key in keys}
while np.count_nonzero(keep) < min_accept: while np.count_nonzero(keep) < min_accept:
......
from __future__ import division
import inspect import inspect
import os import os
from collections import OrderedDict, namedtuple from collections import OrderedDict, namedtuple
...@@ -238,8 +236,9 @@ class Result(object): ...@@ -238,8 +236,9 @@ class Result(object):
sampler_kwargs=None, injection_parameters=None, sampler_kwargs=None, injection_parameters=None,
meta_data=None, posterior=None, samples=None, meta_data=None, posterior=None, samples=None,
nested_samples=None, log_evidence=np.nan, nested_samples=None, log_evidence=np.nan,
log_evidence_err=np.nan, log_noise_evidence=np.nan, log_evidence_err=np.nan, information_gain=np.nan,
log_bayes_factor=np.nan, log_likelihood_evaluations=None, log_noise_evidence=np.nan, log_bayes_factor=np.nan,
log_likelihood_evaluations=None,
log_prior_evaluations=None, sampling_time=None, nburn=None, log_prior_evaluations=None, sampling_time=None, nburn=None,
num_likelihood_evaluations=None, walkers=None, num_likelihood_evaluations=None, walkers=None,
max_autocorrelation_time=None, use_ratio=None, max_autocorrelation_time=None, use_ratio=None,
...@@ -269,6 +268,8 @@ class Result(object): ...@@ -269,6 +268,8 @@ class Result(object):
An array of the output posterior samples and the unweighted samples An array of the output posterior samples and the unweighted samples
log_evidence, log_evidence_err, log_noise_evidence, log_bayes_factor: float log_evidence, log_evidence_err, log_noise_evidence, log_bayes_factor: float
Natural log evidences Natural log evidences
information_gain: float
The Kullback-Leibler divergence
log_likelihood_evaluations: array_like log_likelihood_evaluations: array_like
The evaluations of the likelihood for each sample point The evaluations of the likelihood for each sample point
num_likelihood_evaluations: int num_likelihood_evaluations: int
...@@ -321,6 +322,7 @@ class Result(object): ...@@ -321,6 +322,7 @@ class Result(object):
self.use_ratio = use_ratio self.use_ratio = use_ratio
self.log_evidence = log_evidence self.log_evidence = log_evidence
self.log_evidence_err = log_evidence_err self.log_evidence_err = log_evidence_err
self.information_gain = information_gain
self.log_noise_evidence = log_noise_evidence self.log_noise_evidence = log_noise_evidence
self.log_bayes_factor = log_bayes_factor self.log_bayes_factor = log_bayes_factor
self.log_likelihood_evaluations = log_likelihood_evaluations self.log_likelihood_evaluations = log_likelihood_evaluations
...@@ -573,7 +575,7 @@ class Result(object): ...@@ -573,7 +575,7 @@ class Result(object):
'log_noise_evidence', 'log_bayes_factor', 'priors', 'posterior', 'log_noise_evidence', 'log_bayes_factor', 'priors', 'posterior',
'injection_parameters', 'meta_data', 'search_parameter_keys', 'injection_parameters', 'meta_data', 'search_parameter_keys',
'fixed_parameter_keys', 'constraint_parameter_keys', 'fixed_parameter_keys', 'constraint_parameter_keys',
'sampling_time', 'sampler_kwargs', 'use_ratio', 'sampling_time', 'sampler_kwargs', 'use_ratio', 'information_gain',
'log_likelihood_evaluations', 'log_prior_evaluations', 'log_likelihood_evaluations', 'log_prior_evaluations',
'num_likelihood_evaluations', 'samples', 'nested_samples', 'num_likelihood_evaluations', 'samples', 'nested_samples',
'walkers', 'nburn', 'parameter_labels', 'parameter_labels_with_unit', 'walkers', 'nburn', 'parameter_labels', 'parameter_labels_with_unit',
......
from __future__ import absolute_import
import datetime import datetime
import distutils.dir_util import distutils.dir_util
import numpy as np import numpy as np
......
from __future__ import absolute_import
import array import array
import copy import copy
...@@ -89,8 +88,8 @@ class Cpnest(NestedSampler): ...@@ -89,8 +88,8 @@ class Cpnest(NestedSampler):
prior_samples = self.priors.sample() prior_samples = self.priors.sample()
self._update_bounds() self._update_bounds()
point = LivePoint( point = LivePoint(
self.names, array.array( self.names, array.array('d', [prior_samples[name] for name in self.names])
'f', [prior_samples[name] for name in self.names])) )
return point return point
self._resolve_proposal_functions() self._resolve_proposal_functions()
...@@ -132,6 +131,7 @@ class Cpnest(NestedSampler): ...@@ -132,6 +131,7 @@ class Cpnest(NestedSampler):
self.result.nested_samples['weights'] = np.exp(log_weights) self.result.nested_samples['weights'] = np.exp(log_weights)
self.result.log_evidence = out.NS.state.logZ self.result.log_evidence = out.NS.state.logZ
self.result.log_evidence_err = np.sqrt(out.NS.state.info / out.NS.state.nlive) self.result.log_evidence_err = np.sqrt(out.NS.state.info / out.NS.state.nlive)
self.result.information_gain = out.NS.state.info
return self.result return self.result
def _verify_kwargs_against_default_kwargs(self): def _verify_kwargs_against_default_kwargs(self):
......
from __future__ import absolute_import
import os import os
import dill as pickle import dill as pickle
......
...@@ -6,7 +6,7 @@ import pickle ...@@ -6,7 +6,7 @@ import pickle
import signal import signal
import time import time
import tqdm from tqdm.auto import tqdm
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from pandas import DataFrame from pandas import DataFrame
...@@ -224,7 +224,7 @@ class Dynesty(NestedSampler): ...@@ -224,7 +224,7 @@ class Dynesty(NestedSampler):
self.kwargs['update_interval'] = int(0.6 * self.kwargs['nlive']) self.kwargs['update_interval'] = int(0.6 * self.kwargs['nlive'])
if self.kwargs['print_func'] is None: if self.kwargs['print_func'] is None:
self.kwargs['print_func'] = self._print_func self.kwargs['print_func'] = self._print_func
self.pbar = tqdm.tqdm(file=sys.stdout) self.pbar = tqdm(file=sys.stdout)
Sampler._verify_kwargs_against_default_kwargs(self) Sampler._verify_kwargs_against_default_kwargs(self)
def _print_func(self, results, niter, ncall=None, dlogz=None, *args, **kwargs): def _print_func(self, results, niter, ncall=None, dlogz=None, *args, **kwargs):
...@@ -401,6 +401,7 @@ class Dynesty(NestedSampler): ...@@ -401,6 +401,7 @@ class Dynesty(NestedSampler):
sorted_samples=self.result.samples) sorted_samples=self.result.samples)
self.result.log_evidence = out.logz[-1] self.result.log_evidence = out.logz[-1]
self.result.log_evidence_err = out.logzerr[-1] self.result.log_evidence_err = out.logzerr[-1]
self.result.information_gain = out.information[-1]
def _run_nested_wrapper(self, kwargs): def _run_nested_wrapper(self, kwargs):
""" Wrapper function to run_nested """ Wrapper function to run_nested
...@@ -612,7 +613,7 @@ class Dynesty(NestedSampler): ...@@ -612,7 +613,7 @@ class Dynesty(NestedSampler):
fig = dyplot.traceplot(self.sampler.results, labels=labels)[0] fig = dyplot.traceplot(self.sampler.results, labels=labels)[0]
fig.tight_layout() fig.tight_layout()
fig.savefig(filename) fig.savefig(filename)
except (RuntimeError, np.linalg.linalg.LinAlgError, ValueError) as e: except (RuntimeError, np.linalg.linalg.LinAlgError, ValueError, OverflowError, Exception) as e:
logger.warning(e) logger.warning(e)
logger.warning('Failed to create dynesty state plot at checkpoint') logger.warning('Failed to create dynesty state plot at checkpoint')
finally: finally:
...@@ -690,6 +691,16 @@ class Dynesty(NestedSampler): ...@@ -690,6 +691,16 @@ class Dynesty(NestedSampler):
""" """
return self.priors.rescale(self._search_parameter_keys, theta) return self.priors.rescale(self._search_parameter_keys, theta)
def calc_likelihood_count(self):
if self.likelihood_benchmark:
if hasattr(self, 'sampler'):
self.result.num_likelihood_evaluations = \
getattr(self.sampler, 'ncall', 0)
else:
self.result.num_likelihood_evaluations = 0
else:
return None
def sample_rwalk_bilby(args): def sample_rwalk_bilby(args):
""" Modified bilby-implemented version of dynesty.sampling.sample_rwalk """ """ Modified bilby-implemented version of dynesty.sampling.sample_rwalk """
......
from __future__ import absolute_import, print_function
from collections import namedtuple from collections import namedtuple
import os import os
import signal import signal
...@@ -12,8 +10,7 @@ from pandas import DataFrame ...@@ -12,8 +10,7 @@ from pandas import DataFrame
from distutils.version import LooseVersion from distutils.version import LooseVersion
import dill as pickle import dill as pickle
from ..utils import ( from ..utils import logger, check_directory_exists_and_if_not_mkdir
logger, get_progress_bar, check_directory_exists_and_if_not_mkdir)
from .base_sampler import MCMCSampler, SamplerError from .base_sampler import MCMCSampler, SamplerError
...@@ -353,7 +350,7 @@ class Emcee(MCMCSampler): ...@@ -353,7 +350,7 @@ class Emcee(MCMCSampler):
self.pos0 = self.sampler.chain[:, -1, :] self.pos0 = self.sampler.chain[:, -1, :]
def run_sampler(self): def run_sampler(self):
tqdm = get_progress_bar() from tqdm.auto import tqdm
sampler_function_kwargs = self.sampler_function_kwargs sampler_function_kwargs = self.sampler_function_kwargs
iterations = sampler_function_kwargs.pop('iterations') iterations = sampler_function_kwargs.pop('iterations')
iterations -= self._previous_iterations iterations -= self._previous_iterations
......
from __future__ import absolute_import
import numpy as np import numpy as np
from .base_sampler import Sampler from .base_sampler import Sampler
......
from __future__ import absolute_import, print_function from ..utils import logger
from ..utils import logger, get_progress_bar
import numpy as np import numpy as np
import os import os
from .emcee import Emcee from .emcee import Emcee
...@@ -141,7 +140,7 @@ class Kombine(Emcee): ...@@ -141,7 +140,7 @@ class Kombine(Emcee):
logger.info("Kombine auto-burnin complete. Removing {} samples from chains".format(self.nburn)) logger.info("Kombine auto-burnin complete. Removing {} samples from chains".format(self.nburn))
self._set_pos0_for_resume() self._set_pos0_for_resume()
tqdm = get_progress_bar() from tqdm.auto import tqdm
sampler_function_kwargs = self.sampler_function_kwargs sampler_function_kwargs = self.sampler_function_kwargs
iterations = sampler_function_kwargs.pop('iterations') iterations = sampler_function_kwargs.pop('iterations')
iterations -= self._previous_iterations iterations -= self._previous_iterations
......
from __future__ import absolute_import
import numpy as np import numpy as np
from pandas import DataFrame from pandas import DataFrame
...@@ -74,6 +73,7 @@ class Nestle(NestedSampler): ...@@ -74,6 +73,7 @@ class Nestle(NestedSampler):
sorted_samples=self.result.samples) sorted_samples=self.result.samples)
self.result.log_evidence = out.logz self.result.log_evidence = out.logz
self.result.log_evidence_err = out.logzerr self.result.log_evidence_err = out.logzerr
self.result.information_gain = out.h
self.calc_likelihood_count() self.calc_likelihood_count()
return self.result return self.result
......
from __future__ import absolute_import
import numpy as np import numpy as np
......