Skip to content

Commit 0db6874

Browse files
authored
Merge pull request #161 from python-accelerator-middle-layer/esrf_tune_example_proposal
ESRF tune example proposal
2 parents 948fd9f + 55c92a4 commit 0db6874

File tree

2 files changed

+73
-17
lines changed

2 files changed

+73
-17
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Instructions for how to run the ESRF Tune example.
2+
3+
## Install pyAML
4+
5+
1. Create a virtual environment and activate it. It needs to have >= Python 3.11.
6+
7+
2. Install pyAML including the tango bindings.
8+
9+
```bash
10+
pip install accelerator-middle-layer[tango]
11+
```
12+
13+
3. install EBS dummy Control system. This is valid untill an ESRF virtual machine will be available as for BESSYII and SOLEIL
14+
```bash
15+
pip install tests/dummy_cs/tango-pyaml
16+
```
17+
18+
## Run the examples
19+
Two examples are available for tune correction.
20+
The esrf_tune_example.py shows the standard usage
21+
The esrf_tune_example_no_yaml.py shows the same but without using configuration file.
22+
23+
To run the examples:
24+
1. navigate to the pyaml root directory
25+
2. Download (or clone) the example files.
26+
3. run the files
27+
28+
## expected output of esrf_tune_example.py for SR.design is
29+
30+
30 Jan 2026, 09:23:13 | WARNING | PyAML Tango control system binding (0.3.2) initialized with name 'live' and TANGO_HOST=ebs-simu-3:10000
31+
Tune response: #0 QD2E-C04 [ 0.17851726 -1.25993589]
32+
Tune response: #1 QD2A-C05 [ 0.17889514 -1.25969115]
33+
...
34+
Tune response: #123 QF1A-C03 [ 0.59069308 -0.49430245]
35+
Initial tune: [0.16000001 0.33999986]
36+
Final tune: [0.17 0.32]
37+
38+
39+
## expected output of esrf_tune_example.py for SR.live is
40+
Initial tune: [0. 0.]
41+
MultiAttribute.get(124 values)
42+
MultiAttribute.get(124 values)
43+
MultiAttribute.set(124 values)
44+
//ebs-simu-3:10000/srmag/vps-qd2/c04-e/current:0.8688600876142427
45+
...
46+
//ebs-simu-3:10000/srmag/vps-qf1/c02-e/current:1.3024074153237937
47+
//ebs-simu-3:10000/srmag/vps-qf1/c03-a/current:1.2966875742108155
48+
Final tune: [0. 0.]
49+
50+
## expected output of: esrf_tune_example_no_yaml.py
51+
52+
Creating dummy TangoControlSystem: live
53+
Tune=Value(0.0, quality='VALID',timestamp='2026-01-30 10:14:20.685681'), Value(0.0, quality='VALID',timestamp='2026-01-30 10:14:20.685764')
54+
MultiAttribute.get(4 values)
55+
MultiAttribute.get(4 values)
56+
MultiAttribute.set(4 values)
57+
//ebs-simu-3:10000/srmag/vps-qf1/c01-a/current:9.77449643229055
58+
//ebs-simu-3:10000/srmag/vps-qf1/c01-e/current:9.724114177375114
59+
//ebs-simu-3:10000/srmag/vps-qd2/c01-a/current:7.785894751522811
60+
//ebs-simu-3:10000/srmag/vps-qd2/c01-e/current:7.778613675036138
61+
Tune=Value(0.0, quality='VALID',timestamp='2026-01-30 10:14:23.686925'), Value(0.0, quality='VALID',timestamp='2026-01-30 10:14:23.686994')

examples/ESRF_tune_example/esrf_tune_example.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66
from pyaml.common.constants import ACTION_RESTORE
77
from pyaml.magnet.magnet import Magnet
88

9-
# Get the directory of the current script
10-
script_dir = os.path.dirname(__file__)
11-
12-
# Go up one level and then into 'data'
13-
relative_path = os.path.join(script_dir, "..", "..", "tests", "config", "EBSTune.yaml")
14-
15-
# Normalize the path (resolves '..')
16-
absolute_path = os.path.abspath(relative_path)
17-
18-
sr: Accelerator = Accelerator.load(absolute_path)
9+
sr: Accelerator = Accelerator.load("./tests/config/EBSTune.yaml")
1910
sr.design.get_lattice().disable_6d()
2011

12+
# switch script from live to design
13+
# sr.design acts on simulations sr.live to act on real machine
14+
SR = sr.live
15+
2116

2217
# Callback exectued after each magnet strenght setting
2318
# during the tune response matrix measurement
@@ -29,13 +24,13 @@ def tune_callback(step: int, action: int, m: Magnet, dtune: np.array):
2924

3025

3126
# Compute tune response matrix
32-
tune_adjust_design = sr.design.get_tune_tuning("TUNE")
27+
tune_adjust_design = sr.design.tune
3328
tune_adjust_design.response.measure(callback=tune_callback)
3429
tune_adjust_design.response.save_json("tunemat.json")
3530

36-
# Correct tune on live
37-
tune_adjust_live = sr.live.get_tune_tuning("TUNE")
38-
tune_adjust_live.response.load_json("tunemat.json")
39-
print(tune_adjust_live.readback())
40-
tune_adjust_live.set([0.17, 0.32], iter=2, wait_time=10)
41-
print(tune_adjust_live.readback())
31+
# Correct tune on live or design
32+
tune_adjust = SR.tune
33+
tune_adjust.response.load_json("tunemat.json")
34+
print(f"Initial tune: {tune_adjust.readback()}")
35+
tune_adjust.set([0.17, 0.32], iter=2, wait_time=10)
36+
print(f"Final tune: {tune_adjust.readback()}")

0 commit comments

Comments
 (0)