-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for nessai sampler in pycbc inference #4567
Conversation
@mj-will Is it possible for nessai to provide a callback with whatever data nessai needs to checkpoint? And similar for resuming? Where possible, we'd like to keep the checkpoint information with our results files. This makes it easier to manage on a heterogeneous cluster where we want a higher level workflow to understand the checkpoint files. |
self.model.update(**self.to_dict(x)) | ||
return getattr(self.model, self.loglikelihood_function) | ||
|
||
def from_unit_hypercube(self, x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This direction can be implemented pretty straightforwardly, see https://github.com/gwastro/pycbc/blob/master/pycbc/inference/sampler/base_cube.py#L82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll look at adding that. Unfortunately, the current implementation requires both directions, though it's something I'm hoping to change in a future release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I don't think that's unreasonable, but would require some changes to the distribution package to support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to leave this not implemented and then revisit both methods together when either the distribution package supports the other direction or nessai doesn't require both. It is unused in the standard sampler, so also wouldn't be testing by running the example. What do you think?
@ahnitz So it already supports something like that for resuming, where you can give it an object rather than a resume file path (see the function below and When you say a callback, would that be a function the user provides to nessai that it can then call internally to checkpoint? pycbc/pycbc/inference/sampler/nessai.py Line 225 in 4169605
|
Yes, exactly. I assume the issue is that you don't have any method of forcing a return to the calling code so that it can do a checkpoint. If that is a technical choice (which may be reasonable depending on the code structure), the alternative would be to take a function and call it with the data you'd have checkpointed at the times you'd normally checkpoint. That still takes away options related to checkpoint frequency, but depending on the library implementation might be the only straightforward solution. |
Yes, that's exactly the issue. Adding support for a checkpointing callback is definitely the more straightforward of the two options, so I'll add that to the roadmap for future nessai releases. Thanks for the suggestion! |
From the discussion on the parameter estimation dev call:
|
nessai does not support 1d likelihoods, so this change is neede to test nessai in the CI
@ahnitz I think I've now addressed the all the relevant code climate issues and what remains are issues with either existing code, code that it's directly copied from existing samplers or code that cannot be changed because it is dictated by how nessai is written, e.g. the use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mj-will Looks good
* add basic support for nessai sampler * enable all options and resuming in nessai * fix prior bounds in nessai model * tweak resuming and samples in nessai interface * change outdir to avoid namespace conflicts * tweaks to nessai sampler class * fix nessai checkpointing and other minor tweaks * fix for reading in nessai result files * use callback for checkpointing in nessai * start addressing codeclimate issues * add nessai to auxiliary samplers * add additional comments for nessai * make simple sampler example 2d nessai does not support 1d likelihoods, so this change is neede to test nessai in the CI * fix call to rng.random * add nessai to samplers example and update plot * set minimum version for nessai * force cpu-only version of torch * add missing epsie jump proposal * add plot-marginal to samplers plot * fix whitespace * use lazy formatting in logging functions * move functions to common nested class * update for change common nested class * address more code climate issues
* add basic support for nessai sampler * enable all options and resuming in nessai * fix prior bounds in nessai model * tweak resuming and samples in nessai interface * change outdir to avoid namespace conflicts * tweaks to nessai sampler class * fix nessai checkpointing and other minor tweaks * fix for reading in nessai result files * use callback for checkpointing in nessai * start addressing codeclimate issues * add nessai to auxiliary samplers * add additional comments for nessai * make simple sampler example 2d nessai does not support 1d likelihoods, so this change is neede to test nessai in the CI * fix call to rng.random * add nessai to samplers example and update plot * set minimum version for nessai * force cpu-only version of torch * add missing epsie jump proposal * add plot-marginal to samplers plot * fix whitespace * use lazy formatting in logging functions * move functions to common nested class * update for change common nested class * address more code climate issues
* add basic support for nessai sampler * enable all options and resuming in nessai * fix prior bounds in nessai model * tweak resuming and samples in nessai interface * change outdir to avoid namespace conflicts * tweaks to nessai sampler class * fix nessai checkpointing and other minor tweaks * fix for reading in nessai result files * use callback for checkpointing in nessai * start addressing codeclimate issues * add nessai to auxiliary samplers * add additional comments for nessai * make simple sampler example 2d nessai does not support 1d likelihoods, so this change is neede to test nessai in the CI * fix call to rng.random * add nessai to samplers example and update plot * set minimum version for nessai * force cpu-only version of torch * add missing epsie jump proposal * add plot-marginal to samplers plot * fix whitespace * use lazy formatting in logging functions * move functions to common nested class * update for change common nested class * address more code climate issues
* add basic support for nessai sampler * enable all options and resuming in nessai * fix prior bounds in nessai model * tweak resuming and samples in nessai interface * change outdir to avoid namespace conflicts * tweaks to nessai sampler class * fix nessai checkpointing and other minor tweaks * fix for reading in nessai result files * use callback for checkpointing in nessai * start addressing codeclimate issues * add nessai to auxiliary samplers * add additional comments for nessai * make simple sampler example 2d nessai does not support 1d likelihoods, so this change is neede to test nessai in the CI * fix call to rng.random * add nessai to samplers example and update plot * set minimum version for nessai * force cpu-only version of torch * add missing epsie jump proposal * add plot-marginal to samplers plot * fix whitespace * use lazy formatting in logging functions * move functions to common nested class * update for change common nested class * address more code climate issues
* add basic support for nessai sampler * enable all options and resuming in nessai * fix prior bounds in nessai model * tweak resuming and samples in nessai interface * change outdir to avoid namespace conflicts * tweaks to nessai sampler class * fix nessai checkpointing and other minor tweaks * fix for reading in nessai result files * use callback for checkpointing in nessai * start addressing codeclimate issues * add nessai to auxiliary samplers * add additional comments for nessai * make simple sampler example 2d nessai does not support 1d likelihoods, so this change is neede to test nessai in the CI * fix call to rng.random * add nessai to samplers example and update plot * set minimum version for nessai * force cpu-only version of torch * add missing epsie jump proposal * add plot-marginal to samplers plot * fix whitespace * use lazy formatting in logging functions * move functions to common nested class * update for change common nested class * address more code climate issues
This PR adds basic support for the nested sampler nessai in pycbc inference.
This implementation is intended as a starting point that can be refined and improved upon, so there are some limitations (see below). Below I mention a few points that I think are important and/or may need some discussion/tweaks.
Changes
pycbc/inference/io/nessai.py
which includes two classes: the main interface and the nessai model objectpycbc/inference/sampler/nessai.py
(based on the equivalent for dynesty)nessai
to the dictionary of samplers inpycbc/inference/sampler/__init__.py
Config files
I wanted to avoid needing to provide types for every single keyword argument nessai supports, so I opted to use
ast.literal_eval
to evaluate the arguments. I can understand wanting to avoid literal evaluations, so I can change this if folks have suggestions.Requirements
I made some changes to nessai to enable easier integration with pycbc, so using nessai requires at least
nessai>=0.10
Limitations
There are a few places the implementation could be improved:
i-nessai
; it requires some additional methods in model class nessai usesTesting
I haven't added any unit or integration tests directly, but I can do if that is desired. Instead, I've been testing the implementation using the scripts in this repo: https://github.com/mj-will/nessai-pycbc-testing and the runs I've been doing as a part of other projects.