Skip to content

Response matrices #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
613d301
rebased on master
lfarv Jul 29, 2024
85c3a6c
rebased on master
lfarv Jul 29, 2024
5e54a5f
Documentation fixes
lfarv Jul 29, 2024
d5bea48
rebased on master
lfarv Jul 29, 2024
bcdba4d
rebased on master
lfarv Jul 30, 2024
b056a64
rebased on master
lfarv Jul 30, 2024
d1a1b1f
updated from matching
lfarv Nov 27, 2024
f74441c
updated from matching
lfarv Nov 27, 2024
bc3f48d
updated from matching
lfarv Nov 27, 2024
925ee5c
small improvements
lfarv Nov 30, 2024
7a700b9
rebased on master
lfarv Dec 1, 2024
edf93b5
Added properties
lfarv Dec 3, 2024
7c54973
make checkattr and others pickleable
lfarv Dec 9, 2024
8474df8
rebased on master
lfarv Dec 9, 2024
14567ae
parallel computation
lfarv Dec 10, 2024
a8117a3
switch to concurrent.futures
lfarv Dec 22, 2024
fa15f20
added sequence_split
lfarv Dec 22, 2024
eaebb92
Documentation
lfarv Dec 22, 2024
421a2ec
Added auto normalisation
lfarv Jan 8, 2025
a5bec91
Added a normalise method
lfarv Jan 8, 2025
685cbca
Documentation
lfarv Jan 9, 2025
89a417c
evaluate result
lfarv Jan 13, 2025
2726f6b
remove plot observables
lfarv Jan 16, 2025
36275d7
layout of the norm plot
lfarv Jan 22, 2025
e5174b1
simplification
lfarv Jan 22, 2025
e7c171d
Added analytical orbit response matrix
lfarv Feb 5, 2025
37ca618
Bug fix (issue #903)
lfarv Feb 14, 2025
50e677d
renamed build to build_tracking
lfarv Feb 24, 2025
625f168
Added analytical trajectory response
lfarv Feb 26, 2025
3d166a4
Exclusion of variables and observables
lfarv Mar 1, 2025
be540e4
Documentation
lfarv Mar 2, 2025
a198a2b
typos
lfarv Mar 2, 2025
2c19724
Documentation
lfarv Mar 6, 2025
32d51f7
typing
lfarv Mar 7, 2025
416befb
fix for python 3.7
lfarv Mar 7, 2025
ddf1512
typing
lfarv Mar 7, 2025
52e055f
bug fix
lfarv Mar 8, 2025
f86ffc8
observable weights
lfarv Mar 8, 2025
6438ed5
Check valid orbit before correcting
lfarv Mar 8, 2025
a2d0820
Added access to observable targets
lfarv Mar 8, 2025
0b55b4d
"Blackened" utils.py
lfarv Mar 9, 2025
2ca5935
cleanup
lfarv Mar 9, 2025
8bd436d
Documentation
lfarv Mar 9, 2025
7d20394
Documentation
lfarv Mar 9, 2025
b071a94
Documentation
lfarv Mar 9, 2025
c52d771
bug fix
lfarv Mar 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/p/api/at.latticetools.response_matrix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
at.latticetools.response\_matrix
================================

.. automodule:: at.latticetools.response_matrix
:inherited-members:


.. rubric:: Classes

.. autosummary::

ResponseMatrix
OrbitResponseMatrix
TrajectoryResponseMatrix

3 changes: 2 additions & 1 deletion docs/p/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Sub-packages
howto/multiprocessing
howto/CavityControl
howto/Collective
Working with MAD-X files <api/at.load.madx>
Work with MAD-X files <api/at.load.madx>
Use response matrices <notebooks/response_matrices>

.. autosummary::
:toctree: api
Expand Down
2 changes: 1 addition & 1 deletion docs/p/notebooks/observables.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.20"
"version": "3.11.11"
}
},
"nbformat": 4,
Expand Down
932 changes: 932 additions & 0 deletions docs/p/notebooks/response_matrices.ipynb

Large diffs are not rendered by default.

98 changes: 54 additions & 44 deletions pyat/at/lattice/axisdef.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
"""Helper functions for axis and plane descriptions"""

from __future__ import annotations
from typing import Optional, Union

# For sys.version_info.minor < 9:
# Necessary for type aliases in python <= 3.8 :
from typing import Tuple
from typing import Union

AxisCode = Union[str, int, slice, None, type(Ellipsis)]
AxisDef = Union[AxisCode, Tuple[AxisCode, AxisCode]]

_axis_def = dict(
x=dict(index=0, label="x", unit=" [m]"),
px=dict(index=1, label=r"$p_x$", unit=" [rad]"),
y=dict(index=2, label="y", unit=" [m]"),
py=dict(index=3, label=r"$p_y$", unit=" [rad]"),
dp=dict(index=4, label=r"$\delta$", unit=""),
ct=dict(index=5, label=r"$\beta c \tau$", unit=" [m]"),
)
for xk, xv in [it for it in _axis_def.items()]:
_axis_def = {
"x": {"index": 0, "label": "x", "unit": " [m]"},
"px": {"index": 1, "label": r"$p_x$", "unit": " [rad]"},
"y": {"index": 2, "label": "y", "unit": " [m]"},
"py": {"index": 3, "label": r"$p_y$", "unit": " [rad]"},
"dp": {"index": 4, "label": r"$\delta$", "unit": ""},
"ct": {"index": 5, "label": r"$\beta c \tau$", "unit": " [m]"},
}
for xk, xv in list(_axis_def.items()):
xv["code"] = xk
_axis_def[xv["index"]] = xv
_axis_def[xk.upper()] = xv
Expand All @@ -26,41 +26,43 @@
_axis_def["yp"] = _axis_def["py"] # For backward compatibility
_axis_def["s"] = _axis_def["ct"]
_axis_def["S"] = _axis_def["ct"]
_axis_def[None] = dict(index=None, label="", unit="", code=":")
_axis_def[Ellipsis] = dict(index=Ellipsis, label="", unit="", code="...")

_plane_def = dict(
x=dict(index=0, label="x", unit=" [m]"),
y=dict(index=1, label="y", unit=" [m]"),
z=dict(index=2, label="z", unit=""),
)
for xk, xv in [it for it in _plane_def.items()]:
_axis_def[None] = {"index": None, "label": "", "unit": "", "code": ":"}
_axis_def[Ellipsis] = {"index": Ellipsis, "label": "", "unit": "", "code": "..."}

_plane_def = {
"x": {"index": 0, "label": "x", "unit": " [m]"},
"y": {"index": 1, "label": "y", "unit": " [m]"},
"z": {"index": 2, "label": "z", "unit": ""},
}
for xk, xv in list(_plane_def.items()):
xv["code"] = xk
_plane_def[xv["index"]] = xv
_plane_def[xk.upper()] = xv
_plane_def["h"] = _plane_def["x"]
_plane_def["v"] = _plane_def["y"]
_plane_def["H"] = _plane_def["x"]
_plane_def["V"] = _plane_def["y"]
_plane_def[None] = dict(index=None, label="", unit="", code=":")
_plane_def[Ellipsis] = dict(index=Ellipsis, label="", unit="", code="...")
_plane_def[None] = {"index": None, "label": "", "unit": "", "code": ":"}
_plane_def[Ellipsis] = {"index": Ellipsis, "label": "", "unit": "", "code": "..."}


def _descr(dd: dict, arg: AxisDef, key: Optional[str] = None):
if isinstance(arg, tuple):
return tuple(_descr(dd, a, key=key) for a in arg)
else:
try:
descr = dd[arg]
except (TypeError, KeyError):
descr = dict(index=arg, code=arg, label="", unit="")
if key is None:
return descr
def _descr(dd: dict, *args: AxisDef, key: str | None = None):
for arg in args:
if isinstance(arg, tuple):
for a in arg:
yield from _descr(dd, a, key=key)
else:
return descr[key]
if isinstance(arg, slice):
descr = {"index": arg, "code": arg, "label": "", "unit": ""}
else:
descr = dd[arg]
if key is None:
yield descr
else:
yield descr[key]


def axis_(axis: AxisDef, key: Optional[str] = None):
def axis_(*axis: AxisDef, key: str | None = None):
r"""Return axis descriptions

Parameters:
Expand Down Expand Up @@ -100,28 +102,32 @@ def axis_(axis: AxisDef, key: Optional[str] = None):

Examples:

>>> axis_(('x','dp'), key='index')
>>> axis_("x", "dp", key="index")
(0, 4)

returns the indices in the standard coordinate vector

>>> dplabel = axis_('dp', key='label')
>>> dplabel = axis_("dp", key="label")
>>> print(dplabel)
$\delta$

returns the coordinate label for plot annotation

>>> axis_((0,'dp'))
>>> axis_(0, "dp")
({'plane': 0, 'label': 'x', 'unit': ' [m]', 'code': 'x'},
{'plane': 4, 'label': '$\\delta$', 'unit': '', 'code': 'dp'})

returns the entire description directories

"""
return _descr(_axis_def, axis, key=key)
ret = tuple(_descr(_axis_def, *axis, key=key))
if len(ret) > 1:
return ret
else:
return ret[0]


def plane_(plane: AxisDef, key: Optional[str] = None):
def plane_(*plane: AxisDef, key: str | None = None):
r"""Return plane descriptions

Parameters:
Expand Down Expand Up @@ -154,16 +160,20 @@ def plane_(plane: AxisDef, key: Optional[str] = None):

Examples:

>>> plane_('v', key='index')
>>> plane_("v", key="index")
1

returns the indices in the standard coordinate vector

>>> plane_(('x','y'))
({'plane': 0, 'label': 'h', 'unit': ' [m]', 'code': 'h'},
{'plane': 1, 'label': 'v', 'unit': ' [m]', 'code': 'v'})
>>> plane_("x", "y")
({'plane': 0, 'label': 'x', 'unit': ' [m]', 'code': 'h'},
{'plane': 1, 'label': 'y', 'unit': ' [m]', 'code': 'v'})

returns the entire description directories

"""
return _descr(_plane_def, plane, key=key)
ret = tuple(_descr(_plane_def, *plane, key=key))
if len(ret) > 1:
return ret
else:
return ret[0]
Loading