From 2fa7457d325f6d30ee3c8a7b697b64dc5a7e5358 Mon Sep 17 00:00:00 2001 From: Teresia Olsson Date: Wed, 15 Oct 2025 11:28:41 +0200 Subject: [PATCH 1/2] Added example for the ESRF tune case extracted from the pytests. --- .../ESRF_tune_example/esrf_tune_example.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/ESRF_tune_example/esrf_tune_example.py diff --git a/examples/ESRF_tune_example/esrf_tune_example.py b/examples/ESRF_tune_example/esrf_tune_example.py new file mode 100644 index 00000000..6417e27c --- /dev/null +++ b/examples/ESRF_tune_example/esrf_tune_example.py @@ -0,0 +1,46 @@ +from pyaml.pyaml import pyaml,PyAML +from pyaml.instrument import Instrument +from pyaml.configuration.factory import Factory +import numpy as np + +ml:PyAML = pyaml("/home/a3744/Documents/software/pyAML/pyaml/tests/config/EBSTune.yaml") +sr:Instrument = ml.get('sr') +sr.design.get_lattice().disable_6d() + +quadForTuneDesign = sr.design.get_magnets("QForTune") +quadForTuneLive = sr.live.get_magnets("QForTune") + +# Build tune response matrix +tune = sr.design.get_lattice().get_tune() +print(tune) +tunemat = np.zeros((len(quadForTuneDesign),2)) + +for idx,m in enumerate(quadForTuneDesign): + str = m.strength.get() + m.strength.set(str+1e-4) + dq = sr.design.get_lattice().get_tune() - tune + tunemat[idx] = dq*1e4 + m.strength.set(str) + +# Compute correction matrix +correctionmat = np.linalg.pinv(tunemat.T) + +# Correct tune +strs = quadForTuneDesign.strengths.get() +strs += np.matmul(correctionmat,[0.1,0.05]) # Ask for correction [dqx,dqy] +quadForTuneDesign.strengths.set(strs) +newTune = sr.design.get_lattice().get_tune() +diffTune = newTune-tune +print(diffTune) +assert( np.abs(diffTune[0]-0.1) < 1e-3 ) +assert( np.abs(diffTune[1]-0.05) < 1e-3 ) + +if False: + # Correct the tune on live (need a Virutal Accelerator) + quadForTuneLive = sr.live.get_magnets("QForTune") + strs = quadForTuneLive.strengths.get() + strs += np.matmul(correctionmat,[0.1,0.05]) # Ask for correction [dqx,dqy] + quadForTuneLive.strengths.set(strs) + + +Factory.clear() From 4cc4edf56d4676a44e6224583eaea32e9d7c3917 Mon Sep 17 00:00:00 2001 From: Teresia Olsson Date: Wed, 15 Oct 2025 11:36:40 +0200 Subject: [PATCH 2/2] Make path generic. --- examples/ESRF_tune_example/esrf_tune_example.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/ESRF_tune_example/esrf_tune_example.py b/examples/ESRF_tune_example/esrf_tune_example.py index 6417e27c..abe0253a 100644 --- a/examples/ESRF_tune_example/esrf_tune_example.py +++ b/examples/ESRF_tune_example/esrf_tune_example.py @@ -2,8 +2,19 @@ from pyaml.instrument import Instrument from pyaml.configuration.factory import Factory import numpy as np +import os -ml:PyAML = pyaml("/home/a3744/Documents/software/pyAML/pyaml/tests/config/EBSTune.yaml") + +# Get the directory of the current script +script_dir = os.path.dirname(__file__) + +# Go up one level and then into 'data' +relative_path = os.path.join(script_dir, '..', '..', 'tests', 'config','EBSTune.yaml') + +# Normalize the path (resolves '..') +absolute_path = os.path.abspath(relative_path) + +ml:PyAML = pyaml(absolute_path) sr:Instrument = ml.get('sr') sr.design.get_lattice().disable_6d()