Repository navigation
Description
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:
SerializedMagnetscannot be iterated, indexed or measured (for m in fam,fam[0],len(fam)fail). The magnets
are only reachable throughfam.get_magnets(), which returns a plain list, not aMagnetArray.- 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 familyQF1Aas well as its magnetsQF1A-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 upholder.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.magnetsis a regularMagnetArray(named after the family). It supportsstrengths,hardwares, the set operations (+,&,|,-), selection by name/wildcard, and the aggregator inlive.fam.strengths.set(x)andfam.magnets.strengths.set(x)give the same PS current, because both use the series rule from Serialized magnets: implement the agreed accessor convention indesignandlive#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 memberRules:
- A literal name, a wildcard or a
re:pattern that resolves to a family is replaced by the family's magnets. ~FAMILYexcludes 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 amagnetsproperty (aMagnetArrayofget_magnets(), built lazily on the attached copy and cached). The family stays anElement.ElementHolder._fill_array: add an optionalexpand_func(name) -> list[Element] | Nonehook, 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.magnetsis aMagnetArray, andfam.magnets.strengths.get() == fam.strengths.get().
fam.magnets.strengths.set(x)andfam.strengths.set(x)give the same PS current.- A
pyaml.arrays.magnetwith[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*intests/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*.pystill 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.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
gupichon-soleil commentedon Nov 16, 2026
Change of approach after discussion: a family name in a
pyaml.arrays.magnetis not expanded into its magnets.SerializedMagnetsis now aMagnet. 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).len,fam[i],fam["name"],names(),magnets.pyaml.arrays.serialized_magnetbecomes deprecated, a magnet array now covers it.