Skip to content

Merge final changes before release#121

Merged
thomasckng merged 7 commits into
mainfrom
jim-dev
Jun 26, 2026
Merged

Merge final changes before release#121
thomasckng merged 7 commits into
mainfrom
jim-dev

Conversation

@thomasckng

@thomasckng thomasckng commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Documentation

    • Updated the README badge display links/content.
  • Refactor

    • Tightened scalar type handling across core computations, transforms, priors, likelihoods, and samplers.
    • Improved compatibility with JAX-style scalar values throughout frequency, time, detector, and sky-coordinate utilities.
    • Standardised several return values and parameters to use native Python floats where appropriate.
  • Bug Fixes

    • Made likelihood and prior calculations consistently return scalar values.
    • Improved cleanup of JAX compilation cache settings during sampler shutdown.

@thomasckng thomasckng added this to the v0.5.0 milestone Jun 26, 2026
@thomasckng thomasckng self-assigned this Jun 26, 2026
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updates the README badges, adds shared scalar typing aliases, and propagates them through core single-event helpers, likelihoods, transforms, and sampler contracts. Several sampler cleanup paths also remove postponed annotation imports and clear JAX compilation cache settings.

Changes

Scalar typing and cleanup

Layer / File(s) Summary
Core contracts
src/jimgw/typing.py, src/jimgw/core/base.py, src/jimgw/core/prior.py, src/jimgw/core/jim.py, src/jimgw/samplers/base.py, src/jimgw/samplers/config.py, src/jimgw/samplers/flowmc.py
Adds scalar aliases and updates core likelihood, prior, and sampler contract annotations to use those aliases or Self.
Single-event utilities
src/jimgw/core/single_event/data.py, src/jimgw/core/single_event/time_utils.py, src/jimgw/core/single_event/utils.py
Single-event data, time, and inner-product helpers accept scalar aliases and cast boundary values to Python floats where needed.
Coordinate helpers
src/jimgw/core/single_event/transform_utils.py, src/jimgw/core/single_event/polarization.py
Mass, spin, and sky-coordinate conversion helpers and Polarization.tensor_from_sky use scalar aliases in their signatures.
Detector contracts
src/jimgw/core/single_event/detector.py
Detector geometry, sky-response, and injection typing use scalar aliases and explicit float casts.
Transform contracts
src/jimgw/core/transforms.py
Transform log-Jacobian returns and scalar parameter annotations switch to FloatScalar or built-in float types.
Likelihood base
src/jimgw/core/single_event/likelihood.py
Base and transient single-event likelihood paths use FloatScalar returns and JAX scalar accumulators.
Heterodyned likelihood
src/jimgw/core/single_event/likelihood.py
Heterodyned likelihood return types, phase-difference typing, and the CMA-ES objective use scalar annotations.
Multibanded likelihood
src/jimgw/core/single_event/likelihood.py
Multibanded likelihood parameters and helper methods use native float forms, with FloatScalar returns and JAX scalar accumulators.
Sampler cleanup
src/jimgw/samplers/__init__.py, src/jimgw/samplers/blackjax/_acceptance_walk_kernel.py, src/jimgw/samplers/blackjax/_imports.py, src/jimgw/samplers/blackjax/ns_aw.py, src/jimgw/samplers/blackjax/nss.py, src/jimgw/samplers/blackjax/smc.py, src/jimgw/samplers/periodic.py
Sampler modules remove postponed annotation imports and reset jax_compilation_cache_dir to None during BlackJAX cleanup.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the PR’s purpose of merging the final release-prep changes before release.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jim-dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

thomasckng and others added 7 commits June 26, 2026 17:30
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
After shutil.rmtree removes the jax_cache directory, the global
jax_compilation_cache_dir config was left pointing at the deleted path.
Post-sampling JAX JIT calls would then attempt to write to that path,
causing FileNotFoundError on cache writes and breaking flowMC's
`if current_cache is None` guard for any Sampler constructed later in
the same process.

Reset to None (the field's default) rather than "" — None correctly
signals "no cache configured" to both JAX internals and flowMC's guard.

Also adds the missing reset to _run_adaptive_persistent in SMC (the
default AP mode was the only _run_* method that had rmtree without the
config reset).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@thomasckng

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/jimgw/core/single_event/likelihood.py`:
- Line 403: Restore the Ruff suppression on the jaxtyping annotation in
_reduce_time so the type hint does not trigger F722; add the same # noqa: F722
comment style used elsewhere in the codebase (for example in flowmc.py) to the
Float[Array, " n_freq"] annotation in the likelihood.py single_event likelihood
helper.

In `@src/jimgw/samplers/blackjax/ns_aw.py`:
- Around line 256-258: The JAX cache reset in the cleanup path only runs on the
successful exit path, so a failure after configure_jax_cache() can leave
jax.config’s compilation cache directory pointing at the checkpoint tree. Move
the cache cleanup into a failure-safe finalization path in ns_aw.py, using the
existing config.checkpoint_dir handling and
jax.config.update("jax_compilation_cache_dir", None) so it executes even when
sampling or checkpoint finalisation raises. Keep the cache directory removal and
config reset tied to the same teardown logic regardless of success or failure.

In `@src/jimgw/samplers/blackjax/nss.py`:
- Around line 242-244: Move the JAX cache cleanup in `NSS` sampling into a
`finally` block so it always runs even if `_sample` raises. Update the control
flow around `configure_jax_cache()` and `_sample` in `blackjax/nss.py` so
`shutil.rmtree(config.checkpoint_dir / "jax_cache", ignore_errors=True)` and
`jax.config.update("jax_compilation_cache_dir", None)` are guaranteed to execute
after the sampling attempt, regardless of success or failure.

In `@src/jimgw/samplers/blackjax/smc.py`:
- Around line 274-276: The JAX cache reset in the runner cleanup paths is only
happening when checkpoint_dir is set on the happy path, so failures can leave
jax_compilation_cache_dir pointing at a stale checkpoint location for the rest
of the process. Update the cleanup logic around configure_jax_cache() in the SMC
runner flows (including the matching cleanup blocks in the other runner modes)
so the global JAX cache config is always reset unconditionally, even when
sampling, checkpoint I/O, or post-processing fails; keep the cache directory
removal guarded by checkpoint_dir, but move the config reset into a guaranteed
cleanup/finally path.

In `@src/jimgw/samplers/flowmc.py`:
- Around line 98-106: The F722 suppressions in _logpdf_flowmc and
_logprior_flowmc are attached to the wrong physical lines, so Ruff still flags
the Float[Array, " n_dims"] annotations. Move the # noqa: F722 comments onto the
parameter-annotation lines in those two methods (or otherwise suppress the exact
offending lines), and keep the fix localized to _logpdf_flowmc and
_logprior_flowmc now that from __future__ import annotations is gone.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b35a34d1-45b6-4f6f-a026-81a7cfd9336a

📥 Commits

Reviewing files that changed from the base of the PR and between 9449511 and ae68492.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (24)
  • README.md
  • src/jimgw/core/base.py
  • src/jimgw/core/jim.py
  • src/jimgw/core/prior.py
  • src/jimgw/core/single_event/data.py
  • src/jimgw/core/single_event/detector.py
  • src/jimgw/core/single_event/likelihood.py
  • src/jimgw/core/single_event/polarization.py
  • src/jimgw/core/single_event/time_utils.py
  • src/jimgw/core/single_event/transform_utils.py
  • src/jimgw/core/single_event/transforms.py
  • src/jimgw/core/single_event/utils.py
  • src/jimgw/core/transforms.py
  • src/jimgw/samplers/__init__.py
  • src/jimgw/samplers/base.py
  • src/jimgw/samplers/blackjax/_acceptance_walk_kernel.py
  • src/jimgw/samplers/blackjax/_imports.py
  • src/jimgw/samplers/blackjax/ns_aw.py
  • src/jimgw/samplers/blackjax/nss.py
  • src/jimgw/samplers/blackjax/smc.py
  • src/jimgw/samplers/config.py
  • src/jimgw/samplers/flowmc.py
  • src/jimgw/samplers/periodic.py
  • src/jimgw/typing.py
💤 Files with no reviewable changes (4)
  • src/jimgw/samplers/init.py
  • src/jimgw/samplers/periodic.py
  • src/jimgw/samplers/blackjax/_acceptance_walk_kernel.py
  • src/jimgw/samplers/blackjax/_imports.py

Comment thread src/jimgw/core/single_event/likelihood.py
Comment on lines 256 to +258
if config.checkpoint_dir is not None:
shutil.rmtree(config.checkpoint_dir / "jax_cache", ignore_errors=True)
jax.config.update("jax_compilation_cache_dir", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Make the JAX cache reset run on failure as well.

The new reset on Line 258 only executes after a clean exit. If sampling or checkpoint finalisation raises after configure_jax_cache(), the process-global jax_compilation_cache_dir stays pinned to this checkpoint tree and the stale-cache-path issue still leaks into the next run.

Suggested fix
-        config.configure_jax_cache()
-        _method_t0 = time.perf_counter()
-
-        def _validated_initial_particles(pos):
-            ...
-
-        ...
-
-        if ckpt_path is not None:
-            ckpt_path.unlink(missing_ok=True)
-        if config.checkpoint_dir is not None:
-            shutil.rmtree(config.checkpoint_dir / "jax_cache", ignore_errors=True)
-            jax.config.update("jax_compilation_cache_dir", None)
+        config.configure_jax_cache()
+        _method_t0 = time.perf_counter()
+        try:
+            def _validated_initial_particles(pos):
+                ...
+
+            ...
+
+            if ckpt_path is not None:
+                ckpt_path.unlink(missing_ok=True)
+        finally:
+            if config.checkpoint_dir is not None:
+                shutil.rmtree(config.checkpoint_dir / "jax_cache", ignore_errors=True)
+                jax.config.update("jax_compilation_cache_dir", None)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if config.checkpoint_dir is not None:
shutil.rmtree(config.checkpoint_dir / "jax_cache", ignore_errors=True)
jax.config.update("jax_compilation_cache_dir", None)
config.configure_jax_cache()
_method_t0 = time.perf_counter()
try:
def _validated_initial_particles(pos):
...
...
if ckpt_path is not None:
ckpt_path.unlink(missing_ok=True)
finally:
if config.checkpoint_dir is not None:
shutil.rmtree(config.checkpoint_dir / "jax_cache", ignore_errors=True)
jax.config.update("jax_compilation_cache_dir", None)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/jimgw/samplers/blackjax/ns_aw.py` around lines 256 - 258, The JAX cache
reset in the cleanup path only runs on the successful exit path, so a failure
after configure_jax_cache() can leave jax.config’s compilation cache directory
pointing at the checkpoint tree. Move the cache cleanup into a failure-safe
finalization path in ns_aw.py, using the existing config.checkpoint_dir handling
and jax.config.update("jax_compilation_cache_dir", None) so it executes even
when sampling or checkpoint finalisation raises. Keep the cache directory
removal and config reset tied to the same teardown logic regardless of success
or failure.

Comment on lines 242 to +244
if config.checkpoint_dir is not None:
shutil.rmtree(config.checkpoint_dir / "jax_cache", ignore_errors=True)
jax.config.update("jax_compilation_cache_dir", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Move the cache teardown into a finally block.

Lines 242-244 only run when _sample completes normally. Any exception after configure_jax_cache() leaves jax_compilation_cache_dir pointing at this checkpoint location, so a failed NSS run can still poison later JAX work in the same process.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/jimgw/samplers/blackjax/nss.py` around lines 242 - 244, Move the JAX
cache cleanup in `NSS` sampling into a `finally` block so it always runs even if
`_sample` raises. Update the control flow around `configure_jax_cache()` and
`_sample` in `blackjax/nss.py` so `shutil.rmtree(config.checkpoint_dir /
"jax_cache", ignore_errors=True)` and
`jax.config.update("jax_compilation_cache_dir", None)` are guaranteed to execute
after the sampling attempt, regardless of success or failure.

Comment on lines 274 to +276
if config.checkpoint_dir is not None:
shutil.rmtree(config.checkpoint_dir / "jax_cache", ignore_errors=True)
jax.config.update("jax_compilation_cache_dir", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Reset the global JAX cache config unconditionally in every runner.

These four cleanups still sit on the happy path only. Each mode calls configure_jax_cache() first, so any failure during sampling, checkpoint I/O, or post-processing leaves jax_compilation_cache_dir set to a stale checkpoint path for the rest of the process.

Also applies to: 395-397, 523-525, 653-655

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/jimgw/samplers/blackjax/smc.py` around lines 274 - 276, The JAX cache
reset in the runner cleanup paths is only happening when checkpoint_dir is set
on the happy path, so failures can leave jax_compilation_cache_dir pointing at a
stale checkpoint location for the rest of the process. Update the cleanup logic
around configure_jax_cache() in the SMC runner flows (including the matching
cleanup blocks in the other runner modes) so the global JAX cache config is
always reset unconditionally, even when sampling, checkpoint I/O, or
post-processing fails; keep the cache directory removal guarded by
checkpoint_dir, but move the config reset into a guaranteed cleanup/finally
path.

Comment thread src/jimgw/samplers/flowmc.py
@thomasckng thomasckng merged commit 3e700ac into main Jun 26, 2026
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant