Skip to content

Serialized magnets: a family behaves like a special magnet array #507

Description

@GamelinAl

Sub-issue 2 of #461. Builds on #473 (accessors), to be merged into 461-serializedmagnets (#481).

Problem

A serialized family is a group of magnets, but today it cannot be used as one:

  • SerializedMagnets cannot be iterated, indexed or measured (for m in fam, fam[0], len(fam) fail). The magnets
    are only reachable through fam.get_magnets(), which returns a plain list, not a MagnetArray.
  • A family name cannot be used in a pyaml.arrays.magnet:
    - type: pyaml.arrays.magnet
      name: QForTune
      elements: [S9, QF1*]      # -> PyAMLException: Magnet S9 not defined
  • a wildcard that matches a family name also fails. For example, QF1* matches the family QF1A as well as its magnets QF1A-C01, …. So wildcards cannot be used in magnet arrays as soon as a family name shares their prefix.
  • The only array that accepts family names is pyaml.arrays.serialized_magnet, which tuning tools do not accept (they look up holder.magnets.get(...)).

Expected behavior

1. The family behaves like a magnet array

fam = sr.live.serialized_magnet.get("S9")
len(fam)              # N
fam.names()           # ["S9-01", ..., "S9-16"], declaration order
fam[0], fam["S9-03"]  # one magnet (index or name)
for m in fam:         # the N individual (attached) magnets
    print(m.get_name(), m.strength.get())
fam.magnets           # MagnetArray of the N magnets (same mode)
fam.strengths.get()   # [k_1, ..., k_N]   (already in #473)
fam.hardwares.get()   # [I, ..., I]       (already in #473)
fam.strength.get()    # average strength  (unchanged, family-level value)
fam.hardware.get()    # I                 (unchanged)
  • fam.magnets is a regular MagnetArray (named after the family). It supports strengths, hardwares, the set operations (+, &, |, -), selection by name/wildcard, and the aggregator in live.
  • fam.strengths.set(x) and fam.magnets.strengths.set(x) give the same PS current, because both use the series rule from Serialized magnets: implement the agreed accessor convention in design and live #473.
  • Iterating a family that is not attached (the configuration object) yields the configured virtual magnets. Their accessors raise as usual.

2. Family names in pyaml.arrays.magnet

A family name in the elements of a pyaml.arrays.magnet stands for its magnets, in declaration order, at the place of the name:

- type: pyaml.arrays.magnet
  name: QForTune
  elements:
    - S9            # -> S9-01 ... S9-16
    - QD2*          # individual quads (and any family matched by the wildcard, expanded)
    - ~S9-05        # exclusion still works on a single member

Rules:

  • A literal name, a wildcard or a re: pattern that resolves to a family is replaced by the family's magnets.
  • ~FAMILY excludes all the magnets of that family.
  • A magnet reached several times only because of a family expansion is kept once, at its first position: the family plus one of its members listed explicitly, or a wildcard matching both the family and its members. An explicit duplicate that does not come from a family ([QF1A-C01, QF1A-C01]) still raises as today.
  • A combined-function magnet name keeps its current behavior. Only serialized families are expanded.

The array then holds ordinary magnets. Writing to it follows the array rule of #473: one PS write per series, using the average of the currents requested by the members present.

Implementation notes (light)

  • SerializedMagnets: add __iter__, __len__, __getitem__(int | slice | str), names() and a magnets property (a MagnetArray of get_magnets(), built lazily on the attached copy and cached). The family stays an Element.
  • ElementHolder._fill_array: add an optional expand_func(name) -> list[Element] | None hook, applied to both included and ~ excluded names. Then deduplicate the elements produced by an expansion. MagnetsHolder (pyaml/common/holders/sub_holders.py) passes a hook that returns family.get_magnets()when the name is in _SERIALIZED_MAGNETS`. Other holders are unchanged.
  • Docstrings: pyaml.arrays.magnet.Magnet (family names allowed), SerializedMagnets (iteration, magnets).

Acceptance criteria / tests

In design and live (dummy tango CS):

  • len(fam) == fam.get_nb_magnets(), fam.names() in declaration order, fam[i] / fam[name] return the attached magnet of that mode, list(fam) == fam.get_magnets().
  • fam.magnets is a MagnetArray, and fam.magnets.strengths.get() == fam.strengths.get().
    fam.magnets.strengths.set(x) and fam.strengths.set(x) give the same PS current.
  • A pyaml.arrays.magnet with [FAMILY] gives the N magnets in order. [FAMILY, ~MEMBER] gives N-1. [~FAMILY] and [*, ~FAMILY] exclude all its magnets.
  • [FAMILY, MEMBER] and a wildcard matching both a family and its members give each magnet once.
    [MEMBER, MEMBER] still raises.
  • A wildcard that matches a family name (e.g. QF1* in tests/config/sr_serialized_magnets.yaml) now loads.
  • An array mixing a family name with individually powered magnets writes the PS once (no 1/N). Setting x.set(x.get()) through it leaves the PS current unchanged.
  • The existing tests in tests/magnet/test_serialized_magnets*.py still pass.

Out of scope

  • One knob per power supply in tuning tools: grouping the members of a series into one knob, and variable_names (sub-issue 3).
    After this issue, a family name in a tuning-tool array still gives N columns. That is fixed in sub-issue 3.
  • Family names in runtime selections (sr.live.magnets["S9"], ElementArray.__getitem__): these select over the elements of an array, not over configuration names.
  • Removing or changing pyaml.arrays.serialized_magnet.

Activity

  1. added this to the ESRF Workshop milestone on Nov 4, 2026
  2. added
    enhancement
    on Nov 4, 2026
  3. gupichon-soleil commented on Nov 16, 2026

    @gupichon-soleil
    Contributor

    Change of approach after discussion: a family name in a pyaml.arrays.magnet is not expanded into its magnets.

    • SerializedMagnets is now a Magnet. In an array it counts as one element (average strength, power-supply current), and its magnets are not added.
    • [FAMILY, ~MEMBER] raises, since a series cannot be split (to be confirmed, @GamelinAl, @kparasch and others).
    • The family can still be iterated and indexed: len, fam[i], fam["name"], names(), magnets.
    • pyaml.arrays.serialized_magnet becomes deprecated, a magnet array now covers it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancement

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions