Repository navigation
Description
Sub-issue 3 of #461. Builds on #473 (accessors) and sub-issue 2 (family names in pyaml.arrays.magnet). To be merged into 461-serializedmagnets (#481).
Problem
Tuning tools treat every magnet of their array as an independent knob. A serialized family has only one degree of freedom (its power supply), so when several magnets of a series are in the array, the result is wrong:
- Measurement (
tune_response_matrix,chromaticity_response_matrix,orbit_response_matrix): stepping one magnet of the series moves the whole series. Each of the N columns is then the response of the full family, so the matrix has N identical columns. - Correction (
tune,chromaticity,orbit): the pseudo-inverse treats those N columns as independent knobs and gives each one 1/N of the family correction. The N requests are identical, so the array write (Serialized magnets: implement the agreed accessor convention indesignandlive#473) sets the PS to their average, and the series moves by only 1/N of what is needed.
Tune correction example (measure the TRM, then tune.add([0.01, 0.005])):
| Setup | Today | Expected |
|---|---|---|
| 8 individually powered quads | ✔ | ✔ |
| Series listed as 4 magnets + 4 individual quads | ✘ (moves 1/N) | ✔ (same as the next two rows) |
| 1 magnet of the series + 4 individual quads | ✔ | ✔ |
| Family name + 4 individual quads | ✘ (N columns, after sub-issue 2) | ✔ |
Expected behavior
Before measuring or correcting, a tool turns its input magnet array into a list of knobs, one per independent power supply:
- an individually powered magnet is one knob,
- a serialized family is one knob, the family, driven through
family.strength(average strength). It does not matter how it was listed: one of its magnets, several, all of them, or the family name (sub-issue 2) all give the same knob, - each virtual magnet of a combined-function magnet stays its own knob (as today).
Knobs keep the order of first appearance in the array. The configuration does not change:
- type: pyaml.tuning_tools.tune
name: DEFAULT_TUNE_CORRECTION
quad_array_name: QForTune # any mix of individual magnets, series members or family names
betatron_tune_name: BETATRON_TUNE
response_matrix: ${path:trm.json}Visible effects:
- Response matrices have one column per knob. A series appears under its family name in
variable_names(input_namesfor the ORM). Its column is the response to the average strength of the family. - Callbacks report the knob name (
"magnet": "S9"for a series). - Corrections write one value per knob:
family.strength.set(...)for a series,magnet.strength.set(...)otherwise. So a series is written once, with the full correction. - Consistency check: when the
variable_namesof the loaded matrix do not match the knob names of the array (names or order), the tool raises aPyAMLExceptiononcorrect()/add()/set()and asks for a new measurement. For example, an old matrix with one column per magnet of a series fails this check. A matrix withoutvariable_namesis only checked on its number of columns. At load time (post_init), a mismatch is only logged as a warning, so thatAccelerator.loadstill works with a stale file. - A series mixing magnet functions (no
family.strength, see Serialized magnets: implement the agreed accessor convention indesignandlive#473) cannot be a knob. The tool raises a clearPyAMLExceptionnaming the family.
Implementation proposal
- New helper, for example
pyaml/tuning_tools/knobs.py:KnobArray.from_magnets(holder, magnet_array). It maps each magnet whose modelshares_power_supply()to its family (holder.serialized_magnet, via the model / model name set bySerializedMagnets.__create_virtual_magnet), and keeps the other magnets unchanged. It exposesnames(),__iter__and__len__(each knob hasget_name()andstrength, which bothMagnetandSerializedMagnetsalready provide), plusstrengths.get()/set(). Build it per mode, atpost_init, or lazily. tune.py,tune_response_matrix.py,chromaticity.py,chromaticity_response_matrix.py: iterate and write knobs instead ofself.quadrupoles/self.sextupoles. Keep thevariable_namesof the loadedResponseMatrixData. Today onlymatrixis kept. Use them for the check.orbit.py,orbit_response_matrix.py: build the corrector knobs the same way (H and V), pass the knob names to pySC, and makepyaml/external/pySC_interface.pyget/set(name)resolve a family name tofamily.strength. Today it only looks inelement_holder.magnet. Theinput_namescheck against the corrector arrays (orbit.py:384) uses knob names.- The
quadrupoles/sextupoles/hcorrectors/vcorrectorsproperties keep returning the configuredMagnetArray, and a newknobsproperty exposes the grouped view.
Acceptance criteria / tests
Knob grouping (unit, design and live with the dummy tango CS):
- An array of 4 individual quads + K members of a series gives 5 knobs, for every K in 1..N and for the family name. The family knob is named after the family and sits at the position of the first member.
- Two series in one array give two knobs. A CFM gives one knob per virtual magnet.
knobs.strengths.set(knobs.strengths.get())leaves every PS unchanged. Inlive, a series PS is written once.- A mixed-function series in a tuning-tool array raises a clear error.
Tune: reproduce the table above (design, EBS lattice, new config with one series of 4 quads + 4 individually powered quads):
- For each of the 4 setups, measure the TRM, then call
tune.add([0.01, 0.005]). The achieved ΔQ equals the target (tolerance about 1e-4, linear regime). - The setups "4 members", "1 member" and "family name" give the same
variable_names, the same matrix and the same PS current after correction. - A regression check for today's bug: with 4 members, the series moves by the full correction, not 1/N.
Chromaticity: the same check for one series of sextupoles + individual sextupoles, at least for the setups "all members" vs "family name".
Orbit: one corrector series in the H corrector array. The ORM has one input_names entry for the family, and an orbit correction writes its PS once. Correctors that are not in series behave exactly as before (existing orbit tests unchanged).
Consistency check: loading a TRM with one column per series member (or with names in another order) raises on add() with a message asking for a new measurement. A matrix that matches is accepted.
Existing tuning-tool tests and tests/integration/test_dt4acc_twin_smoke.py (no series) still pass unchanged.
Out of scope
- BBA (
bba.py,bba2.py) and dispersion: they step a single magnet. For a quad in series, the whole series moves. - A series of combined-function magnets (one PS shared by several CFMs, see "Known limitations" in SerializedMagnets:
get/setare not consitent anddesign/livedisagree #461). - A CFM with more multipoles than power supplies (stays a least-squares compromise).
Activity
get/setare not consitent anddesign/livedisagree #461get/setare not consitent anddesign/livedisagree #461get/setare not consitent anddesign/livedisagree #461designandlive#473gupichon-soleil commentedon Nov 19, 2026
@GamelinAl, shall we close the issue?