Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The original MRs are only visible on the [LIGO GitLab repository](https://git.li

## [Unreleased]

### Fixes
* Implemented `get_expected_outputs` for the `Emcee` sampler, which now correctly reports the `chain.dat` and `sampler.pickle` files it writes to the run directory (closes #804)

## [2.7.1]

### Fixes
Expand Down
36 changes: 36 additions & 0 deletions bilby/core/sampler/emcee.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,39 @@ def _generate_result(self):
self.result.log_prior_evaluations = log_priors
self.result.log_evidence = np.nan
self.result.log_evidence_err = np.nan

@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.
The emcee sampler writes its checkpoint information (the serialised
sampler and the tab-separated chain history) inside a per-run
subdirectory ``{outdir}/emcee_{label}/``. The files written there are:

- ``chain.dat``: tab-separated chain history, one row per step per
walker, updated incrementally as the sampler runs.
- ``sampler.pickle``: a dill-pickled copy of the
:class:`emcee.EnsembleSampler` instance, used to resume from the
last completed step.

Parameters
----------
outdir : str
The output directory.
label : str
The label for the run.

Returns
-------
list
List of file names produced by the sampler.
list
List of directory names produced by the sampler.
"""
run_dir = os.path.join(outdir, f"emcee_{label}")
filenames = [
os.path.join(run_dir, "chain.dat"),
os.path.join(run_dir, "sampler.pickle"),
]
return filenames, [run_dir]
15 changes: 15 additions & 0 deletions test/core/sampler/emcee_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import unittest

import bilby
Expand Down Expand Up @@ -71,5 +72,19 @@ def test_translate_kwargs(self):
self.assertDictEqual(expected, self.sampler.kwargs)


def test_get_expected_outputs():
label = "par0"
outdir = os.path.join("some", "bilby_pipe", "dir")
filenames, directories = bilby.core.sampler.emcee.Emcee.get_expected_outputs(
outdir=outdir, label=label
)
assert len(filenames) == 2
assert len(directories) == 1
run_dir = os.path.join(outdir, f"emcee_{label}")
assert run_dir in directories
assert os.path.join(run_dir, "chain.dat") in filenames
assert os.path.join(run_dir, "sampler.pickle") in filenames


if __name__ == "__main__":
unittest.main()