Skip to content

Tuning tools: one knob per power supply #510

Closed as not planned
Closed as not planned

Description

@GamelinAl

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 in design and live #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_names for 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_names of the loaded matrix do not match the knob names of the array (names or order), the tool raises a PyAMLException on correct() / 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 without variable_names is only checked on its number of columns. At load time (post_init), a mismatch is only logged as a warning, so that Accelerator.load still works with a stale file.
  • A series mixing magnet functions (no family.strength, see Serialized magnets: implement the agreed accessor convention in design and live #473) cannot be a knob. The tool raises a clear PyAMLException naming the family.

Implementation proposal

  • New helper, for example pyaml/tuning_tools/knobs.py: KnobArray.from_magnets(holder, magnet_array). It maps each magnet whose model shares_power_supply() to its family (holder.serialized_magnet, via the model / model name set by SerializedMagnets.__create_virtual_magnet), and keeps the other magnets unchanged. It exposes names(), __iter__ and __len__ (each knob has get_name() and strength, which both Magnet and SerializedMagnets already provide), plus strengths.get()/set(). Build it per mode, at post_init, or lazily.
  • tune.py, tune_response_matrix.py, chromaticity.py, chromaticity_response_matrix.py: iterate and write knobs instead of self.quadrupoles / self.sextupoles. Keep the variable_names of the loaded ResponseMatrixData. Today only matrix is 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 make pyaml/external/pySC_interface.py get/set(name) resolve a family name to family.strength. Today it only looks in element_holder.magnet. The input_names check against the corrector arrays (orbit.py:384) uses knob names.
  • The quadrupoles / sextupoles / hcorrectors / vcorrectors properties keep returning the configured MagnetArray, and a new knobs property 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. In live, 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

Metadata

Metadata

Labels

bugenhancement

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions