Latest Results
Python: `set()` Checks on Copies, Then Writes
Review follow-up, now that #1381 is in.
`set()` promises all-or-nothing, and before #1381 the only way to keep that
promise was to write and undo: `_SET_VALIDATORS` pre-checked `nslice`,
`int_order` and `mapsteps` in Python, a copy of the C++ rules, and any other
rejection (`DipEdge.R`, element-dependent array lengths) was caught by rolling
back a journal. Checking on throwaway elements first was ruled out, because
constructing one allocated a `GPUDataRegistry` entry that was never freed.
#1381 removed that registry and added `Element.copy(**overrides)`, so `set()`
is now two passes: every write is made on copies, and only once all of them
succeed on the elements themselves. The element's own setter decides what is
valid, with no second list of rules in Python, and nothing half-written is ever
visible to user code in between. A rejection gets a note naming the property,
value and element, since the element's message need not name the property.
Each step of the check is a copy with a single override, so it is the same
assignment in the same order as the write that follows. A pair of parameters
that can only change length together is therefore rejected up front rather than
passing the check and failing half way through the write. `copy()` refuses the
Twiss settings a `BeamMonitor` keeps by name, which trying on a copy would
change on the original, so `set()` refuses them too.
With the lattice holding the elements themselves, an element may sit at several
positions: it is written and counted once. Writes go to the elements taken at
the start, so user code run during `set()` cannot redirect them by moving
elements. The `Programmable` concern from review is gone with the copies, and
is covered by a test.
Also brings the docs in line with the lattice after #1381: `delete()` no longer
rebuilds the lattice from clones, and `set()` joins the how-to.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Latest Branches
0%
0%
0%
cemitch99:user_specified_wake © 2026 CodSpeed Technology