From 3a8f87a99bb9f20034debcbe82a128a0971029cc Mon Sep 17 00:00:00 2001 From: guillaumepichon Date: Tue, 21 Oct 2025 15:42:04 +0200 Subject: [PATCH] Correction of the usage of powerconverters attribute and new tests. --- pyaml/magnet/identity_cfm_model.py | 6 +-- tests/config/sr-ident-cfm.yaml | 29 ++++++++++++ tests/config/sr/correctors/SH1AC01-ident.yaml | 11 +++++ .../sr/magnet_models/SH1AC01-ident.yaml | 13 +++++ tests/test_ident_models.py | 47 +++++++++++++++++++ 5 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 tests/config/sr-ident-cfm.yaml create mode 100644 tests/config/sr/correctors/SH1AC01-ident.yaml create mode 100644 tests/config/sr/magnet_models/SH1AC01-ident.yaml create mode 100644 tests/test_ident_models.py diff --git a/pyaml/magnet/identity_cfm_model.py b/pyaml/magnet/identity_cfm_model.py index 7328f4b2..a1afa417 100644 --- a/pyaml/magnet/identity_cfm_model.py +++ b/pyaml/magnet/identity_cfm_model.py @@ -33,14 +33,14 @@ def __init__(self, cfg: ConfigModel): # Check config self.__nbFunction: int = len(cfg.multipoles) - if cfg.physics is None and cfg.powerconverter is None: + if cfg.physics is None and cfg.powerconverters is None: raise Exception("Invalid IdentityCFMagnetModel configuration, physics or powerconverters device required") - if cfg.physics is not None and cfg.powerconverter is not None: + if cfg.physics is not None and cfg.powerconverters is not None: raise Exception("Invalid IdentityCFMagnetModel configuration, physics or powerconverters device required but not both") if cfg.physics: self.__devices = cfg.physics else: - self.__devices = cfg.powerconverter + self.__devices = cfg.powerconverters self.__nbDev: int = len(self.__devices) diff --git a/tests/config/sr-ident-cfm.yaml b/tests/config/sr-ident-cfm.yaml new file mode 100644 index 00000000..261a5524 --- /dev/null +++ b/tests/config/sr-ident-cfm.yaml @@ -0,0 +1,29 @@ +type: pyaml.pyaml +instruments: + - type: pyaml.instrument + name: sr + energy: 6e9 + simulators: + - type: pyaml.lattice.simulator + lattice: sr/lattices/ebs.mat + name: design + controls: + - type: tango.pyaml.controlsystem + tango_host: ebs-simu-3:10000 + name: live + data_folder: /data/store + arrays: + - type: pyaml.arrays.magnet + name: HCORR + elements: + - SH1A-C01-H + - SH1A-C02-H + - type: pyaml.arrays.magnet + name: VCORR + elements: + - SH1A-C01-V + - SH1A-C02-V + devices: + - sr/quadrupoles/QF1AC01.yaml + - sr/correctors/SH1AC01-ident.yaml + - sr/correctors/SH1AC02.yaml \ No newline at end of file diff --git a/tests/config/sr/correctors/SH1AC01-ident.yaml b/tests/config/sr/correctors/SH1AC01-ident.yaml new file mode 100644 index 00000000..7e9ae2ad --- /dev/null +++ b/tests/config/sr/correctors/SH1AC01-ident.yaml @@ -0,0 +1,11 @@ +type: pyaml.magnet.cfm_magnet +name: SH1A-C01 #Name of the element in the lattice model +mapping: + # Multipole mapping for usage in families, in this example SH1-C01A-H is not + # a lattice element present in the model, it is just a name to use in + # PyAML families. When this 'virutal' element is set, it then applies + # the corresponding multipole on the parent element. + - [B0, SH1A-C01-H] + - [A0, SH1A-C01-V] + - [A1, SH1A-C01-SQ] +model: sr/magnet_models/SH1AC01-ident.yaml diff --git a/tests/config/sr/magnet_models/SH1AC01-ident.yaml b/tests/config/sr/magnet_models/SH1AC01-ident.yaml new file mode 100644 index 00000000..206754b8 --- /dev/null +++ b/tests/config/sr/magnet_models/SH1AC01-ident.yaml @@ -0,0 +1,13 @@ + type: pyaml.magnet.identity_cfm_model + multipoles: [B0,A0,A1] + units: [rad,rad,m-1] + physics: + - type: tango.pyaml.attribute + attribute: srmag/ps-corr-sh1/c01-a-ch1/strength + unit: rad + - type: tango.pyaml.attribute + attribute: srmag/ps-corr-sh1/c01-a-ch2/strength + unit: rad + - type: tango.pyaml.attribute + attribute: srmag/ps-corr-sh1/c01-a-ch3/strength + unit: m-1 diff --git a/tests/test_ident_models.py b/tests/test_ident_models.py new file mode 100644 index 00000000..272ca2f0 --- /dev/null +++ b/tests/test_ident_models.py @@ -0,0 +1,47 @@ +import pytest + +from pyaml.magnet.cfm_magnet import CombinedFunctionMagnet +from pyaml.magnet.hcorrector import HCorrector +from pyaml.magnet.vcorrector import VCorrector +from pyaml.pyaml import pyaml,PyAML +from pyaml.configuration.factory import Factory +from pyaml.instrument import Instrument +from pyaml.magnet.model import MagnetModel +import numpy as np + +@pytest.mark.parametrize( + ("magnet_file", "install_test_package"), + [ + ("tests/config/sr-ident-cfm.yaml", {"name": "tango", "path": "tests/dummy_cs/tango"}), + ], + indirect=["install_test_package"], +) +def test_cfm_magnets(magnet_file, install_test_package): + + ml:PyAML = pyaml(magnet_file) + sr:Instrument = ml.get('sr') + sr.design.get_lattice().disable_6d() + magnet_design = sr.design.get_magnet("SH1A-C01") + magnet_live = sr.live.get_magnet("SH1A-C01") + assert isinstance(magnet_design, CombinedFunctionMagnet) + assert isinstance(magnet_live, CombinedFunctionMagnet) + magnet_h_design = sr.design.get_magnet("SH1A-C01-H") + magnet_v_design = sr.design.get_magnet("SH1A-C01-V") + magnet_h_live = sr.live.get_magnet("SH1A-C01-H") + magnet_v_live = sr.live.get_magnet("SH1A-C01-V") + assert isinstance(magnet_h_design, HCorrector) + assert isinstance(magnet_v_design, VCorrector) + assert isinstance(magnet_h_live, HCorrector) + assert isinstance(magnet_v_live, VCorrector) + magnet_h_live.strength.set(0.000010) + magnet_v_live.strength.set(0.000015) + magnet_h_design.strength.set(0.000010) + magnet_v_design.strength.set(0.000015) + + o,_ = sr.design.get_lattice().find_orbit() + assert(np.abs(o[0] + 9.91848416e-05)<1e-10) + assert(np.abs(o[1] + 3.54829761e-07)<1e-10) + assert(np.abs(o[2] + 1.56246320e-06)<1e-10) + assert(np.abs(o[3] + 1.75037311e-05)<1e-10) + + Factory.clear() \ No newline at end of file