Repository navigation
Bound legalization's raster resample and report it in moments - #61
Merged
Merged
Conversation
A raster resample changed the waveform under a warning that stated only its largest amplitude change. Over a stretch of raster-centre samples its area changes telescope to the two ends, so within the slew limit it moves the running k by at most raster^2 * max_slew / 4 at every instant, and m1 by at most twice the block's length times that. A resample measured beyond that bound, as a half-raster gradient summed with a trapezoid can be, is now refused. Each resample's warning states how far it moved k, m0 and m1, and an axis resampled in several blocks gets the net m0 and the summed magnitudes. A raster-centre run padded by zeros inside its block is emitted exactly with a delay when PyPulseq can store it. ADR-008 amends ADR-007's resampled-block clause. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Bounds legalization's raster resample, refuses a resample beyond the bound, and reports each one in k, m0 and m1. ADR-008 amends the resampled-block clause of ADR-007. ADR-007's per-block, two-stage comparison is unchanged, and no whole-sequence m1 check comes back.
Why
Legalization resamples a block-axis onto the gradient raster when no pulseq gradient can hold its knots. The usual case is a trapezoid summed with a gradient sampled at raster centres.
ADR-007 compares the emitted block with the tree resampled the same way. That checks the emission, but not the approximation. The approximation's only contract was a warning giving the largest amplitude change as a fraction of
max_grad. Measured onmain:oversampling=True) summed with a trapezoid.The contract (ADR-008)
m0 and k. Keeping only raster-edge values replaces each interval's centre-sample tent by its chord. Over a stretch of samples the change telescopes to the two ends:
Dis the sample step across each end. Within the slew limit, a stretch moves the running k by at mostr²·max_slew/4at every instant, whatever its duration. That is 0.160 1/m at 10 µs and 150 T/m/s.m1. By parts,
Δm1 = L·Δk(L) − ∫Δk dt, so|Δm1| ≤ 2·L·sup|Δk|. The guard is therefore on the running k at every instant, not on block m0. A half-raster input whose edges rise and then fall keeps block m0 within the bound (0.16 1/m) while k climbs 15.9 1/m and m1 moves by 0.016 s/m. An m0-only guard would accept it.Both closed forms and the identity were checked against measurement: equal to every printed digit for every raster-centre case, and the identity holds in every case, half-raster included.
Changes
_resampledmeasures the resample's running k exactly, on the union of knots and at zero crossings. It raisesCompileErrorabover²·max_slew/4per non-edge piece in the block. The only allowance is a relative 1e-9 for float rounding.resamplewarning keeps its amplitude figure and adds how far k moved against the bound, and the block's m0 and m1.resample_totalwarning, for an axis resampled in more than one block, gives the net m0 and the summed magnitudes of the k and m1 changes. There is no signed m1 total: block m1 values share no origin._as_arbitraryholds a raster-centre run padded by zeros inside its block exactly, as an arbitrary gradient with a delay. This applies only to runs of five samples or more: PyPulseq stores four or fewer 5 µs short, so those stay a bounded resample. That includes the case that prompted the review.docs/compiler.md,docs/api_reference.md, the CHANGELOG, and an "Amended by" line on ADR-007.Validation
tests/compiler/test_resample_bound.py.maintoo: the closed forms on a resampled sine stretch, a max-slew triangle reaching the bound, and a smooth half-raster sine compiling.main: the warning's moments, the net and summed totals, the half-raster refusal, the m0-cancelling refusal, the exact delayed split, and four samples staying a bounded resample.pulseq_systemsimport); slow tier 1; doctests 94; ruff, mypy, and the API-reference and prose checks.main: the 25 build notebooks (111 compiles) and 13 long trains (radial, spiral, rosette,EPI2D,ContinuousEPI2D) give the same verdicts and byte-identical emitted sequences.The review and the m1 derivation are in the workspace:
docs/plans/module-mining/compiler_findings/resample_bound/.🤖 Generated with Claude Code