Skip to content

Commit 3a8f87a

Browse files
Correction of the usage of powerconverters attribute and new tests.
1 parent 899311c commit 3a8f87a

File tree

5 files changed

+103
-3
lines changed

5 files changed

+103
-3
lines changed

pyaml/magnet/identity_cfm_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ def __init__(self, cfg: ConfigModel):
3333
# Check config
3434
self.__nbFunction: int = len(cfg.multipoles)
3535

36-
if cfg.physics is None and cfg.powerconverter is None:
36+
if cfg.physics is None and cfg.powerconverters is None:
3737
raise Exception("Invalid IdentityCFMagnetModel configuration, physics or powerconverters device required")
38-
if cfg.physics is not None and cfg.powerconverter is not None:
38+
if cfg.physics is not None and cfg.powerconverters is not None:
3939
raise Exception("Invalid IdentityCFMagnetModel configuration, physics or powerconverters device required but not both")
4040
if cfg.physics:
4141
self.__devices = cfg.physics
4242
else:
43-
self.__devices = cfg.powerconverter
43+
self.__devices = cfg.powerconverters
4444

4545
self.__nbDev: int = len(self.__devices)
4646

tests/config/sr-ident-cfm.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
type: pyaml.pyaml
2+
instruments:
3+
- type: pyaml.instrument
4+
name: sr
5+
energy: 6e9
6+
simulators:
7+
- type: pyaml.lattice.simulator
8+
lattice: sr/lattices/ebs.mat
9+
name: design
10+
controls:
11+
- type: tango.pyaml.controlsystem
12+
tango_host: ebs-simu-3:10000
13+
name: live
14+
data_folder: /data/store
15+
arrays:
16+
- type: pyaml.arrays.magnet
17+
name: HCORR
18+
elements:
19+
- SH1A-C01-H
20+
- SH1A-C02-H
21+
- type: pyaml.arrays.magnet
22+
name: VCORR
23+
elements:
24+
- SH1A-C01-V
25+
- SH1A-C02-V
26+
devices:
27+
- sr/quadrupoles/QF1AC01.yaml
28+
- sr/correctors/SH1AC01-ident.yaml
29+
- sr/correctors/SH1AC02.yaml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type: pyaml.magnet.cfm_magnet
2+
name: SH1A-C01 #Name of the element in the lattice model
3+
mapping:
4+
# Multipole mapping for usage in families, in this example SH1-C01A-H is not
5+
# a lattice element present in the model, it is just a name to use in
6+
# PyAML families. When this 'virutal' element is set, it then applies
7+
# the corresponding multipole on the parent element.
8+
- [B0, SH1A-C01-H]
9+
- [A0, SH1A-C01-V]
10+
- [A1, SH1A-C01-SQ]
11+
model: sr/magnet_models/SH1AC01-ident.yaml
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type: pyaml.magnet.identity_cfm_model
2+
multipoles: [B0,A0,A1]
3+
units: [rad,rad,m-1]
4+
physics:
5+
- type: tango.pyaml.attribute
6+
attribute: srmag/ps-corr-sh1/c01-a-ch1/strength
7+
unit: rad
8+
- type: tango.pyaml.attribute
9+
attribute: srmag/ps-corr-sh1/c01-a-ch2/strength
10+
unit: rad
11+
- type: tango.pyaml.attribute
12+
attribute: srmag/ps-corr-sh1/c01-a-ch3/strength
13+
unit: m-1

tests/test_ident_models.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import pytest
2+
3+
from pyaml.magnet.cfm_magnet import CombinedFunctionMagnet
4+
from pyaml.magnet.hcorrector import HCorrector
5+
from pyaml.magnet.vcorrector import VCorrector
6+
from pyaml.pyaml import pyaml,PyAML
7+
from pyaml.configuration.factory import Factory
8+
from pyaml.instrument import Instrument
9+
from pyaml.magnet.model import MagnetModel
10+
import numpy as np
11+
12+
@pytest.mark.parametrize(
13+
("magnet_file", "install_test_package"),
14+
[
15+
("tests/config/sr-ident-cfm.yaml", {"name": "tango", "path": "tests/dummy_cs/tango"}),
16+
],
17+
indirect=["install_test_package"],
18+
)
19+
def test_cfm_magnets(magnet_file, install_test_package):
20+
21+
ml:PyAML = pyaml(magnet_file)
22+
sr:Instrument = ml.get('sr')
23+
sr.design.get_lattice().disable_6d()
24+
magnet_design = sr.design.get_magnet("SH1A-C01")
25+
magnet_live = sr.live.get_magnet("SH1A-C01")
26+
assert isinstance(magnet_design, CombinedFunctionMagnet)
27+
assert isinstance(magnet_live, CombinedFunctionMagnet)
28+
magnet_h_design = sr.design.get_magnet("SH1A-C01-H")
29+
magnet_v_design = sr.design.get_magnet("SH1A-C01-V")
30+
magnet_h_live = sr.live.get_magnet("SH1A-C01-H")
31+
magnet_v_live = sr.live.get_magnet("SH1A-C01-V")
32+
assert isinstance(magnet_h_design, HCorrector)
33+
assert isinstance(magnet_v_design, VCorrector)
34+
assert isinstance(magnet_h_live, HCorrector)
35+
assert isinstance(magnet_v_live, VCorrector)
36+
magnet_h_live.strength.set(0.000010)
37+
magnet_v_live.strength.set(0.000015)
38+
magnet_h_design.strength.set(0.000010)
39+
magnet_v_design.strength.set(0.000015)
40+
41+
o,_ = sr.design.get_lattice().find_orbit()
42+
assert(np.abs(o[0] + 9.91848416e-05)<1e-10)
43+
assert(np.abs(o[1] + 3.54829761e-07)<1e-10)
44+
assert(np.abs(o[2] + 1.56246320e-06)<1e-10)
45+
assert(np.abs(o[3] + 1.75037311e-05)<1e-10)
46+
47+
Factory.clear()

0 commit comments

Comments
 (0)