Skip to content

Serialized magnets: consistent accessors in design and live, family used as a single magnet in arrays - #481

Merged
GamelinAl merged 14 commits into
mainfrom
461-serializedmagnets
Nov 25, 2026
Merged

GamelinAl merged 14 commits into
mainfrom
461-serializedmagnets

Conversation

@gupichon-soleil

@gupichon-soleil gupichon-soleil commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A serialized family (N magnets on one power supply) has a single degree of freedom, the power supply current I. This PR makes every accessor follow that rule, with the same behaviour in design and live, and turns the family into a special Magnet that magnet arrays hold as one element.

Closes #461, #473, #507

Accessor convention (#461, #473)

  • family.hardware reads and writes I (it used to return N x I).
  • family.strength reads the mean strength sum(f_i(I)) / N and writes the I that gives it.
  • magnet[i].strength writes I = f_i^-1(x) with that magnet's own submodel. The other magnets of the series follow.
  • design no longer splits a value by magnet length.
  • Combined-function magnets keep their current behaviour. The strength aggregator now calls MagnetModel.compute_hardware_values_partial(), whose default is the previous logic, and LinearSerializedMagnetModel overrides it.

Inverse of the excitation curves

  • The current is found as the zero of a normalized residual on the piecewise-linear curves, so it is the exact inverse when all requested strengths agree.
  • When the requested strengths cannot all be reached with one current, the result is a compromise and a warning is logged.
  • When the solution is outside the current range shared by all the curves, the current is clamped to the end of that range and a warning is logged.

Arrays (#507)

  • SerializedMagnets derives from Magnet. A magnet array that holds a family contains the family as one element, its members are never expanded.
  • Wildcards that only match the members of a family do not add them twice.
  • A family and one of its own magnets in the same array raise an error, in every mode.
  • An array write gives the power supply the mean of the currents asked by the series members present in the array, not by all N. Writing one member no longer moves the power supply by 1/N. Design arrays apply the same rule as live.
  • pyaml.arrays.serialized_magnet is deprecated.

Other fixes

  • The serialized submodels are built once, at configuration. Attaching a family used to rebuild them, so the per-magnet accessors kept stale submodels that never received the magnetic rigidity.
  • SerializedMagnetsArray.unit() no longer splits unit strings into characters.
  • ReadWriteSerializedStrengths.elements / get_elements() are removed, use SerializedMagnets.get_magnets().

Tests

  • New design and live tests for idempotence, family values, per-magnet writes, design/live parity, array writes, curve clamping and the family-as-magnet behaviour (tests/magnet/test_serialized_family_as_magnet.py, test_serialized_magnets_cs.py, test_serialized_magnets_expected_behaviour.py).
  • New configuration tests/config/sr_serialized_magnets_range.yaml for curves with different current ranges.
  • Tests that relied on the sum and length-sharing convention are updated.

🤖 Generated with Claude Code

JeanLucPons
JeanLucPons previously approved these changes Oct 15, 2026
GamelinAl and others added 10 commits November 18, 2026 18:13
A serialized family (N magnets on one power supply) has a single degree
of freedom, the PS current I. The accessors now follow that in design
and live:

- family.hardware returns I (was N x I) and sets I.
- family.strength returns the average strength sum(f_i(I))/N and sets
  the I that gives it (exact inverse of the piecewise-linear curves).
- magnet[i].strength sets I = f_i^-1(x) with the magnet's own submodel;
  the other magnets follow. Design no longer splits the value by length.
- Array writes give the PS the mean of the currents asked by the series
  members present in the array, not by all N, so writing one member no
  longer moves the PS by 1/N. Inconsistent requests log a warning.
  Design arrays (no aggregator) apply the same rule as live.

Combined-function magnets keep their current behaviour: the strength
aggregator now calls MagnetModel.compute_hardware_values_partial(),
whose default is the previous logic; LinearSerializedMagnetModel
overrides it.

Also:
- Build the serialized submodels once, at configuration. Attaching a
  family used to rebuild them, so the per-magnet accessors kept stale
  submodels that never received the magnetic rigidity.
- SerializedMagnetsArray.unit() no longer splits unit strings into
  characters.
- Remove ReadWriteSerializedStrengths.elements / get_elements(); use
  SerializedMagnets.get_magnets().

Tests: new design/live tests for idempotence, family values, per-magnet
writes, design/live parity and array writes; tests that relied on the
sum and length-sharing convention are updated.

Refs #461

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d completed partial requests for serialized magnets (#461)
… strength is clamped to the excitation curve
… strength is clamped to the excitation curve
SerializedMagnets derives from Magnet, its members are not added to an array that holds it, pyaml.arrays.serialized_magnet is deprecated.
@gupichon-soleil gupichon-soleil changed the title 461 serializedmagnets Serialized magnets: consistent accessors in design and live, family used as a single magnet in arrays Nov 19, 2026
@gupichon-soleil

Copy link
Copy Markdown
Contributor Author

It looks like this PR is ready for review.

@gupichon-soleil
gupichon-soleil marked this pull request as ready for review November 19, 2026 09:42
@GamelinAl

GamelinAl commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Tests with the SOLEIL configuration on design mode seem to run fine, I'll also test on the real machine on the 30/11.

I only found one issue when writing an array holding two magnets of the same series, with arr a MagnetArray like [QF1A-C05, QF1A-C06]:

design: family.hardwares.set([10, 20, 10, 20]) -> PS = 15.0
design: arr.strengths.set(k(10 A), k(20 A))    -> PS = 15.00056
design: arr.hardwares.set([10, 20])            -> PS = 20.0  # last write wins

@gupichon-soleil

Copy link
Copy Markdown
Contributor Author

Tests with the SOLEIL configuration on design mode seem to run fine, I'll also test on the real machine on the 30/11.

I only found one issue when writing an array holding two magnets of the same series, with arr a MagnetArray like [QF1A-C05, QF1A-C06]:

design: family.hardwares.set([10, 20, 10, 20]) -> PS = 15.0
design: arr.strengths.set(k(10 A), k(20 A))    -> PS = 15.00056
design: arr.hardwares.set([10, 20])            -> PS = 20.0  # last write wins

I'm on it. It's not as easy as I first thought. I'm creating a new PR for this.

The power supply gets the average of the values of the magnets of the series present in the array, in design and live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gupichon-soleil and others added 2 commits November 23, 2026 10:44
Applies to strengths and hardwares, in design and live, before anything is written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alized-array-hardwares

Serialized magnets: write the power supply once from array hardware values
@GamelinAl

Copy link
Copy Markdown
Member

I made a very small change to have the same error behaviour for family.strengths.set() and family.hardwares.set() but otherwise I think it's good to go.

family.strengths.set() with a single number crashed with a bare
TypeError. It now raises a PyAMLException before anything is written
unless it gets one value per magnet, as family.hardwares.set() already
does.

Also fix the Returns underline in the MagnetModel.shares_power_supply
docstring.

Refs #461

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gupichon-soleil

Copy link
Copy Markdown
Contributor Author

At last !

@gupichon-soleil

Copy link
Copy Markdown
Contributor Author

@kparasch, I think we should wait for your PRs to be merged, and then we'll be good to go.
Also, a rebase will be necessary.

@kparasch

Copy link
Copy Markdown
Member

@kparasch, I think we should wait for your PRs to be merged, and then we'll be good to go. Also, a rebase will be necessary.

@gupichon-soleil I don't think we need to wait for them. PR #518 can be merged but since a rebase is anyway needed I can just rebase to main after this is merged as it is quite independent.

PR #521 can wait until I have completed the specialization of SerializedMagnets, which still needs work.

@GamelinAl

Copy link
Copy Markdown
Member

Great, then let's merge this.

@GamelinAl
GamelinAl merged commit 29218af into main Nov 25, 2026
4 checks passed
GamelinAl added a commit that referenced this pull request Nov 25, 2026
Resolve the conflicts with the serialized-magnet rework (#481, #516):
- Keep main's serialized family accessors and apply the SI unit conventions
  to them: a single unit when values share it, the standard unit() docstring,
  control_system_unit() on hardware accessors. The family average strength
  reports its pyAML unit, since no device holds it.
- Build the CSHardwareScalarAggregator with SI device access and give it
  per-magnet unit() and control_system_unit(): the inherited ones listed one
  unit per power supply.
- Take main's deprecated SerializedMagnetsArray, which now relies on the unit
  handling of MagnetArray.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants