Skip to content

Thread the SHG crystal through the solvers, sessions and GUI, with BBO - #37

Open
chrisbrahms wants to merge 15 commits into
LupoLab:feature/shg-crystal-corefrom
chrisbrahms:feature/shg-crystal-integration
Open

chrisbrahms wants to merge 15 commits into
LupoLab:feature/shg-crystal-corefrom
chrisbrahms:feature/shg-crystal-integration

Conversation

@chrisbrahms

@chrisbrahms chrisbrahms commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Important

This PR is part of a stack. Each PR builds on the one before it. Review and merge them in this order:

  1. Model SHG in a Type I crystal in the forward models #31: SHG crystal core: croak.crystals and the forward models
  2. Thread the SHG crystal through the solvers, sessions and GUI, with BBO #37: threading through solvers, sessions and GUI; BBO ← this PR
  3. Two-beam delay smearing for SHG FROG #38: two-beam SHG delay smearing
  4. Predict and correct the SHG marginal through a crystal #39: SHG marginal through a crystal

This PR's base is #31's branch (feature/shg-crystal-core), so its diff shows only its own changes. Merge the PRs bottom-up. After each merge, retarget the next PR onto main.

What changed

The second part of #24. It threads the Type I crystal from #31 through the rest of croak and adds BBO.

  • Solvers and uncertainty. Every solver, retrieve_from_tracedata, the bootstraps, the covariance and the thickness uncertainty accept a CrystalSetup as material. The thickness bootstrap gives each drawn thickness the depth nodes it needs.
  • BBO is a built-in crystal (croak.crystals.builtin_crystal). It uses optmat's Tamošauskas et al. 2018 ordinary and extraordinary indices. This raises the requirement to optmat[gas]>=0.10.0, the first optmat release that includes BBO.
  • Sessions describe the crystal with these keys: crystal, cut_angle_deg, angle_mode, tilt_deg, phase_match_nm, polarization, delayed_beam and beam_separation_mm. One TwoBeamGeometry holds the crossing angle.
  • GUI. For SHG data, the Retrieve stage shows Nonlinear crystal and Beam geometry groups. These have read-outs of the solved tilt, the internal angle, the path, the depth nodes and the tilt check. The Synthetic stage can generate SHG traces through the crystal.
  • Marginal correction. TraceData.marginal_corrected records whether a trace was corrected, and a crystal model refuses a corrected trace. Predict and correct the SHG marginal through a crystal #39 relaxes this.
  • Thickness uncertainty. A session's thickness uncertainty now raises a clear error when dispersive propagation is off. Before, it passed the unused slab material on.
  • Docs. A new how-to, SHG FROG with a thick crystal; updates to the GUI guide and the thickness how-to; a changelog fragment.

Not in this PR: two-beam SHG delay smearing (#38, stacked on this) and the crystal-aware marginal check (#39). Fitting the crystal stays refused for SHG (#26).

Verification

  • uv run poe check on the final commit, against the released optmat 0.10.0: lint, format, pyright, codespell, the changelog check and the full suite at 100 % statement and branch coverage. uv run poe docs builds without warnings.
  • BBO's collinear Type I SHG phase-matching angle at 800 nm comes out as 29.226°, which matches the 29.2° cut in Tamošauskas et al. 2018. The test also checks the stated validity range of 0.188–5.2 µm.
  • GUI tests drive both angle modes and both polarisations through qtbot. Session round-trips cover every new key.
  • Each block had an independent review, and the findings were fixed.

Related

Part of #24. Stacked on #31; #38 and #39 build on it. Follow-ups: #26 and #36.

Drafted by Claude (AI).

🤖 Generated with Claude Code

https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX

chrisbrahms and others added 15 commits November 13, 2026 10:12
The solvers, the covariance and the pipeline forward material to the
forward models, so a CrystalSetup works once their types admit it. The
thickness bootstrap raises each draw's depth nodes to what its crystal
thickness needs. Tests drive every registered solver with a crystal, check
that the crystal model fits its own 100 um trace better than ideal SHG,
and that a thick bootstrap draw is resolved rather than refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WM2AxN7Kx14WFWk3qbzDq5
TraceData.marginal_corrected says whether load_and_clean rescaled the
trace's rows onto the spectrum-predicted SHG marginal. That correction
already divides out an estimate of the phase-matching response, so
retrieve_from_tracedata refuses a crystal on such a trace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WM2AxN7Kx14WFWk3qbzDq5
builtin_crystal(name) builds a UniaxialCrystal from optmat's recommended
models of both rays, with the range both hold over as its transparency.
BBO (Tamosauskas et al. 2018) phase-matches 800 nm SHG at 29.226 degrees,
consistent with the paper's nominal 29.2 degree cut and optmat's pin.
materials.optmat_index, the wrapper of an optmat model, is now public so
both modules use it.

Needs optmat with BBO (LupoLab/optmat#48); the dependency bump follows
its release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
RetrieveParams gains the crystal (built-in name), its cut angle, the angle
mode (phase-matched wavelength or external tilt), the fundamental's
polarisation relative to the crossing plane, the delayed beam's side and
the beam separation, which with focal_f_mm sets the crossing angle (0 is
collinear). For an SHG trace with dispersive set, the session builds the
CrystalSetup and passes it, with at least the depth nodes it needs, to the
retrieval, the bootstraps, the covariance and the thickness uncertainty;
PG and SD keep their material slab. The polarisation defaults to the
crossing plane, where the trace stays symmetric.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
For an SHG trace the Retrieve stage shows a Nonlinear crystal group (on/off
and thickness shared with the slab, crystal, cut angle, phase-matched
wavelength or external tilt, polarisation relative to the crossing plane,
delayed beam's side) and a Beam geometry group (beam separation and the
focal length the focal mixture also uses), in place of the material slab.
A read-out gives the internal angle, the tilt, the path and the depth
nodes, or why the settings give no crystal. Thickness fitting stays off for
a crystal (LupoLab#26).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
The Synthetic stage can make an SHG trace through the nonlinear crystal the
Retrieve stage describes, at a thickness set there, so a trace made in a
crystal and its retrieval share one description of the crystal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
A how-to page covers describing the crystal (built-in or custom indices,
cut angle with a tilt or a phase-matched wavelength, the beam geometry and
depth nodes), the polarisation and the delayed beam's side, the session
and GUI settings, what is not modelled yet (SHG smearing, fitting the
crystal, marginal-corrected traces) and how the model compares with
full-field simulations. The models guide, the feature list, the GUI and
thickness-fitting pages point to it; a release-note fragment records the
change. The formatter also rewrapped one test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
- A crystal gets the depth nodes its phase mismatch needs, not the slab's
  tied count, and its thickness is not fitted (as without dispersive).
- A session retrieval crossing in the principal plane runs check_tilt on
  the retrieved spectrum.
- The thickness uncertainty raises a clear error when dispersive
  propagation is off.
- An optmat without a built-in crystal's models raises a ValueError, which
  the GUI read-out shows.
- The GUI keeps the crystal's thickness, focal length and switch in step
  with the slab and the focal mixture, shows the slab alone before a trace
  is loaded, uses the same ranges for the shared settings, and shows an
  unknown stored setting as it is, with the read-out saying why.
- The Synthetic stage's note wraps to its column.
- Tests check that every solver receives the crystal and run a covariance
  through it; the docs give the smearing width as rms and FWHM, the tilt
  check, the defaults and the sources of the full-field figures.

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
crystal_tilt_error estimates what the first-order tilt model leaves out on
the part of the grid the pulse occupies (its live band, doubled), so it no
longer costs seconds on wide grids, and returns None where there is nothing
to check instead of raising after the retrieval. run_retrieval warns from
it unless check_tilt=False; the GUI worker turns that off, since capturing
warnings in a thread is unsafe, and sends the estimate to the Retrieve
stage as a notice. The per-solver test now checks that each solver's own
model trace is the crystal model's, which a solver ignoring the crystal
fails.

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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WM2AxPM9w8Mg7mfKikaeCX
@chrisbrahms chrisbrahms added enhancement New feature or request area: forward model Forward models, interactions, dispersion, smearing and collection labels Nov 17, 2026
@read-the-docs-community

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: forward model Forward models, interactions, dispersion, smearing and collection enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant