Simulating a trace#

A configuration (pnps.setup.Config) describes the instrument and the run: the pulse, the beam, the mask, the slab, the collection windows and the numerical grids. pnps.setup.build_setup() turns it into the tables every delay point shares, none of them field-sized. A delay point then forms the delayed input, propagates it through the slab on solprop and reduces each save plane to the measured spectra; a scan does that for every delay and writes an HDF5 file.

One delay point, and a scan#

import numpy as np
from pnps import (
    Config,
    HE11Beam,
    WindowSpec,
    build_bridge,
    build_setup,
    run_delay_point,
    simulate_delay_point,
)

d = 1.0e-3  # boxcar hole-centre offset
cfg = Config(
    lam0=260e-9,
    tau_fwhm=1e-15,
    energy=0.1e-6,
    thickness=40e-6,
    mask_diam=1e-3,
    mask_spacing=1e-3,
    beam=HE11Beam(a=125e-6, f_coll=5.0, f_foc=0.1),
    windows=(WindowSpec(holex=-d, holey=-d, holediam=1e-3, zmask=0.1),),
    lam_lims=(143e-9, 600e-9),
    trange=250e-15,
    r_max=366e-6,
    n_transverse=768,
)
setup = build_setup(cfg)  # grids, input tables, absorber — once, nothing field-sized
zsave = np.array([0.0, 20e-6, 40e-6])
result = simulate_delay_point(setup, 0.0, zsave, h_target=0.5e-6)  # one point
result["i_omega_win"]  # (nz, n_windows, nt) spectra

with build_bridge(setup, zsave, 0.5e-6) as bridge:  # one engine, many points
    results = [run_delay_point(bridge, tau) for tau in (-2e-15, 0.0, 2e-15)]

The illuminating beam#

The beamlets are cut by the chromatic mask holes from one beam, whose far field is the same in transverse momentum at every frequency (one focal spot):

  • pnps.beams.HE11Beam — the HE11 output of a capillary of core radius a, collimated (f_coll) and refocused (f_foc): the default instrument;

  • pnps.beams.GaussianBeam — a Gaussian focus of 1/e² intensity radius w0 (f_foc sets the mask mapping). This is a Gaussian illumination of the same masked instrument, not three separate Gaussian beams tilted by one achromatic wavevector;

  • pnps.beams.UniformBeam — the ideal-instrument control: flat illumination, so each arm is exactly its hole as rendered.

Files record the beam as beam_model with its parameters (a, f_coll, w0, f_foc).

The beam layout#

Config.geometry chooses the layout (pnps.geometry):

  • "tg", the default: the four-hole transient-grating boxcar. Gate 1 at (+d, +d), gate 2 at (+d, -d) and the delayed test arm at (-d, +d), with d = (mask_spacing + mask_diam) / 2; the signal appears at (-d, -d).

  • "sd": self-diffraction. Two holes on the x axis, s = mask_spacing + mask_diam apart: the probe at (-s/2, 0) and the delayed gate at (+s/2, 0). The signal 2 k_E - k_G appears at (-3s/2, 0). The layout is symmetric about the axis, so that both beams are cut from the same part of the beam and carry the same energy; the signal is E² G*, so an imbalance would not cancel.

Place the windows where the signal appears, pnps.geometry.signal_centre():

from pnps import WindowSpec, signal_centre

x, y = signal_centre("sd", mask_diam=1e-3, mask_spacing=1e-3)  # (-3e-3, 0.0)
windows = (WindowSpec(holex=x, holey=y, holediam=1e-3, zmask=0.1),)

i_omega_full sums the layout’s signal region, so Iω_win / Iω_full stays the collection efficiency. For TG it is the quadrant kx, ky < 0. For SD it is the half-plane beyond the bisector between the signal and the probe (mask-plane x < -s), which moves with frequency, and which only light able to leave the slab into air reaches. solprop’s statistics express it as a half-plane of the mask, so a self-diffraction run reduces on the device like a TG one (The propagation engine: solprop). pnps.grids.optimal_spatial_grid() takes the layout too. The signal’s outer edge, 3s/2 + mask_diam/2, bounds the momentum span, which is less than the boxcar asks for. Files record geometry and the signal centre (signal_x, signal_y).

simulate_delay_point builds the solprop engine for one delay point and releases it; to run several, build a bridge once (pnps.bridge.build_bridge()) and call pnps.simulate.run_delay_point() for each. Delays run one at a time. Full scans go through pnps.scan.run_scan(), which does exactly that and writes the HDF5 file with per-point resume.

The output file#

<scan_name>_collected.h5, in the scan-file layout the Croak retrieval package reads (h5py sees (N_tau, nz, N_omega); a column-major reader sees (N_omega, nz, N_tau) — the same bytes). Croak reads it unchanged: tests/test_croak.py runs Croak’s readers and its retrieval loader on a file this package writes. The file holds:

  • /scanvariables/τ — the delay axis;

  • /Iω_win, /Iω_win_reimaged, /Iω_win_2, … — one pair per collection window (first window unsuffixed);

  • /Iω_full — the un-windowed spectrum of the signal region (pnps.geometry.signal_region()); Iω_win / Iω_full is the exact per-frequency collection efficiency;

  • /Iω_beam — the whole beam’s spectrum, every column, per plane;

  • /Iω_lap_lost — per delay, the energy per frequency bin the lap budget removed over the slab (read back as SimulatedScan.lap_lost);

  • /grid/* — axes and conventions (ω FFT-ordered absolute, delay_convention = "gate"), the input truth (Eω_re/_im), the vignetted-beamlet truth (below), window definitions including window_def*_weighting (the collected windows: hard discs on the nonlinear field with exact windows, recorded by exact_windows and window_field, with the configured rendering as window_def*_configured_*; see Masks and collection windows), delivered_energy (the post-hole energy of all the arms, which is grid-dependent and so belongs in the file), and the numerical parameters of the run, including the engine’s provenance (pnps.io_h5.ENGINE_KEYS: the solprop backend and version, the stepper, the kernel schema and how the operator was pinned; see The propagation engine: solprop). A run with an injected input pulse adds that field’s provenance (Input pulses).

Spectra are in the state’s unnormalised-FFT units: at fixed physical extent they scale as the fourth power of the transverse sample count (Iω_win_reimaged, a real-space on-axis sample, is grid-invariant).

The time-domain truth is written alongside the spectral truth, on the native axis (t, It*) and an 8x oversampled one (To, Ito*): Ito = OVERSAMPLE**2 * |ifft(zero-padded E)|**2, so It and Ito share one intensity scale.

The beamlet truth#

The retrievable ground truth — one arm’s pulse after the input hole has vignetted it — is recorded twice, because the two trace observables measure different things:

  • Iω_beamlet, Eω_beamlet_re/_im: k-integrated. Compare against Iω_win.

  • Iω_beamlet_reimaged, Eω_beamlet_reimaged_re/_im (and It_beamlet_reimaged/Ito_beamlet_reimaged): the on-axis focal amplitude. Compare against Iω_win_reimaged.

It_beamlet keeps its established k-integrated meaning so that no recorded dataset silently changes definition; the on-axis frame is offered beside it under the _reimaged names. Which one a retrieval should consume is the open question, not a naming choice.

These are not proportional. The focal spot area goes as \(\omega^{-2}\), so their ratio sweeps a factor of about seven across a 160–425 nm band. Comparing a re-imaged trace against the k-integrated truth therefore imposes a large spurious spectral tilt on the retrieval residual.

Both are recorded in the state’s arbitrary units — they are momentum-space sums whose normalisation depends on the transverse sample count, so only their shape is meaningful. That shape is invariant to the sample count to machine precision (it is fixed by the momentum resolution, hence by r_max, not by n_transverse), and is within about 1e-3 of the exact hard-hole vignetting.

The hole is a real amplitude filter and the illumination profile is real, so a beamlet’s spectral phase is exactly the input phase; only the amplitude is vignetted. pnps.io_h5.beamlet_truth() builds the complex spectrum on that basis, and zeroes both the power and the complex array in the deep wings where the input phase is not defined, so abs(Eω_beamlet)**2 == Iω_beamlet holds everywhere in the file.

Reading a scan back#

pnps.io_h5.load_simulated_scan() reads a scan file into a pnps.io_h5.SimulatedScan: the trace with the frequency axis in ascending order, the delay axis and the save positions, the input and beamlet truths, and every scalar of /grid as metadata.

from pnps.io_h5 import load_simulated_scan

scan = load_simulated_scan("tiny_collected.h5")  # first window, last plane
full = load_simulated_scan("tiny_collected.h5", "Iω_full")  # the whole signal region
efficiency = scan.trace / full.trace  # per-frequency collection
thin = load_simulated_scan("tiny_collected.h5", z_thickness=10e-6)  # nearest plane
every = load_simulated_scan("tiny_collected.h5", z_index="all")  # (n_tau, n_z, n_omega)

Sizing jobs#

Memory, not compute, is what limits the grid: one field volume is 16 n^2 nt bytes (5.3 GiB at n_transverse = 768, nt = 600), and a run peaks at about five of them with the default stepper. pnps.memory.memory_budget() gives a configuration’s budget before it is launched, building the backend to read its ledger, so run it where the job will run; The propagation engine: solprop gives the parts and Performance the measured costs. The setup itself is never field-sized, so a configuration can be built and inspected on any machine.

Choosing the numerical parameters#

  • trange: pnps.absorber.required_trange() is the shortest window that absorbs nothing in the band (3 time_headroom plus the band’s largest walk-off; see The physical and numerical model), and building a configuration with a shorter one logs the band it leaves untouched. To see what a shorter window costs, read the lap budget’s loss per band from the file:

    from pnps.absorber import lap_loss_share
    
    beam = load_simulated_scan("run_collected.h5", "Iω_beam")  # the last plane
    share = lap_loss_share(beam.lap_lost, beam.trace, beam.omega, (143e-9, 160e-9))
    
  • time_headroom: protected half-width around \(t=0\). Delays within 75% of it are always admitted; a longer delay is admitted when light that wraps the window cannot act at it, which pnps.absorber.wrap_coupling() bounds (The physical and numerical model, “Which delays the window holds”). On the production window that is 96 fs for the 1 fs pulse, and a pulse with a long wing needs more headroom: each femtosecond of it admits about 2 fs more delay.

  • h_target: the largest step of the replayed schedule; certify it with examples/calibrate_production.py / pnps.calibrate on your exact configuration (Accuracy: control, verification, and limits).

  • stepper: "rk4ip" (the default), solprop’s low-storage interaction-picture RK4, fourth order, about four field volumes; or "dopri5", the Dormand–Prince 5(4) pair replayed on the same fixed schedule, fifth order, about fifteen.

  • backend: a solprop registry name ("auto" prefers "native"); see The propagation engine: solprop.

  • geometry: "tg" (the default) or "sd"; see The beam layout above.

  • absorption: keep the material loss of optmat’s silica index (off by default: a lossless slab with optmat’s real index); recorded as absorption. The silica is always optmat’s, with the n2 of its silica bundle at the carrier (extrapolated below 350 nm), recorded as index_model, kerr_model, n2 and n2_extrapolated; see The physical and numerical model.

  • raman: the delayed Raman response of fused silica (off by default), with the bundle’s \(f_R = 0.2188\); recorded as raman, raman_fraction and raman_model. It costs about 40 % more time per step (145 against 204 ms at 192 x 192 x 300 on the native CPU backend, Apple M5 Max).

  • node_budget: solprop’s per-chunk memory budget, default 1 GiB.

  • edge_diagnostic: compute the time-window edge fraction per save (off by default; NaN in the results otherwise).

  • reduction: "auto" (default) takes solprop’s far-field statistics when solprop accepts the windows without a warning, and the host reduction otherwise; "host" reduces each saved field here; "solprop" keeps no field and reads solprop’s statistics (on every backend); see The propagation engine: solprop.

  • r_max, n_transverse: pnps.grids.optimal_spatial_grid() gives the sizing rule; verify with a one-off larger-grid run.