-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from mj-will/testing-ci-updates
Testing and CI updates
- Loading branch information
Showing
7 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Lint | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
black: | ||
name: Black | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: psf/black@stable | ||
with: | ||
options: "--check --diff" | ||
src: "./src" | ||
version: "~= 24.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Test the integration with bilby""" | ||
|
||
import bilby | ||
import pytest | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import bilby | ||
import copy | ||
from nessai_bilby.plugin import Nessai, ImportanceNessai | ||
import os | ||
import pytest | ||
from unittest.mock import mock_open, patch | ||
|
||
|
||
@pytest.fixture(params=[Nessai, ImportanceNessai]) | ||
def SamplerClass(request): | ||
return request.param | ||
|
||
|
||
@pytest.fixture() | ||
def create_sampler( | ||
SamplerClass, bilby_gaussian_likelihood_and_priors, tmp_path | ||
): | ||
likelihood, priors = bilby_gaussian_likelihood_and_priors | ||
|
||
def create_fn(**kwargs): | ||
return SamplerClass( | ||
likelihood, | ||
priors, | ||
outdir=tmp_path / "outdir", | ||
label="test", | ||
use_ratio=False, | ||
**kwargs, | ||
) | ||
|
||
return create_fn | ||
|
||
|
||
@pytest.fixture | ||
def sampler(create_sampler): | ||
return create_sampler() | ||
|
||
|
||
@pytest.fixture | ||
def default_kwargs(sampler): | ||
expected = copy.deepcopy(sampler.default_kwargs) | ||
expected["output"] = os.path.join( | ||
sampler.outdir, f"{sampler.label}_{sampler.sampler_name}", "" | ||
) | ||
expected["seed"] = 12345 | ||
return expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"key", | ||
bilby.core.sampler.base_sampler.NestedSampler.npoints_equiv_kwargs, | ||
) | ||
def test_translate_kwargs_nlive(create_sampler, key): | ||
sampler = create_sampler(**{key: 1000}) | ||
assert sampler.kwargs["nlive"] == 1000 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"key", | ||
bilby.core.sampler.base_sampler.NestedSampler.npool_equiv_kwargs, | ||
) | ||
def test_translate_kwargs_npool(create_sampler, key): | ||
sampler = create_sampler(**{key: 2}) | ||
assert sampler.kwargs["n_pool"] == 2 | ||
|
||
|
||
def test_split_kwargs(sampler): | ||
kwargs, run_kwargs = sampler.split_kwargs() | ||
assert "save" not in run_kwargs | ||
assert "plot" in run_kwargs | ||
|
||
|
||
def test_translate_kwargs_no_npool(create_sampler): | ||
sampler = create_sampler() | ||
assert sampler.kwargs["n_pool"] == 1 | ||
|
||
|
||
def test_translate_kwargs_seed(create_sampler): | ||
sampler = create_sampler(sampling_seed=150914) | ||
assert sampler.kwargs["seed"] == 150914 | ||
|
||
|
||
@patch("builtins.open", mock_open(read_data='{"nlive": 4000}')) | ||
def test_update_from_config_file(create_sampler): | ||
sampler = create_sampler(config_file="config_file.json") | ||
assert sampler.kwargs["nlive"] == 4000 | ||
|
||
|
||
def test_expected_outputs(SamplerClass): | ||
expected = os.path.join("outdir", f"test_{SamplerClass.sampler_name}", "") | ||
filenames, dirs = SamplerClass.get_expected_outputs( | ||
outdir="outdir", | ||
label="test", | ||
) | ||
assert len(filenames) == 0 | ||
assert len(dirs) == 3 | ||
assert dirs[0] == expected | ||
assert dirs[1] == os.path.join(expected, "proposal", "") | ||
assert dirs[2] == os.path.join(expected, "diagnostics", "") |