Skip to content

Commit 883233c

Browse files
authored
Merge pull request #224 from python-accelerator-middle-layer/doc-fix-tuning-tool
Fix and add exmaple in docstring
2 parents e04efa6 + 0e92220 commit 883233c

6 files changed

Lines changed: 83 additions & 14 deletions

File tree

pyaml/apidoc/gen_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
modules = [
1212
"pyaml.accelerator",
13-
"pyaml.apidoc.gen_api",
1413
"pyaml.arrays.array",
1514
"pyaml.arrays.bpm",
1615
"pyaml.arrays.bpm_array",
@@ -81,8 +80,10 @@
8180
"pyaml.tuning_tools.dispersion",
8281
"pyaml.tuning_tools.orbit",
8382
"pyaml.tuning_tools.orbit_response_matrix",
84-
"pyaml.tuning_tools.measurement_tool",
83+
"pyaml.tuning_tools.chromaticity",
8584
"pyaml.tuning_tools.tune",
85+
"pyaml.tuning_tools.chromaticity_response_matrix",
86+
"pyaml.tuning_tools.measurement_tool",
8687
"pyaml.tuning_tools.orbit_response_matrix_data",
8788
"pyaml.tuning_tools.response_matrix_data",
8889
"pyaml.tuning_tools.tune_response_matrix",

pyaml/tuning_tools/chromaticity.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ def __init__(self, cfg: ConfigModel):
8080
self._setpoint = np.array([np.nan, np.nan])
8181

8282
def load(self, load_path: Path):
83+
"""
84+
Dyanmically loads a response matrix.
85+
86+
Parameters
87+
----------
88+
load_path : Path
89+
Filename of the :class:`~.ResponseMatrixData` to load
90+
"""
8391
self._cfg.response_matrix = ResponseMatrixData.load(load_path)
8492
self._response_matrix = np.array(self._cfg.response_matrix._cfg.matrix)
8593
self._correctionmat = np.linalg.pinv(self._response_matrix)

pyaml/tuning_tools/chromaticity_response_matrix.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConfigModel(MeasurementToolConfigModel):
2222
Parameters
2323
----------
2424
sextu_array_name : str
25-
Array name of quad used to adjust the tune
25+
Array name of sextupole used to adjust the chromaticity
2626
chromaticity_name : str
2727
Name of the diagnostic chromaticy monitor
2828
sextu_delta : float
@@ -54,24 +54,44 @@ def measure(
5454
"""
5555
Measure tune response matrix
5656
57+
**Example**
58+
59+
.. code-block:: python
60+
61+
from pyaml.accelerator import Accelerator
62+
from pyaml.common.constants import Action
63+
64+
def callback(action: Action, data:dict):
65+
print(f"{action}, data:{data}")
66+
return True
67+
68+
sr = Accelerator.load("tests/config/EBSOrbit.yaml")
69+
acc = sr.design
70+
71+
if acc.crm.measure(callback=callback):
72+
acc.crm.save("ideal_crm.json")
73+
acc.crm.save("ideal_crm.yaml", with_type="yaml")
74+
acc.crm.save("ideal_crm.npz", with_type="npz")
75+
76+
5777
Parameters
5878
----------
5979
sextu_delta : float
6080
Delta strength used to get the response matrix
6181
n_step: int, optional
62-
Number of step for fitting the tune [-quad_delta/n_step..quad_delta/n_step]
82+
Number of step for fitting the chomaticity slope [-sextu_delta/n_step..sextu_delta/n_step]
6383
Default from config
6484
sleep_between_step: float
65-
Default time sleep after quad exitation
85+
Default time sleep after sextu exitation
6686
Default: from config
6787
n_avg_meas : int, optional
68-
Default number of chroma measurement per step used for averaging
88+
Default number of chromaticity measurement per step used for averaging
6989
Default from config
7090
sleep_between_meas: float
71-
Default time sleep between two tune measurment
91+
Default time sleep between two chomaticity measurment
7292
Default: from config
7393
callback : Callable, optional
74-
Callback executed after each strength setting.
94+
Callback executed after each strength setting or measurement.
7595
See :py:meth:`~.measurement_tool.MeasurementTool.send_callback`.
7696
If the callback return false, then the scan is aborted and strength restored.
7797
callback_data dict contains:

pyaml/tuning_tools/orbit_response_matrix.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,30 @@ def measure(
6161
callback: Optional[Callable] = None,
6262
):
6363
"""
64-
Measure orbit response matrix
64+
Measure orbit response matrix.
65+
66+
**Example**
67+
68+
.. code-block:: python
69+
70+
sr = Accelerator.load("MyAccelerator.yaml")
71+
acc = sr.design
72+
73+
if acc.orm.measure():
74+
acc.orm.save("ideal_orm.json")
75+
acc.orm.save("ideal_orm.yaml", with_type="yaml")
76+
acc.orm.save("ideal_orm.npz", with_type="npz")
6577
6678
Parameters
6779
----------
6880
sleep_between_step: float
69-
Default time sleep after quad exitation
81+
Default time sleep after steerer exitation
7082
Default: from config
7183
n_avg_meas : int, optional
72-
Default number of tune measurement per step used for averaging
84+
Default number of orbit measurement per step used for averaging
7385
Default from config
7486
sleep_between_meas: float
75-
Default time sleep between two tune measurment
87+
Default time sleep between two orbit measurment
7688
Default: from config
7789
callback : Callable, optional
7890
example: callback(action:int, callback_data: 'Complicated struct')

pyaml/tuning_tools/tune.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ def __init__(self, cfg: ConfigModel):
8181
self._setpoint = np.array([np.nan, np.nan])
8282

8383
def load(self, load_path: Path):
84+
"""
85+
Dyanmically loads a response matrix.
86+
87+
Parameters
88+
----------
89+
load_path : Path
90+
Filename of the :class:`~.ResponseMatrixData` to load
91+
92+
"""
8493
self._cfg.response_matrix = ResponseMatrixData.load(load_path)
8594
self._response_matrix = np.array(self._cfg.response_matrix._cfg.matrix)
8695
self._correctionmat = np.linalg.pinv(self._response_matrix)

pyaml/tuning_tools/tune_response_matrix.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,31 @@ def measure(
5252
"""
5353
Measure tune response matrix
5454
55+
**Example**
56+
57+
.. code-block:: python
58+
59+
from pyaml.accelerator import Accelerator
60+
from pyaml.common.constants import Action
61+
62+
def callback(action: Action, data:dict):
63+
print(f"{action}, data:{data}")
64+
return True
65+
66+
sr = Accelerator.load("tests/config/EBSTune.yaml")
67+
acc = sr.design
68+
69+
if acc.trm.measure(n_avg_meas=3,sleep_between_meas=5,callback=callback):
70+
acc.trm.save("ideal_trm.json")
71+
acc.trm.save("ideal_trm.yaml", with_type="yaml")
72+
acc.trm.save("ideal_trm.npz", with_type="npz")
73+
5574
Parameters
5675
----------
5776
quad_delta : float
5877
Delta strength used to get the response matrix
5978
n_step: int, optional
60-
Number of step for fitting the tune [-quad_delta/n_step..quad_delta/n_step]
79+
Number of step for fitting the tune slope [-quad_delta/n_step..quad_delta/n_step]
6180
Default from config
6281
sleep_between_step: float
6382
Default time sleep after quad exitation
@@ -69,7 +88,7 @@ def measure(
6988
Default time sleep between two tune measurment
7089
Default: from config
7190
callback : Callable, optional
72-
Callback executed after each strength setting.
91+
Callback executed after each strength setting or measurement.
7392
See :py:meth:`~.measurement_tool.MeasurementTool.send_callback`.
7493
If the callback return false, then the scan is aborted and strength restored.
7594
callback_data dict contains:

0 commit comments

Comments
 (0)