-
Notifications
You must be signed in to change notification settings - Fork 6
Add cache-aware Nested Slice within Gibbs sampler #128
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
Open
yallup
wants to merge
2
commits into
jim-dev
Choose a base branch
from
codex/nested-swig-cache
base: jim-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| """GW170817-style 128 s BNS analysis with BlackJAX Nested SwiG. | ||
|
|
||
| This example deliberately uses Ripple's built-in aligned-spin | ||
| IMRPhenomD_NRTidalv2 model. Coalescence time and phase are analytically | ||
| marginalized; the remaining parameters are partitioned into waveform and | ||
| projection blocks. | ||
| """ | ||
|
|
||
| import time | ||
| import math | ||
|
|
||
| import jax | ||
| import jax.numpy as jnp | ||
| from jimgw.core.jim import Jim | ||
| from jimgw.core.prior import ( | ||
| CombinePrior, | ||
| CosinePrior, | ||
| PowerLawPrior, | ||
| SinePrior, | ||
| UniformPrior, | ||
| ) | ||
| from jimgw.core.single_event.data import Data | ||
| from jimgw.core.single_event.detector import get_H1, get_L1, get_V1 | ||
| from jimgw.core.single_event.likelihood import TransientLikelihoodFD | ||
| from jimgw.core.single_event.transforms import MassRatioToSymmetricMassRatioTransform | ||
| from jimgw.core.single_event.waveform import RippleIMRPhenomD_NRTidalv2 | ||
| from jimgw.samplers.config import BlackJAXSwiGConfig | ||
|
|
||
| jax.config.update("jax_enable_x64", True) | ||
|
|
||
|
|
||
| gps = 1187008882.43 | ||
| duration = 128.0 | ||
| start = gps + 2.0 - duration | ||
| end = start + duration | ||
| psd_start = start - 2048.0 | ||
|
|
||
| ifos = [get_H1(), get_L1(), get_V1()] | ||
| for ifo in ifos: | ||
| strain = Data.from_gwosc(ifo.name, start, end) | ||
| ifo.set_data(strain) | ||
| psd_data = Data.from_gwosc(ifo.name, psd_start, start) | ||
| ifo.set_psd( | ||
| psd_data.to_psd(nperseg=int(strain.duration * strain.sampling_frequency)) | ||
| ) | ||
|
|
||
| distance_prior = PowerLawPrior(30.0, 150.0, 2.0, parameter_names=["d_L"]) | ||
| prior = CombinePrior( | ||
| [ | ||
| UniformPrior(1.18, 1.21, parameter_names=["M_c"]), | ||
| UniformPrior(0.5, 1.0, parameter_names=["q"]), | ||
| UniformPrior(-0.05, 0.05, parameter_names=["s1_z"]), | ||
| UniformPrior(-0.05, 0.05, parameter_names=["s2_z"]), | ||
| UniformPrior(0.0, 5000.0, parameter_names=["lambda_1"]), | ||
| UniformPrior(0.0, 5000.0, parameter_names=["lambda_2"]), | ||
| SinePrior(parameter_names=["iota"]), | ||
| distance_prior, | ||
| UniformPrior(0.0, 2.0 * jnp.pi, parameter_names=["ra"]), | ||
| CosinePrior(parameter_names=["dec"]), | ||
| UniformPrior(0.0, jnp.pi, parameter_names=["psi"]), | ||
| ] | ||
| ) | ||
|
|
||
| likelihood = TransientLikelihoodFD( | ||
| ifos, | ||
| waveform=RippleIMRPhenomD_NRTidalv2(f_ref=20.0), | ||
| trigger_time=gps, | ||
| f_min=20.0, | ||
| f_max=2048.0, | ||
| phase_marginalization=True, | ||
| time_marginalization={"tc_range": (-0.03, 0.03)}, | ||
| ) | ||
|
|
||
| jim = Jim( | ||
| likelihood, | ||
| prior, | ||
| likelihood_transforms=[MassRatioToSymmetricMassRatioTransform], | ||
| periodic={ | ||
| "ra": (0.0, 2.0 * float(jnp.pi)), | ||
| "psi": (0.0, float(jnp.pi)), | ||
| }, | ||
| sampler_config=BlackJAXSwiGConfig( | ||
| blocks=[ | ||
| ["M_c", "q", "lambda_1", "lambda_2"], | ||
| ["s1_z", "s2_z"], | ||
| ["iota"], | ||
| ["d_L"], | ||
| ["ra", "dec"], | ||
| ["psi"], | ||
| ], | ||
| n_live=512, | ||
| n_delete_frac=0.125, | ||
| num_inner_steps_per_dim=1, | ||
| num_gibbs_sweeps=2, | ||
| termination_dlogz=math.exp(-3.0), | ||
| ), | ||
| ) | ||
|
|
||
| start_time = time.time() | ||
| jim.sample() | ||
| print(f"Sampling took {(time.time() - start_time) / 60.0:.2f} minutes") | ||
| print(jim.get_diagnostics()) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: GW-JAX-Team/Jim
Length of output: 5196
🏁 Script executed:
Repository: GW-JAX-Team/Jim
Length of output: 38525
🏁 Script executed:
Repository: GW-JAX-Team/Jim
Length of output: 12633
Move
jax_enable_x64above thejimgwimports.src/jimgw/core/single_event/time_utils.pyrequires 64-bit mode at import time, so this example can fail before it reaches line 29. Put the config update immediately after the JAX imports, before anyjimgwimports.🤖 Prompt for AI Agents