Repository navigation
Closed
Labels
Description
If you try to access a magnet configured in IdentyModel with hardware only from the design , it ends in in infinite loop due to recursive error printing.
It should print something like:
pyaml.common.exception.PyAMLException: CH1 has no model that supports hardware units
How to reproduce:
simple_hmag.yaml
class: pyaml.accelerator.Accelerator
facility: ESRF
machine: SR
data_folder: null
energy: 6e9
simulators:
- class: pyaml.lattice.simulator.Simulator
lattice: 'config/sr/lattices/ebs.mat'
name: design
devices:
- class: pyaml.magnet.hcorrector.HCorrector
name: CH1
model:
class: pyaml.magnet.identity_model.IdentityMagnetModel
unit: A
powerconverter: my/device/exmaple/1from pyaml.accelerator import Accelerator
sr = Accelerator.load("simple_hmag.yaml")
print(sr.design.magnet.get("CH1").hardware.get())Proposed fix:
diff --git a/pyaml/magnet/magnet.py b/pyaml/magnet/magnet.py
index b01491d7..fd5a4a09 100644
--- a/pyaml/magnet/magnet.py
+++ b/pyaml/magnet/magnet.py
@@ -83,7 +83,7 @@ class Magnet(Element):
"""
self.check_peer()
if self.__strength is None:
- raise PyAMLException(f"{str(self)} has no model that supports physics units")
+ raise PyAMLException(f"{self.name} has no model that supports physics units")
return self.__strength
@property
@@ -94,7 +94,7 @@ class Magnet(Element):
"""
self.check_peer()
if self.__hardware is None:
- raise PyAMLException(f"{str(self)} has no model that supports hardware units")
+ raise PyAMLException(f"{self.name} has no model that supports hardware units")
return self.__hardware
@property
Activity
Merge pull request #498 from python-accelerator-middle-layer/fix-475
Fix recursive formatting in missing magnet model errors (#475)