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.
get_devices() returns [self._cfg.powerconverter] (length 1).
get_strength_units() returns [self._cfg.unit] * self.__nbMagnets.
get_hardware_units() iterates over the instance's self.__sub_models, not _cfg.
SerializedMagnets.get_devices() delegates to self.model.get_devices().
compute_strengths([I]) accepts 1 current, returns N individual strengths via per-magnet calibration curves.
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
Bug:
LinearSerializedMagnetModelhas multiple broken methodsDescription
Four
AttributeErrorbugs inLinearSerializedMagnetModel— all methods that bridge the model to the control system are broken.get_devices(): wrong field name (plural vs singular):SerializedMagnets.get_devices(): accesses a non-existent attribute on the model:get_strength_units(): wrong field name:get_hardware_units():__sub_modelsbelongs to the instance, not to_cfg:Reproducer
Proposed fix
Align with the physical reality: one power converter feeds all magnets in series.
get_devices()returns[self._cfg.powerconverter](length 1).get_strength_units()returns[self._cfg.unit] * self.__nbMagnets.get_hardware_units()iterates over the instance'sself.__sub_models, not_cfg.SerializedMagnets.get_devices()delegates toself.model.get_devices().compute_strengths([I])accepts 1 current, returns N individual strengths via per-magnet calibration curves.compute_hardware_values([k1*l1, ..., kN*lN])accepts N strengths, returns 1 current.Files affected
pyaml/magnet/linear_serialized_model.pypyaml/magnet/serialized_magnet.pytests/test_serialized_magnets.py