Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyaml/magnet/identity_cfm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 29 additions & 0 deletions tests/config/sr-ident-cfm.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/config/sr/correctors/SH1AC01-ident.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/config/sr/magnet_models/SH1AC01-ident.yaml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions tests/test_ident_models.py
Original file line number Diff line number Diff line change
@@ -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()
Loading