Commit e2a37ebb authored by Michael Williams's avatar Michael Williams

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:
# test example on python 3.7
python-3.7:
stage: test
image: bilbydev/v2-dockerfile-test-suite-python37
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script:
- python -m pip install .
......@@ -69,7 +69,7 @@ python-3.7:
# test example on python 3.8
python-3.8:
stage: test
image: bilbydev/v2-dockerfile-test-suite-python38
image: quay.io/bilbydev/v2-dockerfile-test-suite-python38
script:
- python -m pip install .
......@@ -78,7 +78,7 @@ python-3.8:
# test example on python 3.6
python-3.6:
stage: test
image: bilbydev/v2-dockerfile-test-suite-python36
image: quay.io/bilbydev/v2-dockerfile-test-suite-python36
script:
- python -m pip install .
......@@ -87,7 +87,7 @@ python-3.6:
# test samplers on python 3.7
python-3.7-samplers:
stage: test
image: bilbydev/v2-dockerfile-test-suite-python37
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script:
- python -m pip install .
......@@ -97,7 +97,7 @@ python-3.7-samplers:
# test samplers on python 3.6
python-3.6-samplers:
stage: test
image: bilbydev/v2-dockerfile-test-suite-python36
image: quay.io/bilbydev/v2-dockerfile-test-suite-python36
script:
- python -m pip install .
......@@ -106,7 +106,7 @@ python-3.6-samplers:
# Test containers are up to date
containers:
stage: test
image: bilbydev/v2-dockerfile-test-suite-python37
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script:
- cd containers
- python write_dockerfiles.py
......@@ -117,7 +117,7 @@ containers:
# Tests run at a fixed schedule rather than on push
scheduled-python-3.7:
stage: test
image: bilbydev/v2-dockerfile-test-suite-python37
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
only:
- schedules
script:
......@@ -129,7 +129,7 @@ scheduled-python-3.7:
plotting:
stage: test
image: bilbydev/bilby-test-suite-python37
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
only:
- schedules
script:
......@@ -140,7 +140,7 @@ plotting:
authors:
stage: test
image: bilbydev/bilby-test-suite-python37
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script:
- python test/check_author_list.py
......@@ -162,7 +162,7 @@ pages:
deploy_release:
stage: deploy
image: bilbydev/v2-dockerfile-test-suite-python37
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
variables:
TWINE_USERNAME: $PYPI_USERNAME
TWINE_PASSWORD: $PYPI_PASSWORD
......@@ -177,7 +177,7 @@ deploy_release:
precommits-py3.7:
stage: test
image: bilbydev/v2-dockerfile-test-suite-python37
image: quay.io/bilbydev/v2-dockerfile-test-suite-python37
script:
- source activate python37
- mkdir -p .pip37
......
# 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
Version 1.0.3 release of bilby
......
......@@ -16,7 +16,6 @@ https://lscsoft.docs.ligo.org/bilby/installation.html.
"""
from __future__ import absolute_import
import sys
from . import core, gw, hyper
......
from __future__ import absolute_import
from . import grid, likelihood, prior, result, sampler, series, utils
from __future__ import division
import numpy as np
import os
import json
......
from __future__ import division, print_function
import copy
import numpy as np
......
......@@ -370,8 +370,8 @@ class SymmetricLogUniform(Prior):
class Cosine(Prior):
def __init__(self, name=None, latex_label=None, unit=None,
minimum=-np.pi / 2, maximum=np.pi / 2, boundary=None):
def __init__(self, minimum=-np.pi / 2, maximum=np.pi / 2, name=None,
latex_label=None, unit=None, boundary=None):
"""Cosine prior with bounds
Parameters
......@@ -389,8 +389,8 @@ class Cosine(Prior):
boundary: str
See superclass
"""
super(Cosine, self).__init__(name=name, latex_label=latex_label, unit=unit,
minimum=minimum, maximum=maximum, boundary=boundary)
super(Cosine, self).__init__(minimum=minimum, maximum=maximum, name=name,
latex_label=latex_label, unit=unit, boundary=boundary)
def rescale(self, val):
"""
......@@ -425,8 +425,8 @@ class Cosine(Prior):
class Sine(Prior):
def __init__(self, name=None, latex_label=None, unit=None, minimum=0,
maximum=np.pi, boundary=None):
def __init__(self, minimum=0, maximum=np.pi, name=None,
latex_label=None, unit=None, boundary=None):
"""Sine prior with bounds
Parameters
......@@ -444,8 +444,8 @@ class Sine(Prior):
boundary: str
See superclass
"""
super(Sine, self).__init__(name=name, latex_label=latex_label, unit=unit,
minimum=minimum, maximum=maximum, boundary=boundary)
super(Sine, self).__init__(minimum=minimum, maximum=maximum, name=name,
latex_label=latex_label, unit=unit, boundary=boundary)
def rescale(self, val):
"""
......
......@@ -3,7 +3,6 @@ from io import open as ioopen
import json
import os
from future.utils import iteritems
from matplotlib.cbook import flatten
import numpy as np
......@@ -185,7 +184,7 @@ class PriorDict(dict):
def from_dictionary(self, dictionary):
eval_dict = dict(inf=np.inf)
for key, val in iteritems(dictionary):
for key, val in dictionary.items():
if isinstance(val, Prior):
continue
elif isinstance(val, (int, float)):
......@@ -391,6 +390,7 @@ class PriorDict(dict):
samples = self.sample_subset(keys=keys, size=sampling_chunk)
keep = np.atleast_1d(self.evaluate_constraints(samples))
if len(keep) == 1:
self._cached_normalizations[keys] = 1
return 1
all_samples = {key: np.array([]) for key in keys}
while np.count_nonzero(keep) < min_accept:
......
from __future__ import division
import inspect
import os
from collections import OrderedDict, namedtuple
......@@ -238,8 +236,9 @@ class Result(object):
sampler_kwargs=None, injection_parameters=None,
meta_data=None, posterior=None, samples=None,
nested_samples=None, log_evidence=np.nan,
log_evidence_err=np.nan, log_noise_evidence=np.nan,
log_bayes_factor=np.nan, log_likelihood_evaluations=None,
log_evidence_err=np.nan, information_gain=np.nan,
log_noise_evidence=np.nan, log_bayes_factor=np.nan,
log_likelihood_evaluations=None,
log_prior_evaluations=None, sampling_time=None, nburn=None,
num_likelihood_evaluations=None, walkers=None,
max_autocorrelation_time=None, use_ratio=None,
......@@ -269,6 +268,8 @@ class Result(object):
An array of the output posterior samples and the unweighted samples
log_evidence, log_evidence_err, log_noise_evidence, log_bayes_factor: float
Natural log evidences
information_gain: float
The Kullback-Leibler divergence
log_likelihood_evaluations: array_like
The evaluations of the likelihood for each sample point
num_likelihood_evaluations: int
......@@ -321,6 +322,7 @@ class Result(object):
self.use_ratio = use_ratio
self.log_evidence = log_evidence
self.log_evidence_err = log_evidence_err
self.information_gain = information_gain
self.log_noise_evidence = log_noise_evidence
self.log_bayes_factor = log_bayes_factor
self.log_likelihood_evaluations = log_likelihood_evaluations
......@@ -573,7 +575,7 @@ class Result(object):
'log_noise_evidence', 'log_bayes_factor', 'priors', 'posterior',
'injection_parameters', 'meta_data', 'search_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',
'num_likelihood_evaluations', 'samples', 'nested_samples',
'walkers', 'nburn', 'parameter_labels', 'parameter_labels_with_unit',
......
from __future__ import absolute_import
import datetime
import distutils.dir_util
import numpy as np
......
from __future__ import absolute_import
import array
import copy
......@@ -89,8 +88,8 @@ class Cpnest(NestedSampler):
prior_samples = self.priors.sample()
self._update_bounds()
point = LivePoint(
self.names, array.array(
'f', [prior_samples[name] for name in self.names]))
self.names, array.array('d', [prior_samples[name] for name in self.names])
)
return point
self._resolve_proposal_functions()
......@@ -132,6 +131,7 @@ class Cpnest(NestedSampler):
self.result.nested_samples['weights'] = np.exp(log_weights)
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.information_gain = out.NS.state.info
return self.result
def _verify_kwargs_against_default_kwargs(self):
......
from __future__ import absolute_import
import os
import dill as pickle
......
......@@ -6,7 +6,7 @@ import pickle
import signal
import time
import tqdm
from tqdm.auto import tqdm
import matplotlib.pyplot as plt
import numpy as np
from pandas import DataFrame
......@@ -224,7 +224,7 @@ class Dynesty(NestedSampler):
self.kwargs['update_interval'] = int(0.6 * self.kwargs['nlive'])
if self.kwargs['print_func'] is None:
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)
def _print_func(self, results, niter, ncall=None, dlogz=None, *args, **kwargs):
......@@ -401,6 +401,7 @@ class Dynesty(NestedSampler):
sorted_samples=self.result.samples)
self.result.log_evidence = out.logz[-1]
self.result.log_evidence_err = out.logzerr[-1]
self.result.information_gain = out.information[-1]
def _run_nested_wrapper(self, kwargs):
""" Wrapper function to run_nested
......@@ -612,7 +613,7 @@ class Dynesty(NestedSampler):
fig = dyplot.traceplot(self.sampler.results, labels=labels)[0]
fig.tight_layout()
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('Failed to create dynesty state plot at checkpoint')
finally:
......@@ -690,6 +691,16 @@ class Dynesty(NestedSampler):
"""
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):
""" Modified bilby-implemented version of dynesty.sampling.sample_rwalk """
......
from __future__ import absolute_import, print_function
from collections import namedtuple
import os
import signal
......@@ -12,8 +10,7 @@ from pandas import DataFrame
from distutils.version import LooseVersion
import dill as pickle
from ..utils import (
logger, get_progress_bar, check_directory_exists_and_if_not_mkdir)
from ..utils import logger, check_directory_exists_and_if_not_mkdir
from .base_sampler import MCMCSampler, SamplerError
......@@ -353,7 +350,7 @@ class Emcee(MCMCSampler):
self.pos0 = self.sampler.chain[:, -1, :]
def run_sampler(self):
tqdm = get_progress_bar()
from tqdm.auto import tqdm
sampler_function_kwargs = self.sampler_function_kwargs
iterations = sampler_function_kwargs.pop('iterations')
iterations -= self._previous_iterations
......
from __future__ import absolute_import
import numpy as np
from .base_sampler import Sampler
......
from __future__ import absolute_import, print_function
from ..utils import logger, get_progress_bar
from ..utils import logger
import numpy as np
import os
from .emcee import Emcee
......@@ -141,7 +140,7 @@ class Kombine(Emcee):
logger.info("Kombine auto-burnin complete. Removing {} samples from chains".format(self.nburn))
self._set_pos0_for_resume()
tqdm = get_progress_bar()
from tqdm.auto import tqdm
sampler_function_kwargs = self.sampler_function_kwargs
iterations = sampler_function_kwargs.pop('iterations')
iterations -= self._previous_iterations
......
from __future__ import absolute_import
import numpy as np
from pandas import DataFrame
......@@ -74,6 +73,7 @@ class Nestle(NestedSampler):
sorted_samples=self.result.samples)
self.result.log_evidence = out.logz
self.result.log_evidence_err = out.logzerr
self.result.information_gain = out.h
self.calc_likelihood_count()
return self.result
......
from __future__ import absolute_import
import numpy as np
......
This diff is collapsed.
from __future__ import absolute_import, print_function
import glob
import shutil
......
from __future__ import absolute_import, print_function
from collections import OrderedDict
from distutils.version import StrictVersion
......
from __future__ import absolute_import
import datetime
import distutils.dir_util
......@@ -61,7 +60,7 @@ class Ultranest(NestedSampler):
log_interval=None,
dlogz=None,
max_iters=None,
update_interval_iter_fraction=0.2,
update_interval_volume_fraction=0.2,
viz_callback=None,
dKL=0.5,
frac_remain=0.01,
......@@ -232,7 +231,7 @@ class Ultranest(NestedSampler):
]
else:
keys = [
"update_interval_iter_fraction",
"update_interval_volume_fraction",
"update_interval_ncall",
"log_interval",
"show_status",
......@@ -366,6 +365,8 @@ class Ultranest(NestedSampler):
self.result.nested_samples = nested_samples
self.result.log_evidence = out["logz"]
self.result.log_evidence_err = out["logzerr"]
if self.kwargs["num_live_points"] is not None:
self.result.information_gain = np.power(out["logzerr"], 2) * self.kwargs["num_live_points"]
self.result.outputfiles_basename = self.outputfiles_basename
self.result.sampling_time = datetime.timedelta(seconds=self.total_sampling_time)
from __future__ import division
from distutils.spawn import find_executable
import logging
......@@ -508,26 +507,6 @@ def get_version_information():
print("No version information file '.version' found")
def get_progress_bar(module='tqdm'):
"""
TODO: Write proper docstring
"""
if module in ['tqdm']:
try:
from tqdm import tqdm
except ImportError:
def tqdm(x, *args, **kwargs):
return x
return tqdm
elif module in ['tqdm_notebook']:
try:
from tqdm import tqdm_notebook as tqdm
except ImportError:
def tqdm(x, *args, **kwargs):
return x
return tqdm
def spherical_to_cartesian(radius, theta, phi):
""" Convert from spherical coordinates to cartesian.
......
from __future__ import division
import sys
import multiprocessing
from tqdm import tqdm
from tqdm.auto import tqdm
import numpy as np
from pandas import DataFrame
......
# LIGO India Aundha at Aplus sensitvity.
# LIGO-T2000158
# https://dcc.ligo.org/LIGO-T2000012/public
name = 'A1'
power_spectral_density = PowerSpectralDensity(asd_file='Aplus_asd.txt')
minimum_frequency = 20
maximum_frequency = 2048
length = 4
latitude = 19 + 36. / 60 + 47.9017 / 3600
longitude = 77 + 1. / 60 + 51.0997 / 3600
elevation = 440.0
xarm_azimuth = 117.6157
yarm_azimuth = 207.6165
......@@ -31,7 +31,7 @@ class InterferometerStrainData(object):
time_array = PropertyAccessor('_times_and_frequencies', 'time_array')
def __init__(self, minimum_frequency=0, maximum_frequency=np.inf,
roll_off=0.2):
roll_off=0.2, notch_list=None):
""" Initiate an InterferometerStrainData object
The initialised object contains no data, this should be added using one
......@@ -46,11 +46,14 @@ class InterferometerStrainData(object):
roll_off: float
The roll-off (in seconds) used in the Tukey window, default=0.2s.
This corresponds to alpha * duration / 2 for scipy tukey window.
notch_list: bilby.gw.detector.strain_data.NotchList
A list of notches
"""
self.minimum_frequency = minimum_frequency
self.maximum_frequency = maximum_frequency
self.notch_list = notch_list
self.roll_off = roll_off
self.window_factor = 1
......@@ -122,18 +125,46 @@ class InterferometerStrainData(object):
self._maximum_frequency = maximum_frequency
self._frequency_mask_updated = False
@property
def notch_list(self):
return self._notch_list
@notch_list.setter
def notch_list(self, notch_list):
""" Set the notch_list
Parameters
----------
notch_list: list, bilby.gw.detector.strain_data.NotchList
A list of length-2 tuples of the (max, min) frequency for the
notches or a pre-made bilby NotchList.
"""
if notch_list is None:
self._notch_list = NotchList(None)
elif isinstance(notch_list, list):
self._notch_list = NotchList(notch_list)
elif isinstance(notch_list, NotchList):
self._notch_list = notch_list
else:
raise ValueError("notch_list {} not understood".format(notch_list))
self._frequency_mask_updated = False
@property
def frequency_mask(self):
"""Masking array for limiting the frequency band.
""" Masking array for limiting the frequency band.
Returns
-------
array_like: An array of boolean values
mask: np.ndarray
An array of boolean values
"""
if not self._frequency_mask_updated:
frequency_array = self._times_and_frequencies.frequency_array
mask = ((frequency_array >= self.minimum_frequency) &
(frequency_array <= self.maximum_frequency))
for notch in self.notch_list:
mask[notch.get_idxs(frequency_array)] = False
self._frequency_mask = mask
self._frequency_mask_updated = True
return self._frequency_mask
......@@ -683,3 +714,104 @@ class InterferometerStrainData(object):
strain = strain.resample(sampling_frequency)
self.set_from_gwpy_timeseries(strain)
class Notch(object):
def __init__(self, minimum_frequency, maximum_frequency):
""" A notch object storing the maximum and minimum frequency of the notch
Parameters
----------
minimum_frequency, maximum_frequency: float
The minimum and maximum frequency of the notch
"""
if 0 < minimum_frequency < maximum_frequency < np.inf:
self.minimum_frequency = minimum_frequency
self.maximum_frequency = maximum_frequency