Skip to content

Commit

Permalink
MAINT: update for 2.3.0 (#6)
Browse files Browse the repository at this point in the history
* ENH: add `get_expected_outputs` to demo sampler

* TST: add test for `get_expected_outputs`

* CI: install bilby 2.3.0rc0

* MAINT: add more comments explaining get_expected_outputs

* CI: require numpy<2

Co-authored-by: Colm Talbot <[email protected]>

* MAINT: clarify comment about `get_expected_outputs`

* BLD: specify bilby>=2.3.0 in dependencies

* CI: remove bilby and numpy requirements

---------

Co-authored-by: Colm Talbot <[email protected]>
  • Loading branch information
mj-will and ColmTalbot authored Aug 23, 2024
1 parent 431ecec commit 358d084
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
run: |
python -m pip install --upgrade pip
# install bilby directly from source to support plugins
python -m pip install git+https://git.ligo.org/lscsoft/bilby.git
python -m pip install .[test]
- name: Test with pytest
run: |
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ classifiers = [
"Programming Language :: Python :: 3",
]
dependencies = [
"bilby",
"bilby>=2.3.0",
"numpy",
]

Expand Down
53 changes: 53 additions & 0 deletions src/demo_sampler_bilby/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ class DemoSampler(NestedSampler):
This class should inherit from :code:`MCMCSampler` or :code:`NestedSampler`
"""

sampler_name = "demo_sampler"
"""
Name of the sampler. This should match the name specified in the entry
point.
"""
abbreviation = None
"""
Abbreviation for the sampler name. Does not have to be specified.
"""

@property
def external_sampler_name(self) -> str:
"""The name of package that provides the sampler."""
Expand Down Expand Up @@ -75,3 +85,46 @@ def run_sampler(self) -> dict:

# Must return the result object
return self.result

@classmethod
def get_expected_outputs(cls, outdir=None, label=None):
"""Get lists of the expected outputs directories and files.
These are used by :code:`bilby_pipe` when transferring files via
HTCondor. Both can be empty.
Parameters
----------
outdir : str
The output directory.
label : str
The label for the run.
Returns
-------
list
List of file names.
list
List of directory names.
"""
# Update this function to list any files and/or directories produced by
# the sampler when it runs.

# If no files/directories are produced, both lists should be empty.
filenames = []
dirs = []

# If this method is not defined the defaults are used; an empty list
# for filenames and <outdir>/<sampler_name>_<label> for the
# directories. If `abbreviation` has been specified, it will be used
# instead of `<sampler_name>.
# Delete this method to use the defaults.

# Alternatively, if your sampler uses the defaults plus additional
# files and/or directories. Uncomment the following lines and add any
# additional files to the relevant lists.
# Note: the class here should match the parent class.
# filenames, dirs = super(NestedSampler, cls).get_expected_outputs(
# outdir=outdir, label=label
# )
return filenames, dirs
10 changes: 10 additions & 0 deletions tests/test_bilby_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bilby
from demo_sampler_bilby.plugin import DemoSampler
import numpy as np
import pytest

Expand Down Expand Up @@ -44,3 +45,12 @@ def test_run_sampler(bilby_likelihood, bilby_priors, tmp_path, sampler_kwargs):
sampler="demo_sampler", # This should match the name of the sampler
outdir=outdir,
)


def test_expected_outputs():
filenames, dirs = DemoSampler.get_expected_outputs(
outdir="outdir",
label="test",
)
assert len(filenames) == 0
assert len(dirs) == 0

0 comments on commit 358d084

Please sign in to comment.