Fix jbs_delta_mode: sigma=0 bootstrap reference must use the same scale_jBS as the draws - #45
Open
d-burg wants to merge 1 commit into
Open
Fix jbs_delta_mode: sigma=0 bootstrap reference must use the same scale_jBS as the draws#45d-burg wants to merge 1 commit into
d-burg wants to merge 1 commit into
Conversation
…draw scale distribution's center
OFT applies scale_jBS INSIDE solve_with_bootstrap, so a 1.0 reference
makes the delta composition
bs*SWB0 + bs*SWB_pert - 1.0*SWB0
lose (1-bs)/bs of the pedestal bootstrap on every draw -- zero error only
at bs_scale=1, which is why the original validation passed.
The center is sigma0_reference_scale(jBS_scale_range): the midpoint of
the configured range (run.py has already re-centred it on bl.bs_scale),
or 1.0 when no range is set (draws then all run at scale 1.0). The
per-draw scale_jBS local CANNOT be used here -- it is bound inside the
draw loop, and referencing it before that raised an UnboundLocalError
that the cache block's blanket except swallowed into a silent
cache-disable fallback.
tests/test_delta_cache_reference.py pins the center semantics, the
helper wiring, and the scoping property itself (an AST load-before-store
check over generate_bouquet's locals that fails on the broken form).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
d-burg
force-pushed
the
fix/delta-mode-scale-jbs-reference
branch
from
September 4, 2026 19:05
8161df5 to
79a7815
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The core fix is localized and well-tested, and the remaining feedback is limited to minor doc/test robustness nits.
Pull request overview
This PR fixes a correctness bug in jbs_delta_mode where the cached σ=0 SWB reference spike was computed with a hard-coded scale_jBS=1.0, causing the delta composition to fail to telescope when baseline bootstrap scaling (bs_scale) differs from 1.
Changes:
- Add
sigma0_reference_scale()helper to define the appropriatescale_jBSfor the σ=0 cached reference. - Use the helper-derived scale when populating the σ=0 SWB cache, aligning the cache reference with per-draw scaling semantics.
- Add targeted tests to lock in reference-scale semantics and prevent regressions from Python scoping/
UnboundLocalErrorbeing silently swallowed.
File summaries
| File | Description |
|---|---|
bouquet/TokaMaker_interface.py |
Introduces sigma0_reference_scale() and uses it to compute the cached σ=0 SWB reference with consistent scaling. |
tests/test_delta_cache_reference.py |
Adds tests covering reference scale semantics and guarding against prior scoping regression patterns. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+99
to
+103
| The cached reference must sit at the CENTER of the per-draw scale | ||
| distribution so the delta composition telescopes at sigma=0: the | ||
| midpoint of ``jBS_scale_range`` (uniform draws -> mean == midpoint; | ||
| run.py has already re-centred the range on ``bl.bs_scale``), and 1.0 | ||
| when no range is configured (every draw then runs at scale 1.0). |
Comment on lines
+41
to
+42
| src = inspect.getsource(tmi) | ||
| assert "_scale_ref = sigma0_reference_scale(jBS_scale_range)" in src |
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.
Fixes #44.
One line: the cached σ=0 bootstrap reference in
jbs_delta_modemust be computedwith the same
scale_jBSas the per-draw spike.OFT applies that factor inside SWB, so with a
1.0reference the deltacomposition does not telescope:
i.e. every draw loses
(1 − bs)/bsof its bootstrap. Zero error atbs_scale = 1, which is why the defaultdiffworkflow never showed it.Why this targets
mainrather than only the feature branch that found it:jBS_baseline_mode="rescale"setsbl.bs_scaleto the l_i-matching factor(
run.py), so any rescale-mode run withjbs_delta_mode=Trueand a calibratedscale away from 1 is affected on
maintoday.Verification (DIII-D 173630 @ 4.440 s,
bs_scale = 0.7001): predicteddraw/baseline j_BS ratio 0.572, measured 0.470–0.507 over two independent
archives; with this fix the implied
SWB(pert)/SWB(σ0)returns to 1.015 ± 0.086.Downstream the draw ensemble moves from Δ′ = 7.22 ± 1.42 (baseline 14.28, i.e.
entirely outside the distribution) to 10.49 ± 2.60 with the best-reproducing draw
at 14.14, and in-spec yield rises from 4/14 to 3/3. Full diagnosis in #44.
Not included here, tracked as follow-up in #44:
verify_sigma0_consistencyre-derives the spike with the correct scaling and therefore never exercises the
delta path — it should be reworked to use the draws' own composition so this
class of defect is caught rather than soft-gated.
🤖 Generated with Claude Code