Skip to content

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
mainfrom
fix/delta-mode-scale-jbs-reference
Open

Fix jbs_delta_mode: sigma=0 bootstrap reference must use the same scale_jBS as the draws#45
d-burg wants to merge 1 commit into
mainfrom
fix/delta-mode-scale-jbs-reference

Conversation

@d-burg

@d-burg d-burg commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Fixes #44.

One line: the cached σ=0 bootstrap reference in jbs_delta_mode must be computed
with the same scale_jBS as the per-draw spike.

# TokaMaker_interface.py, cached σ=0 reference for the delta composition
scale_jBS=float(scale_jBS),   # was: 1.0

OFT applies that factor inside SWB, so with a 1.0 reference the delta
composition does not telescope:

spike = bs·SWB0 + bs·SWB_pert − 1.0·SWB0 = bs·SWB_pert − (1 − bs)·SWB0

i.e. every draw loses (1 − bs)/bs of its bootstrap. Zero error at
bs_scale = 1, which is why the default diff workflow never showed it.

Why this targets main rather than only the feature branch that found it:
jBS_baseline_mode="rescale" sets bl.bs_scale to the l_i-matching factor
(run.py), so any rescale-mode run with jbs_delta_mode=True and a calibrated
scale away from 1 is affected on main today.

Verification (DIII-D 173630 @ 4.440 s, bs_scale = 0.7001): predicted
draw/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_consistency
re-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

…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
d-burg force-pushed the fix/delta-mode-scale-jbs-reference branch from 8161df5 to 79a7815 Compare September 4, 2026 19:05
Copilot AI lite review requested due to automatic review settings September 4, 2026 19:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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 appropriate scale_jBS for 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/UnboundLocalError being 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
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.

jbs_delta_mode: sigma=0 bootstrap reference uses scale_jBS=1.0 while draws use bs_scale — draws lose (1-bs)/bs of bootstrap

2 participants