Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bilby-dev/bilby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b36df31ff1917239d222dbd0647ef8b700841f0f
Choose a base ref
..
head repository: bilby-dev/bilby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 508dd5c5fa461fa051e0bb2acf889179a36a6371
Choose a head ref
Showing with 248 additions and 33 deletions.
  1. +71 −4 CONTRIBUTING.md
  2. +1 −1 bilby/gw/conversion.py
  3. +62 −0 bilby/gw/prior.py
  4. +72 −2 bilby/gw/source.py
  5. +0 −2 requirements.txt
  6. +0 −20 test/gw/conversion_test.py
  7. +1 −0 test/gw/likelihood/marginalization_test.py
  8. +38 −0 test/gw/prior_test.py
  9. +3 −4 test/gw/source_test.py
75 changes: 71 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -8,10 +8,11 @@ have some familiarity with python and git.
3. [Automated Code Checking](#automated-code-checking)
4. [Unit Testing](#unit-testing)
5. [Code relevance](#code-relevance)
6. [Pull requests](#pull-requets)
6. [Pull requests](#pull-requests)
7. [Typical workflow](#typical-workflow)
8. [Hints and tips](#hints-and-tips)
9. [Code overview](#code-overview)
8. [Making releases](#making-releases)
9. [Hints and tips](#hints-and-tips)
10. [Code overview](#code-overview)


## Code of Conduct
@@ -308,6 +309,72 @@ you can [convert it to a draft](https://docs.github.com/en/pull-requests/collabo
Once the request has been opened, one of the maintainers will assign someone to
review the change.


## Making releases

**Note:** releases should be made in coordination with other developers and,
doing so requires certain permissions.

### Versioning

We use [semantic versioning](https://semver.org/) when creating bilby releases
and versions should have the format `MAJOR.MINOR.PATCH`.
The version tag should also start with `v` e.g. `v2.4.0`.

`bilby` uses `setuptools_scm` to automatically set the version based on git tags.
This means no manual changes are needed to the version number are required.

### Updating the changelog

Before making a release, the [changelog](https://github.com/bilby-dev/bilby/blob/main/CHANGELOG.md)
should be updated to include the changes since the last release. This should
be done by a new pull request.
We roughly follow the style proposed in [keep a changelog](https://keepachangelog.com/en/1.1.0/)

When making a changelog keep the following in mind:

- Only document meaningful changes to the code. Changes to, e.g., the CI or test suite do not need to be included.
- Include links to the relevant PRs
- Remember to update the URLs at the bottom of changelog file

### Making the release on GitHub

**Note:** releases will automatically be pushed to PyPI and versions on PyPI
cannot be changed, so please take care when making a release.

Once the changelog has been updated, follow these steps for making a release:

1. Navigate to https://github.com/bilby-dev/bilby/releases.
2. Click `Draft new release`.
3. Select an existing tag that does not have a release or specify the name of a
new tag that will be made when the release is made.
4. Specify the version as the title, e.g. `v2.4.0`.
5. Copy the relevant section from the changelog and include a link to the full changelog, e.g.
`**Full Changelog:** https://github.com/bilby-dev/bilby/compare/<previous-release>...<this-release>`
6. If this is latest stable release, make sure `Set at latest release` is checked.
If making a pre-release, make sure `Set as a pre-release` is checked.
7. Check the formatting using the `Preview` tab.
8. Click `Publish release`.

Once step 8 is complete, the CI will trigger and the new release will be
automatically uploaded to PyPI. Check that the CI workflow completed successfully.
After this, you should see the new release on PyPI.

If the CI workflow fails, please contact Colm Talbot (@ColmTalbot) and
Michael Williams (@mj-will).

**Note:** pre-releases will not show up as the latest release on PyPI, but they
are listed under [Release history](https://pypi.org/project/bilby/#history)

### Updating conda-forge

**Note:** we do not currently release pre-releases on `conda-forge`

`conda-forge` is not automatically updated when a new release is made, but an
pull request should be opened automatically on the [bilby feedstock](https://github.com/conda-forge/bilby-feedstock)
(this can take up to a day). Once it is open, follow the steps in the pull request
to review and merge the changes.

## Hints and tips

### Licence
@@ -353,6 +420,6 @@ parts of the code. Note that this document is not programmatically generated and
so may get out of date with time. If you notice something wrong, please open an
issue.

![bilby overview](docs/images/bilby_layout.png)
![bilby overview](https://raw.githubusercontent.com/bilby-dev/bilby/main/docs/images/bilby_layout.png)

**Note** this layout is not comprehensive, for example only a few example "Priors" are shown.
2 changes: 1 addition & 1 deletion bilby/gw/conversion.py
Original file line number Diff line number Diff line change
@@ -259,7 +259,7 @@ def convert_to_lal_binary_black_hole_parameters(parameters):
)
converted_parameters[f"cos_tilt_{idx}"] = 1.0

for key in ["phi_jl", "phi_12", "eccentricity", "mean_per_ano"]:
for key in ["phi_jl", "phi_12"]:
if key not in converted_parameters:
converted_parameters[key] = 0.0

62 changes: 62 additions & 0 deletions bilby/gw/prior.py
Original file line number Diff line number Diff line change
@@ -812,6 +812,68 @@ def phase(self):
""" Return true if priors include phase parameters """
return self.is_nonempty_intersection("phase")

@property
def _cosmological_priors(self):
return [
key for key, prior in self.items() if isinstance(prior, Cosmological)
]

@property
def is_cosmological(self):
"""Return True if any of the priors are cosmological."""
if self._cosmological_priors:
return True
else:
return False

@property
def cosmology(self):
"""The cosmology used in the priors."""
if self.is_cosmological:
return self[self._cosmological_priors[0]].cosmology
else:
return None

def check_valid_cosmology(self, error=True, warning=False):
"""Check that all cosmological priors use the same cosmology.
.. versionadded:: 2.5.0
Parameters
==========
error: bool
Whether to raise a ValueError on failure.
warning: bool
Whether to log a warning on failure.
Returns
=======
bool: whether the cosmological priors are valid.
Raises
======
ValueError: if error is True and the cosmological priors are invalid.
"""
cosmological_priors = self._cosmological_priors
if not cosmological_priors:
return True

from astropy.cosmology import cosmology_equal

cosmologies = [self[key].cosmology for key in self._cosmological_priors]
if all(cosmology_equal(cosmologies[0], c, allow_equivalent=True) for c in cosmologies[1:]):
return True

message = (
"All cosmological priors must use the same cosmology. "
f"Found: {cosmologies}"
)
if warning:
logger.warning(message)
return False
if error:
raise ValueError(message)

def validate_prior(self, duration, minimum_frequency, N=1000, error=True, warning=False):
""" Validate the prior is suitable for use
74 changes: 72 additions & 2 deletions bilby/gw/source.py
Original file line number Diff line number Diff line change
@@ -16,8 +16,22 @@
"""


def gwsignal_binary_black_hole(frequency_array, mass_1, mass_2, luminosity_distance, a_1, tilt_1,
phi_12, a_2, tilt_2, phi_jl, theta_jn, phase, eccentricity, mean_per_ano, **kwargs):
def _base_gwsignal_binary_black_hole(
frequency_array,
mass_1,
mass_2,
luminosity_distance,
a_1,
tilt_1,
phi_12,
a_2,
tilt_2,
phi_jl,
theta_jn,
phase,
eccentricity,
mean_per_ano,
**kwargs):
"""
A binary black hole waveform model using GWsignal
@@ -254,6 +268,62 @@ def gwsignal_binary_black_hole(frequency_array, mass_1, mass_2, luminosity_dista
return dict(plus=h_plus, cross=h_cross)


def gwsignal_binary_black_hole(frequency_array, mass_1, mass_2, luminosity_distance, a_1, tilt_1,
phi_12, a_2, tilt_2, phi_jl, theta_jn, phase, **kwargs):

return _base_gwsignal_binary_black_hole(
frequency_array=frequency_array,
mass_1=mass_1,
mass_2=mass_2,
luminosity_distance=luminosity_distance,
a_1=a_1,
tilt_1=tilt_1,
phi_12=phi_12,
a_2=a_2,
tilt_2=tilt_2,
phi_jl=phi_jl,
theta_jn=theta_jn,
phase=phase,
eccentricity=0,
mean_per_ano=0,
**kwargs)


def gwsignal_eccentric_binary_black_hole(
frequency_array,
mass_1,
mass_2,
luminosity_distance,
a_1,
tilt_1,
phi_12,
a_2,
tilt_2,
phi_jl,
theta_jn,
phase,
eccentricity,
mean_per_ano,
**kwargs):

return _base_gwsignal_binary_black_hole(
frequency_array=frequency_array,
mass_1=mass_1,
mass_2=mass_2,
luminosity_distance=luminosity_distance,
a_1=a_1,
tilt_1=tilt_1,
phi_12=phi_12,
a_2=a_2,
tilt_2=tilt_2,
phi_jl=phi_jl,
theta_jn=theta_jn,
phase=phase,
eccentricity=eccentricity,
mean_per_ano=mean_per_ano,
**kwargs)


def lal_binary_black_hole(
frequency_array, mass_1, mass_2, luminosity_distance, a_1, tilt_1,
phi_12, a_2, tilt_2, phi_jl, theta_jn, phase, **kwargs):
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -12,5 +12,3 @@ tqdm
h5py
attrs
importlib-metadata>=3.6; python_version < '3.10'
parameterized
gwpy
20 changes: 0 additions & 20 deletions test/gw/conversion_test.py
Original file line number Diff line number Diff line change
@@ -428,8 +428,6 @@ def setUp(self):
"tilt_2",
"phi_12",
"phi_jl",
"eccentricity",
"mean_per_ano",
"luminosity_distance",
"theta_jn",
"psi",
@@ -482,24 +480,6 @@ def test_generate_all_bbh_parameters(self):
self.expected_bbh_keys,
)

def test_generate_all_bbh_default_parameters(self):
for default_param in [
"phi_12",
"phi_jl",
"eccentricity",
"mean_per_ano",
]:
param = self.parameters.copy()
if default_param in param:
param.pop(default_param)
ret = bilby.gw.conversion.generate_all_bbh_parameters(param)
self.assertIn(default_param, ret)
self.assertEqual(ret[default_param], 0)

ret = bilby.gw.conversion.generate_all_bbh_parameters(self.parameters)
self.assertIn(default_param, ret)
self.assertEqual(ret[default_param], self.parameters.get(default_param, 0))

def test_generate_all_bns_parameters(self):
self._generate(
bilby.gw.conversion.generate_all_bns_parameters,
1 change: 1 addition & 0 deletions test/gw/likelihood/marginalization_test.py
Original file line number Diff line number Diff line change
@@ -157,6 +157,7 @@ def test_run_sampler_flags_if_marginalized_time_is_sampled(self):
bilby.run_sampler(like, new_prior)


@pytest.mark.requires_roqs
class TestMarginalizations(unittest.TestCase):
"""
Test all marginalised likelihoods matches brute force version.
38 changes: 38 additions & 0 deletions test/gw/prior_test.py
Original file line number Diff line number Diff line change
@@ -170,6 +170,44 @@ def test_add_constraint_prior_not_redundant(self):
)
self.assertFalse(self.bbh_prior_dict.test_has_redundant_keys())

def test_is_cosmological_true(self):
self.bbh_prior_dict["luminosity_distance"] = bilby.gw.prior.UniformComovingVolume(
minimum=10, maximum=10000, name="luminosity_distance"
)
self.assertTrue(self.bbh_prior_dict.is_cosmological)

def test_is_cosmological_false(self):
del self.bbh_prior_dict["luminosity_distance"]
self.assertFalse(self.bbh_prior_dict.is_cosmological)

def test_check_valid_cosmology(self):
self.bbh_prior_dict["luminosity_distance"] = bilby.gw.prior.UniformComovingVolume(
minimum=10, maximum=10000, name="luminosity_distance"
)
self.assertTrue(self.bbh_prior_dict.check_valid_cosmology())

def test_check_valid_cosmology_raises_error(self):
self.bbh_prior_dict["luminosity_distance"] = bilby.gw.prior.UniformComovingVolume(
minimum=10, maximum=10000, name="luminosity_distance", cosmology="Planck15",
)
self.bbh_prior_dict["redshift"] = bilby.gw.prior.UniformComovingVolume(
minimum=0.1, maximum=1, name="redshift", cosmology="Planck15_LAL",
)
self.assertEqual(
self.bbh_prior_dict._cosmological_priors,
["luminosity_distance", "redshift"],
)
self.assertRaises(ValueError, self.bbh_prior_dict.check_valid_cosmology)

def test_cosmology(self):
self.bbh_prior_dict["luminosity_distance"] = bilby.gw.prior.UniformComovingVolume(
minimum=10, maximum=10000, name="luminosity_distance"
)
self.assertEqual(
self.bbh_prior_dict.cosmology,
self.bbh_prior_dict["luminosity_distance"].cosmology,
)

def test_pickle_prior(self):
priors = dict(
chirp_mass=bilby.core.prior.Uniform(10, 20),
7 changes: 3 additions & 4 deletions test/gw/source_test.py
Original file line number Diff line number Diff line change
@@ -130,8 +130,6 @@ def setUp(self):
phi_jl=2.9,
theta_jn=0.3,
phase=0.0,
eccentricity=0,
mean_per_ano=0,
)
self.waveform_kwargs = dict(
waveform_approximant="IMRPhenomXPHM",
@@ -232,11 +230,11 @@ class MyException(Exception):

parameters = self.parameters.copy()
parameters["waveform_approximant"] = "SEOBNRv5PHM"
parameters.update(self.waveform_kwargs)
parameters.update(self.waveform_kwargs | {"eccentricity": 0, "mean_per_ano": 0})
parameters[current_param] = random.uniform(0, 0.3)

with self.assertRaises(MyException):
bilby.gw.source.gwsignal_binary_black_hole(
bilby.gw.source.gwsignal_eccentric_binary_black_hole(
self.frequency_array, **parameters
)

@@ -376,6 +374,7 @@ def test_fails_without_eccentricity(self):
)


@pytest.mark.requires_roqs
class TestROQBBH(unittest.TestCase):
def setUp(self):
roq_dir = "/roq_basis"