Skip to content

BugFix: get_devices() broken for serialized magnets #253

@gupichon

Description

@gupichon

Bug: LinearSerializedMagnetModel has multiple broken methods

Description

Four AttributeError bugs in LinearSerializedMagnetModel — all methods that bridge the model to the control system are broken.

get_devices(): wrong field name (plural vs singular):

return self._cfg.powerconverters  # AttributeError: field is `powerconverter` (singular)

SerializedMagnets.get_devices(): accesses a non-existent attribute on the model:

if isinstance(self.model.powerconverter, list):  # AttributeError: no such attribute on LinearSerializedMagnetModel

get_strength_units(): wrong field name:

return self._cfg.units  # AttributeError: field is `unit` (singular)

get_hardware_units(): __sub_models belongs to the instance, not to _cfg:

return [p.unit() for p in self._cfg.__sub_models]  # AttributeError: no such attribute on ConfigModel

Reproducer

from pyaml.accelerator import Accelerator

acc = Accelerator.load("tests/config/sr_serialized_magnets.yaml", use_fast_loader=True, ignore_external=True)
sm = acc.design.get_serialized_magnet("QF1A")

sm.get_devices()         # AttributeError: 'LinearSerializedMagnetModel' object has no attribute 'powerconverter'
sm.model.get_strength_units()  # AttributeError: 'ConfigModel' object has no attribute 'units'
sm.model.get_hardware_units()  # AttributeError: 'ConfigModel' object has no attribute '_LinearSerializedMagnetModel__sub_models'

Proposed fix

Align with the physical reality: one power converter feeds all magnets in series.

  1. get_devices() returns [self._cfg.powerconverter] (length 1).
  2. get_strength_units() returns [self._cfg.unit] * self.__nbMagnets.
  3. get_hardware_units() iterates over the instance's self.__sub_models, not _cfg.
  4. SerializedMagnets.get_devices() delegates to self.model.get_devices().
  5. compute_strengths([I]) accepts 1 current, returns N individual strengths via per-magnet calibration curves.
  6. compute_hardware_values([k1*l1, ..., kN*lN]) accepts N strengths, returns 1 current.

Files affected

  • pyaml/magnet/linear_serialized_model.py
  • pyaml/magnet/serialized_magnet.py
  • tests/test_serialized_magnets.py

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions