Add STROOPWAFEL Adaptive Importance Sampling#810
Open
TomWagg wants to merge 48 commits into
Open
Conversation
Collaborator
Author
|
Things for me and @katiebreivik to discuss:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #810 +/- ##
============================================
- Coverage 86.91% 74.46% -12.45%
============================================
Files 40 67 +27
Lines 25542 29361 +3819
Branches 0 986 +986
============================================
- Hits 22198 21862 -336
- Misses 3344 7194 +3850
- Partials 0 305 +305 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Okay this is a big one, finally done with the STROOPWAFL implementation.
This PR adds a vectorised implementation of the STROOPWAFEL adaptive importance sampling algorithm (Broekgaarden et al. 2019) for efficiently sampling rare binary-evolution outcomes (e.g. merging BH–BH / NS–NS), where flat Monte Carlo would need millions of evolutions to collect a usable sample.
The sampler explores parameter space, fits a Gaussian-mixture proposal to discovered "hits", concentrates sampling there, and returns importance-weighted results that stay unbiased estimators of the true prior-weighted population. New code lives under
cosmic.sample.stroopwafel, with the result/checkpoint types incosmic.output.Usage
What's new
Sampling engine (
cosmic.sample.stroopwafel.AdaptiveSampler)mc_only=Truegives a plain Monte Carlo baseline. Multiprocessing vianproc.Parameter space & binary definition
ParameterSpace/Parameter; columns follow the order parameters are supplied.{mass_1, mass_2, porb, ecc, metallicity}; each is either sampled or supplied by a userderive_params(sampled) -> dictcallback (scalars broadcast). Coverage is validated at construction with a clear error.Composable distributions (
cosmic.sample.stroopwafel.distributions)Uniform,PowerLaw,BrokenPowerLaw,TruncatedNormal) composed with coordinate transforms (Identity,Log10,Ln,Sin,CosShift). Each bundles sampling, prior pdf, and adaptive kernel width.kroupa(continuous broken power law, α=−1.3 below 0.5 M⊙ and −2.3 above),sana,sana_ecc,flat_in_log,uniform,uniform_in_sine,uniform_in_cosine,disberg. Extend via aDistributioninstance,register(...), or subclassing.Rejection & hit definitions
rejection.default_rejectapplies physical cuts (secondary-mass floor, ZAMS contact, Roche-lobe overflow at periastron) using COSMIC'sset_reff/a_from_p; it isSSEDict-aware so ZAMS radii use the same stellar engine as evolution (auto-wired into the default reject).any_dco/merging_dco(presets.py), or any(bpp) -> (n_hits, hit_bin_nums)callable.Outputs (
cosmic.output.COSMICStroopOutput)bpp/bcm/initC/kick_info). Addshit_rate/hit_rate_uncertainty,draw_representative_sample(n_samples)(weighted bootstrap returning params + bin numbers), andsave/from_file.Self-contained checkpointing (
cosmic.output.STROOPWAFELCheckpoint)run_exploration()returns a checkpoint (.save(path));AdaptiveSampler.from_checkpoint(path)rebuilds the sampler — parameter space,BSEDict/SSEDict, the callables (serialised withdill, so lambdas/closures survive), and the RNG state — andrun_refinement()resumes with no re-specification. Any constructor argument can be overridden as a keyword.New
bhflagbhflag=4(src/cosmic/src/kick.f, documented incosmic-settings.json): BH natal kicks get fallback scaling even when supplied directly vianatal_kick_array, which is what enables per-binary BH natal-kick sampling in STROOPWAFEL.Documentation
New "Adaptive importance sampling" tutorial series under
docs/pages/tutorials/adaptive/:basics— end-to-end walkthrough (parameter space, binary definition, rejection, hit functions, running, rules of thumb).distributions— built-in registry and how to define custom distributions/transforms.outputs— interpreting importance weights and drawing a representative sample.checkpoint— the self-contained explore/refine workflow.Wired into the tutorials toctree and the
cosmic.sampleAPI reference.Testing
I got a little carried away on the tests...so these tests now outnumber all other COSMIC tests 😅 (Can you tell weights scare me?)
src/cosmic/tests/test_stroopwafel.py— 60 tests covering transforms/distributions (continuity, normalization, KS goodness-of-fit, broken-power-law slope recovery), thebase × transformregistry and custom-distribution paths,ParameterSpace(ordering, transforms, prior, sigma), binary-parameter assembly + validation, rejection, the Gaussian mixture,SSEDictwiring, checkpoint save/restore + overrides, anddraw_representative_sample(verifying returned bin numbers map to matchinginitCinitial conditions). Validated end-to-end against real COSMIC evolution.