Skip to content

Commit a67a00d

Browse files
committed
notebook drafts
1 parent 16f7e14 commit a67a00d

File tree

3 files changed

+304
-0
lines changed

3 files changed

+304
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "7a473047",
6+
"metadata": {},
7+
"source": [
8+
"# Control System set up"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"id": "62672006",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"from pyaml.pyaml import pyaml,PyAML"
19+
]
20+
}
21+
],
22+
"metadata": {
23+
"language_info": {
24+
"name": "python"
25+
}
26+
},
27+
"nbformat": 4,
28+
"nbformat_minor": 5
29+
}

docs/notebooks/live_design.ipynb

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "d3621c17",
6+
"metadata": {},
7+
"source": [
8+
"# Live/Design: control modes\n",
9+
"\n",
10+
"With *pyAML* it is possible to use the same commands either:\n",
11+
"1. live: on the real accelerator\n",
12+
"2. design: in simulations\n",
13+
"3. errors: in simulations with errors (and for several seeds)\n",
14+
"4. live (with a different prefix/host): in a virtual control system (same as in point 1. for those laboratories that have a simulated control system)\n",
15+
"\n",
16+
"Those are called \"control modes\" and may be used \n",
17+
"- at a global script level (for testing in simulations and then using in real accelerator measurements with a simple switch/comment) \n",
18+
"- anywhere in the script "
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"id": "805b0f6c",
24+
"metadata": {},
25+
"source": [
26+
"Using pyAML on a real accelerator"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": null,
32+
"id": "c4884e24",
33+
"metadata": {},
34+
"outputs": [],
35+
"source": [
36+
"from pyaml.pyaml import pyaml,PyAML\n",
37+
"from pyaml.instrument import Instrument\n",
38+
"from pyaml.configuration.factory import Factory\n",
39+
"import numpy as np"
40+
]
41+
},
42+
{
43+
"cell_type": "markdown",
44+
"id": "b8ff1736",
45+
"metadata": {},
46+
"source": [
47+
"instantiate a pyAML accelerator"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"id": "fc1881d9",
54+
"metadata": {},
55+
"outputs": [],
56+
"source": [
57+
"ml:PyAML = pyaml('../../tests/config/EBSTune.yaml')\n",
58+
"SR:Instrument = ml.get('sr')"
59+
]
60+
},
61+
{
62+
"cell_type": "markdown",
63+
"id": "9a3c6e0a",
64+
"metadata": {},
65+
"source": [
66+
"Switch between live and design"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": null,
72+
"id": "21ce8527",
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"# sr = SR.live # use real accelerator\n",
77+
"sr = SR.design # run script in simulations"
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"id": "4e55d6b6",
83+
"metadata": {},
84+
"source": [
85+
"access some magnet families defined in the configuration"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": null,
91+
"id": "b1fb943f",
92+
"metadata": {},
93+
"outputs": [],
94+
"source": [
95+
"\n",
96+
"quadForTuneDesign = sr.get_magnets(\"QForTune\")\n",
97+
"quadForTuneLive = sr.get_magnets(\"QForTune\")\n"
98+
]
99+
},
100+
{
101+
"cell_type": "markdown",
102+
"id": "fdc66eea",
103+
"metadata": {},
104+
"source": [
105+
"Execute actions with the magnets families (here for example a tune response matrix is evaluated)"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": null,
111+
"id": "d6dc44d3",
112+
"metadata": {},
113+
"outputs": [],
114+
"source": [
115+
"# Build tune response matrix\n",
116+
"tune = sr.get_lattice().get_tune()\n",
117+
"\n",
118+
"print(tune)\n",
119+
"tunemat = np.zeros((len(quadForTuneDesign),2))\n",
120+
"\n",
121+
"for idx,m in enumerate(quadForTuneDesign):\n",
122+
" str = m.strength.get()\n",
123+
" m.strength.set(str+1e-4)\n",
124+
" dq = sr.get_lattice().get_tune() - tune\n",
125+
" tunemat[idx] = dq*1e4\n",
126+
" m.strength.set(str)"
127+
]
128+
},
129+
{
130+
"cell_type": "markdown",
131+
"id": "bf75c939",
132+
"metadata": {},
133+
"source": [
134+
"At any point in the code it is always possible to still access any of the control modes"
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": null,
140+
"id": "b5cec1f2",
141+
"metadata": {},
142+
"outputs": [],
143+
"source": [
144+
"print(sr.get_tune()) # what ever the globally set mode whas\n",
145+
"\n",
146+
"SR.design.get_tune() # tune from design simulations \n",
147+
"\n",
148+
"SR.live.get_tune() # tune from real accelerator"
149+
]
150+
}
151+
],
152+
"metadata": {
153+
"kernelspec": {
154+
"display_name": "pyaml_venv",
155+
"language": "python",
156+
"name": "python3"
157+
},
158+
"language_info": {
159+
"codemirror_mode": {
160+
"name": "ipython",
161+
"version": 3
162+
},
163+
"file_extension": ".py",
164+
"mimetype": "text/x-python",
165+
"name": "python",
166+
"nbconvert_exporter": "python",
167+
"pygments_lexer": "ipython3",
168+
"version": "3.14.0"
169+
}
170+
},
171+
"nbformat": 4,
172+
"nbformat_minor": 5
173+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "420c1a3c",
6+
"metadata": {},
7+
"source": [
8+
"# Configuration"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"id": "7204f09a",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"from pyaml.pyaml import pyaml,PyAML\n",
19+
"\n",
20+
"ml:PyAML = pyaml('../../tests/config/EBSTune.yaml')"
21+
]
22+
},
23+
{
24+
"cell_type": "markdown",
25+
"id": "f6ccb72a",
26+
"metadata": {},
27+
"source": [
28+
"pyaml/tests/config/EBSTune.yaml is an example pyAML yaml configuration file that defines:\n",
29+
"- a 6GeV Storage ring with\n",
30+
" - 1 array (family) of quadrupoles used for tune correction\n",
31+
" - 1 tune device\n",
32+
" - controlled by Tango\n",
33+
" - simulated with AT\n",
34+
"\n",
35+
"It looks like this: \n",
36+
"\n",
37+
"```\n",
38+
"type: pyaml.pyaml\n",
39+
"instruments:\n",
40+
" - type: pyaml.instrument\n",
41+
" name: sr \n",
42+
" energy: 6e9\n",
43+
" simulators:\n",
44+
" - type: pyaml.lattice.simulator\n",
45+
" lattice: sr/lattices/ebs.mat\n",
46+
" name: design\n",
47+
" controls:\n",
48+
" - type: tango.pyaml.controlsystem\n",
49+
" tango_host: ebs-simu-3:10000\n",
50+
" name: live\n",
51+
" data_folder: /data/store\n",
52+
" arrays:\n",
53+
" - type: pyaml.arrays.magnet\n",
54+
" name: QForTune\n",
55+
" elements:\n",
56+
" - QD2E-C04\n",
57+
" - QD2A-C05\n",
58+
" - QD2E-C05\n",
59+
" - QD2A-C06\n",
60+
" - QD2E-C06\n",
61+
" - QD2A-C07\n",
62+
" - ...\n",
63+
" devices: \n",
64+
" - type: pyaml.magnet.quadrupole\n",
65+
" name: QD2A-C03\n",
66+
" model:\n",
67+
" type: pyaml.magnet.linear_model\n",
68+
" calibration_factor: 1.002096389\n",
69+
" crosstalk: 0.99912\n",
70+
" curve:\n",
71+
" type: pyaml.configuration.csvcurve\n",
72+
" file: sr/magnet_models/QD2_strength.csv\n",
73+
" unit: 1/m\n",
74+
" powerconverter:\n",
75+
" type: tango.pyaml.attribute\n",
76+
" attribute: srmag/vps-qd2/c03-a/current\n",
77+
" unit: A\n",
78+
" - ... \n",
79+
" - ...\n",
80+
" - ...\n",
81+
" - type: pyaml.diagnostics.tune_monitor\n",
82+
" name: BETATRON_TUNE\n",
83+
" tune_h:\n",
84+
" type: tango.pyaml.attribute_read_only\n",
85+
" attribute: srdiag/tune/tune_h\n",
86+
" unit: mm\n",
87+
" tune_v:\n",
88+
" type: tango.pyaml.attribute_read_only\n",
89+
" attribute: srdiag/tune/tune_v\n",
90+
" unit: mm\n",
91+
"```\n"
92+
]
93+
}
94+
],
95+
"metadata": {
96+
"language_info": {
97+
"name": "python"
98+
}
99+
},
100+
"nbformat": 4,
101+
"nbformat_minor": 5
102+
}

0 commit comments

Comments
 (0)