fix(core): correct Crucible-confirmed QS + spectral physics defects#60
Closed
jungdaesuh wants to merge 1 commit into
Closed
fix(core): correct Crucible-confirmed QS + spectral physics defects#60jungdaesuh wants to merge 1 commit into
jungdaesuh wants to merge 1 commit into
Conversation
- qs_bridge: fit-quality status used ok/warn/error, which the contract's Quality (good/warn/bad) and NodeView.QCOLOR can't color; route through contracts.quality_for_k (SSOT). - _slcontour/fit.py + core/quasistationary.py: per-coefficient SVD σ summed the wrong axis (axis=0 → 1/w_k² by singular position, not the covariance diagonal); axis=1 fixes the QS error bars and sizes fit_sigmas to n_cols so underdetermined fits no longer IndexError. - _slcontour/fit.py: 2D sinusoidal-integral basis divided by deg2rad(dx*dy)*n*m (π/180 once, no i²) → m≠0 columns off by -180/π; use the separable product. - core/quasistationary.py reconstruct_grid: used c instead of conj(c) vs its own forward model (and qs_bridge's sign) → toroidal mirror; use conj(c). - core/spectral.py: phase_sigma reported the inverse-variance (BLUE) variance while the intercept is amplitude/coherence-weighted; propagate σ through the same weights so the reported 1σ matches the returned estimator. Adds tests/test_crucible_regressions.py + a qs_bridge quality-vocab test, each failing against the pre-fix behavior. ruff + ty(src) clean; full suite green. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Collaborator
|
Superseded by #68, which is a rebased superset of this PR on current |
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.
Summary
Fixes five confirmed correctness/contract defects in the QS + spectral core, surfaced
by an adversarial (Crucible) review. Each is covered by a regression test that fails
against the pre-fix behavior. No behavioral scope creep.
Related issue
Relates to #40 — three of these are in the pure
core/quasistationaryport, aprerequisite to wiring it in place of the
_slcontourreference.Type of change
src/magnetics/core)src/magnetics/data)src/magnetics/service)gui/web)What changed
qs_bridge: fit-quality status vocabulary (ok/warn/error) diverged from thecontract's
good/warn/bad, so the GUI traffic light lost its color for healthy /ill-conditioned fits → route through
contracts.quality_for_k(SSOT)._slcontour/fit.py+core/quasistationary.py: per-coefficient SVD σ summed thewrong axis (
axis=0→1/w_k²by singular position, not the covariance diagonal) →wrong live QS error bars;
axis=1also sizesfit_sigmaston_cols, fixing anunderdetermined-fit
IndexError._slcontour/fit.py: the 2Dsinusoidal-integralbasis divided bydeg2rad(dx*dy)*n*m(π/180 once, no i²) → m≠0 columns off by −180/π; use theseparable product of the two 1D branches.
core/quasistationary.pyreconstruct_grid: usedcinstead ofconj(c)vs itsown forward model → toroidal mirror.
core/spectral.py:phase_sigmareported the inverse-variance (BLUE) variancewhile the intercept is amplitude/coherence-weighted → propagate σ through the same
weights (honest, non-optimistic 1σ).
How I tested it
uv sync --extra service;uv run ruff format --check ./ruff check ./ty check src/magnetics→ clean;uv run --with pytest pytest -q→ green(
tests/test_crucible_regressions.py+ atest_qs_bridgequality-vocab test, eachfailing against the pre-fix behavior).
Checklist
ruff+pytest; web:lint+build) — validated locallycore(device-agnostic); none added to service routes🤖 Generated with Claude Code