Repository navigation
Predict and correct the SHG marginal through a crystal - #39
Open
chrisbrahms wants to merge 15 commits into
Open
chrisbrahms wants to merge 15 commits into
chrisbrahms wants to merge 15 commits into
Conversation
croak.crystals.shg_marginal gives the crystal model's delay-summed SHG marginal (the autoconvolution filtered by the pairs' sinc^2 phase matching, with the principal-plane drift, weighted by the generation prefactor). predicted_marginal, predicted_centroid and apply_marginal_correction take an optional PhaseMatching (crystal + thickness), and load_and_clean's marginal_correct can target it (marginal_crystal), so the correction removes the instrument's response and leaves the phase matching for the crystal model. TraceData records the crystal; the retrieval refuses a corrected trace retrieved through a different medium instead of refusing every corrected trace with a crystal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
build_tracedata takes the crystal the trace was measured through and hands it to the marginal correction; marginal_crystal derives it from the retrieval settings, so the correction and the retrieval always describe the same medium. The session engine and exported scripts pass it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
correction_crystal picks the crystal build_tracedata corrects through (only when the correction is on) and pulse_carrier gives the carrier the retrieval grid will have, so a prediction made before preprocessing matches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
- Refuse a generation envelope (depth_weight) on a crystal-corrected trace: it reweights the depth integral, so the marginal is no longer the one the correction targeted. - Refuse the session's thickness uncertainty on a crystal-corrected trace (the draws would misfit a marginal fixed to the central thickness), and say so in thickness_bootstrap's docstring. - Check that a crystal correction gets the trace's centred grid, and that shg_marginal's inputs are finite. - Say in the guard's message that the same CrystalSetup is needed. - Generated scripts pick the crystal with correction_crystal, as the engine. - Tests: odd grids, an end-to-end correction on a grid whose carrier is not the simulation's, and the new refusals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
The marginals explanation derives the crystal marginal; the marginal-check and SHG-crystal how-tos show the check and the correction through a crystal and what the retrieval then requires. The pending crystal integration fragment no longer says a crystal refuses a corrected trace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
The crystal and the beams describe the apparatus, and the Check stage needs them before Retrieve. One CrystalPanel, bound to state.retrieve, now shows on the measured and synthetic Data pages for SHG; Retrieve keeps a read-only summary and the delay-smearing switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
The Check stage predicts, labels and previews the correction through the crystal when it is modelled, falls back to the thin medium with a warning when the settings give no crystal, and says in the correction's tooltip what it corrects onto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
Prepare resolves the correction's crystal with its parameter snapshot and hands it to build_tracedata, inline and in the worker; invalid crystal settings are a status error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
… stage in the docs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
Toggling the marginal correction on the Check step, or editing the crystal on the Data stage while the correction is on, left the prepared trace in place, and Prepare only recomputes when there is none: the retrieval then used a trace prepared with the old setting (or, through the crystal, refused it with a medium mismatch). Both now drop the prepared trace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
From the model's signal: the pair's depth-dependent phase, the frame dropping out to leave the true mismatch, the analytic depth integral and Parseval over delay; then why the principal-plane drift enters at second order, smearing and zero thickness, and the assumptions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
# Conflicts: # changelog.d/shg-crystal-integration.added.md
This was referenced Nov 17, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch has not been deployed
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.
Important
This PR is part of a stack. Each PR builds on the one before it. Review and merge them in this order:
croak.crystalsand the forward modelsThis PR's base is #38's branch (
feature/shg-smearing), so its diff shows only its own changes. Merge the PRs bottom-up. After each merge, retarget the next PR ontomain.What changed
The marginal checks and the SHG marginal correction can now predict the marginal through a Type I crystal.
croak.crystals.shg_marginalgives the crystal model's delay-summed marginal.predicted_marginal,predicted_centroidandapply_marginal_correctiontake acroak.crystals.PhaseMatching(the crystal and its thickness) together with the pulse carrier.load_and_clean(marginal_correct=True, marginal_crystal=...)corrects a measured trace onto the crystal's marginal. This removes the instrument's spectral response but keeps the phase matching, which the crystal model needs. The crystal used is recorded asTraceData.marginal_crystal.Verification
uv run poe checkpasses on the final commit: the full suite at 100 % statement and branch coverage.uv run poe docsbuilds without warnings.shg_marginalequals the crystal forward model's trace summed over delay. This is checked collinear, crossing out of the principal plane, and crossing in it with the delayed beam on either side, at 0, 20 and 100 µm;Related
Closes #25. Part of #24. Stacked on #38. This PR's base is not
main, so #25 has to be closed by hand when this reachesmain. Related: #35, where the SHG marginal correction scales the regrid's tapered edge rows back up. This PR does not change that.Drafted by Claude (AI).
🤖 Generated with Claude Code
https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX