dipas.elements module
Accelerator lattice elements represented by PyTorch Modules.
The various element classes are made available together with the corresponding MADX command name in the following dicts.
- dipas.elements.elements
Maps MADX command names to corresponding Element backend classes.
- Type
dict
- dipas.elements.alignment_errors
Maps MADX
EALIGN
command attributes to corresponding AlignmentError backend classes.- Type
dict
- dipas.elements.aperture_types
Maps MADX
apertypes
definitions to corresponding Aperture backend classes.- Type
dict
- class dipas.elements.ApertureCircle(aperture: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = <MagicMock name='mock.tensor()' id='139745949143376'>, padding: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = <MagicMock name='mock.tensor()' id='139745949143376'>, offset: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>] = <MagicMock name='mock.zeros()' id='139745955693840'>)
Bases:
Aperture
Circular aperture.
- Parameters
aperture (Tensor, scalar (shape [])) – Radius of the circle.
- aperture: Parameter' id='139745955712976'>]
- classmethod loss(xy: <MagicMock name='mock.Tensor' id='139745955357904'>, aperture: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Compute the loss values for the given xy-positions.
- Parameters
xy (Tensor) – Tensor of shape (2, N) where N is the number of particles and rows are x- and y-positions, respectively, centered within the aperture.
aperture (Tensor) – The effective aperture of the element, interpreted by the particular subclass.
- Returns
loss_val – Tensor of shape (N,), zero where positions are inside the aperture (including exactly at the aperture) and greater than zero where positions are outside the aperture.
- Return type
Tensor
- offset: <MagicMock name='mock.Tensor' id='139745955357904'>
- padding: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.ApertureEllipse(aperture: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = <MagicMock name='mock.tensor()' id='139745949143376'>, padding: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>] = <MagicMock name='mock.zeros()' id='139745955693840'>, offset: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>] = <MagicMock name='mock.zeros()' id='139745955693840'>)
Bases:
Aperture
Elliptical aperture.
- Parameters
aperture (Tensor, shape (2,)) – Horizontal and vertical semi-axes of the ellipse.
- aperture: Parameter' id='139745955712976'>]
- classmethod loss(xy: <MagicMock name='mock.Tensor' id='139745955357904'>, aperture: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Compute the loss values for the given xy-positions.
- Parameters
xy (Tensor) – Tensor of shape (2, N) where N is the number of particles and rows are x- and y-positions, respectively, centered within the aperture.
aperture (Tensor) – The effective aperture of the element, interpreted by the particular subclass.
- Returns
loss_val – Tensor of shape (N,), zero where positions are inside the aperture (including exactly at the aperture) and greater than zero where positions are outside the aperture.
- Return type
Tensor
- offset: <MagicMock name='mock.Tensor' id='139745955357904'>
- padding: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.ApertureRectEllipse(aperture: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = <MagicMock name='mock.tensor()' id='139745949143376'>, padding: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>] = <MagicMock name='mock.zeros()' id='139745955693840'>, offset: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>] = <MagicMock name='mock.zeros()' id='139745955693840'>)
Bases:
Aperture
Overlay of rectangular and elliptical aperture.
- Parameters
aperture (Tensor, shape (4,)) – Half width (horizontal) and half height (vertical) of the rectangle followed by horizontal and vertical semi-axes of the ellipse.
- aperture: Parameter' id='139745955712976'>]
- classmethod loss(xy: <MagicMock name='mock.Tensor' id='139745955357904'>, aperture: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Compute the loss values for the given xy-positions.
- Parameters
xy (Tensor) – Tensor of shape (2, N) where N is the number of particles and rows are x- and y-positions, respectively, centered within the aperture.
aperture (Tensor) – The effective aperture of the element, interpreted by the particular subclass.
- Returns
loss_val – Tensor of shape (N,), zero where positions are inside the aperture (including exactly at the aperture) and greater than zero where positions are outside the aperture.
- Return type
Tensor
- offset: <MagicMock name='mock.Tensor' id='139745955357904'>
- padding: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.ApertureRectangle(aperture: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = <MagicMock name='mock.tensor()' id='139745949143376'>, padding: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>] = <MagicMock name='mock.zeros()' id='139745955693840'>, offset: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>] = <MagicMock name='mock.zeros()' id='139745955693840'>)
Bases:
Aperture
Rectangular aperture.
- Parameters
aperture (Tensor, shape (2,)) – Half width (horizontal) and half height (vertical) of the rectangle.
- aperture: Parameter' id='139745955712976'>]
- classmethod loss(xy: <MagicMock name='mock.Tensor' id='139745955357904'>, aperture: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Compute the loss values for the given xy-positions.
- Parameters
xy (Tensor) – Tensor of shape (2, N) where N is the number of particles and rows are x- and y-positions, respectively, centered within the aperture.
aperture (Tensor) – The effective aperture of the element, interpreted by the particular subclass.
- Returns
loss_val – Tensor of shape (N,), zero where positions are inside the aperture (including exactly at the aperture) and greater than zero where positions are outside the aperture.
- Return type
Tensor
- offset: <MagicMock name='mock.Tensor' id='139745955357904'>
- padding: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.BPMError(target: ~dipas.elements.Monitor, ax: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, ay: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, rx: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, ry: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, noise_scale: ~typing.Union[~typing.Sequence[~typing.Union[float, ~typing.Sequence[~typing.Union[float, ~typing.Sequence[float]]]]], <MagicMock name='mock.Tensor' id='139745955357904'>] = (1e-100, 1e-100))
Bases:
AlignmentError
BPM readout errors.
The actual BPM reading is computed as:
r * (x + a) + noise
. Herer
is the relative read error,a
is the absolute read error andnoise
is random Gaussian noise sampled according to the defined noise_scale.x
denotes the true position.- ax
Horizontal absolute read error.
- Type
Tensor or Parameter
- ay
Vertical absolute read error.
- Type
Tensor or Parameter
- rx
Horizontal relative read error.
- Type
Tensor or Parameter
- ry
Vertical relative read error.
- Type
Tensor or Parameter
- noise_scale
Tensor with two elements, denoting the noise scale in x- and y-dimension. On each
readout()
random Gaussian noise with the corresponding scale will be added.- Type
Tensor
- ax: Parameter' id='139745955712976'>]
- ay: Parameter' id='139745955712976'>]
- enter(x: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Applies linear coordinate transformation at the entrance of the wrapped element.
- exit(x: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Applies linear coordinate transformation at the exit of the wrapped element.
- noise_scale: <MagicMock name='mock.Tensor' id='139745955357904'>
- readout(x: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Return BPM readings subject to absolute and relative readout errors.
- Parameters
x (Tensor) – 6D phase-space coordinates of shape (6, N).
- Returns
xy – BPM readings in x- and y-dimension of shape (2, N).
- Return type
Tensor
See also
- rx: Parameter' id='139745955712976'>]
- ry: Parameter' id='139745955712976'>]
- triggers = ('mrex', 'mrey', 'mscalx', 'mscaly')
- class dipas.elements.Dipedge(h: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], e1: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], fint: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], hgap: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], he: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, *, entrance: bool = True, **kwargs)
Bases:
Element
Fringing fields at the entrance and exit of dipole magnets.
- Parameters
h (Number) – Curvature of the associated dipole magnet body.
e1 (Number) – The rotation angle of the pole face.
fint (Number) – The fringing field integral.
hgap (Number) – The half gap height of the associated dipole magnet.
he (Number) – The curvature of the pole face.
- e1: <MagicMock name='mock.Tensor' id='139745955357904'>
- fint: <MagicMock name='mock.Tensor' id='139745955357904'>
- h: <MagicMock name='mock.Tensor' id='139745955357904'>
- hgap: <MagicMock name='mock.Tensor' id='139745955357904'>
- makethin(n: int, *, style: Optional[str] = None) Union[Element, ThinElement]
Transform element to a sequence of n thin elements using the requested slicing style.
Important
If optimization of parameters is required then it is important to call makethin before each forward pass in order to always use the up-to-date parameter values from the original elements. Calling makethin only once at the beginning and then reusing the resulting sequence on every iteration would reuse the initial parameter values and hence make the optimization ineffective.
- Parameters
n (int) – The number of slices (thin elements).
style (str, optional) – The slicing style to be used. For available styles see
ThinElement.create_thin_sequence()
.
- Returns
A segment containing the slices (thin elements) separated by drifts.
- Return type
ThinElement
See also
ThinElement.create_thin_sequence()
- update_transfer_map(*, reset=False) None
Update the element’s transfer map coefficients (d, R, T) to correspond to the elements’ parameters.
This method should be called after any of the elements’ parameters have been modified in order to update the transfer map to correspond to the new values.
- Parameters
reset (bool) – If True then the tensors corresponding to transfer map coefficients are replaced by new tensor objects before their values are updated. In this case the resulting tensors guarantee to reflect any change in the elements attribute, parametrized and non-parametrized (see notes below).
Notes
This method guarantees to incorporate the values of all parameters but not for non-parameter attributes (such as the length of an element; these are only guaranteed to be incorporated if
reset=True
). Forreset=False
these non-parameter attributes might be reflected in the transfer map update but this is an implementation detail that should not be relied on. Even though this method is only relevant for elements that cache their transfer map and for others it is a no-op, this caching property also is an implementation detail that should not be relied on. Hence after having modified an element the update_transfer_map method should be called.
- class dipas.elements.Drift(l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], *, beam: dict, **kwargs)
Bases:
Element
Drift space.
Note
Unlike in MADX, drift spaces feature aperture checks here.
- Parameters
l (Number) – Length of the drift [m].
- exact(x)
Exact analytic solution for tracking through the element.
- l: <MagicMock name='mock.Tensor' id='139745955357904'>
- update_transfer_map(*, reset=False) None
Update the element’s transfer map coefficients (d, R, T) to correspond to the elements’ parameters.
This method should be called after any of the elements’ parameters have been modified in order to update the transfer map to correspond to the new values.
- Parameters
reset (bool) – If True then the tensors corresponding to transfer map coefficients are replaced by new tensor objects before their values are updated. In this case the resulting tensors guarantee to reflect any change in the elements attribute, parametrized and non-parametrized (see notes below).
Notes
This method guarantees to incorporate the values of all parameters but not for non-parameter attributes (such as the length of an element; these are only guaranteed to be incorporated if
reset=True
). Forreset=False
these non-parameter attributes might be reflected in the transfer map update but this is an implementation detail that should not be relied on. Even though this method is only relevant for elements that cache their transfer map and for others it is a no-op, this caching property also is an implementation detail that should not be relied on. Hence after having modified an element the update_transfer_map method should be called.
- class dipas.elements.HKicker(kick: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>], l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, *, beam: ~typing.Optional[dict] = None, **kwargs)
Bases:
Kicker
Horizontal kicker magnet.
- property kick: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.HMonitor(l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], *, beam: dict, **kwargs)
Bases:
Monitor
Beam position monitor for measuring horizontal beam position.
- l: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.Instrument(l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], *, beam: dict, **kwargs)
Bases:
Drift
A place holder for any type of beam instrumentation.
- l: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.Kicker(hkick: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, vkick: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, *, beam: ~typing.Optional[dict] = None, dkh: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, dkv: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, **kwargs)
Bases:
Element
Combined horizontal and vertical kicker magnet.
- Parameters
hkick (Number or Parameter) – Horizontal kick [rad].
vkick (Number or Parameter) – Vertical kick [rad].
dkh (Number or Parameter) – Horizontal absolute dipolar field error [rad].
dkv (Number or Parameter) – Vertical absolute dipolar field error [rad].
- property d: <MagicMock name='mock.Tensor' id='139745955357904'>
- field_errors = {'hkick': 'dkh', 'vkick': 'dkv'}
- hkick: Parameter' id='139745955712976'>]
- linear(x: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Linear tracking through the element.
- reset_transfer_map()
- second_order(x: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Second order tracking through the element.
- property transfer_map: ]
- vkick: Parameter' id='139745955712976'>]
- class dipas.elements.LongitudinalRoll(target: ~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError], psi: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0)
Bases:
AlignmentError
AlignmentError representing the roll about the longitudinal axis of an element.
Note
MADX uses a right-handed coordinate system (see Fig. 1.1, MADX User’s Guide), therefore
x = x*cos(psi) - y*sin(psi)
describes a clockwise rotation of the trajectory.- psi
Rotation angle about s-axis.
- Type
Number or Parameter
- property R_enter: <MagicMock name='mock.Tensor' id='139745955357904'>
- property R_exit: <MagicMock name='mock.Tensor' id='139745955357904'>
- psi: Parameter' id='139745955712976'>]
- triggers = ('dpsi',)
- class dipas.elements.Marker(**kwargs)
Bases:
Element
Marker element.
- exact(x: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Exact analytic solution for tracking through the element.
- l: <MagicMock name='mock.Tensor' id='139745955357904'>
- linear(x: <MagicMock name='mock.Tensor' id='139745955357904'>) <MagicMock name='mock.Tensor' id='139745955357904'>
Linear tracking through the element.
- class dipas.elements.Monitor(l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], *, beam: dict, **kwargs)
Bases:
Drift
Beam position monitor.
- l: <MagicMock name='mock.Tensor' id='139745955357904'>
- readout(x)
Return BPM readings for the given coordinates.
- Parameters
x (Tensor) – 6D phase-space coordinates of shape (6, N).
- Returns
xy – BPM readings in x- and y-dimension of shape (2, N).
- Return type
Tensor
- class dipas.elements.Offset(target: ~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError], dx: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, dy: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0)
Bases:
AlignmentError
AlignmentError representing the xy-offset of an element.
- dx
Horizontal offset.
- Type
Number or Parameter
- dy
Vertical offset.
- Type
Number or Parameter
- property d_enter: <MagicMock name='mock.Tensor' id='139745955357904'>
- property d_exit: <MagicMock name='mock.Tensor' id='139745955357904'>
- dx: Parameter' id='139745955712976'>]
- dy: Parameter' id='139745955712976'>]
- triggers = ('dx', 'dy')
- class dipas.elements.Placeholder(l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], *, beam: dict, **kwargs)
Bases:
Drift
A place holder for any type of element.
- l: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.Quadrupole(k1: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>], l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], *, beam: dict, dk1: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, **kwargs)
Bases:
Element
Quadrupole magnet.
Whether this is a (horizontally) focusing or defocusing magnet is determined from the value of k1 (k1 > 0 indicates a horizontally focusing quadrupole). Hence, in case k1 is a Parameter, it always must be non-zero. For that reason it is convenient to use boundaries e.g. [eps, k1_max] with a small number eps (e.g. 1e-16) and clip the value of k1 accordingly. If k1 is not a Parameter it can be zero and a corresponding Drift transformation will be used.
- Parameters
k1 (Number or Parameter) – Normalized quadrupole gradient strength [1/m^2].
dk1 (Number or Parameter) – Absolute error of k1 [1/m^2].
- field_errors = {'k1': 'dk1'}
- k1: Parameter' id='139745955712976'>]
- property k1l
- makethin(n: int, *, style: Optional[str] = None) Union[Quadrupole, ThinElement]
Transform element to a sequence of n thin elements using the requested slicing style.
Important
If optimization of parameters is required then it is important to call makethin before each forward pass in order to always use the up-to-date parameter values from the original elements. Calling makethin only once at the beginning and then reusing the resulting sequence on every iteration would reuse the initial parameter values and hence make the optimization ineffective.
- Parameters
n (int) – The number of slices (thin elements).
style (str, optional) – The slicing style to be used. For available styles see
ThinElement.create_thin_sequence()
.
- Returns
A segment containing the slices (thin elements) separated by drifts.
- Return type
ThinElement
See also
ThinElement.create_thin_sequence()
- update_transfer_map(*, reset=False) None
Update the element’s transfer map coefficients (d, R, T) to correspond to the elements’ parameters.
This method should be called after any of the elements’ parameters have been modified in order to update the transfer map to correspond to the new values.
- Parameters
reset (bool) – If True then the tensors corresponding to transfer map coefficients are replaced by new tensor objects before their values are updated. In this case the resulting tensors guarantee to reflect any change in the elements attribute, parametrized and non-parametrized (see notes below).
Notes
This method guarantees to incorporate the values of all parameters but not for non-parameter attributes (such as the length of an element; these are only guaranteed to be incorporated if
reset=True
). Forreset=False
these non-parameter attributes might be reflected in the transfer map update but this is an implementation detail that should not be relied on. Even though this method is only relevant for elements that cache their transfer map and for others it is a no-op, this caching property also is an implementation detail that should not be relied on. Hence after having modified an element the update_transfer_map method should be called.
- class dipas.elements.RBend(angle: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], e1: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, e2: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, fint: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, bool] = 0.0, fintx: ~typing.Optional[~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>]] = None, hgap: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, h1: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, h2: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, *, beam: dict, dk0: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, aperture: ~typing.Optional[~dipas.elements.Aperture] = None, label: ~typing.Optional[str] = None, **kwargs)
Bases:
SBend
Sector bending magnet with parallel pole faces (see
SBend
).
- class dipas.elements.SBend(angle: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], e1: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, e2: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, fint: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, bool] = 0.0, fintx: ~typing.Optional[~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>]] = None, hgap: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, h1: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, h2: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, *, beam: dict, dk0: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, aperture: ~typing.Optional[~dipas.elements.Aperture] = None, label: ~typing.Optional[str] = None, **kwargs)
Bases:
CompoundElement
Sector bending magnet.
- Parameters
angle (Number) – Bending angle of the dipole [rad].
e1 (Number) – Rotation angle for the entrance pole face [rad].
e1 = e2 = angle/2
turns an SBEND into a RBEND.e2 (Number) – Rotation angle for the exit pole face [rad].
fint (Number) – Fringing field integral at entrance. If fintx is not specified then fint is also used at the exit.
fintx (Number) – Fringing field integral at exit.
hgap (Number) – Half gap of the magnet [m].
h1 (Number) – Curvature of the entrance pole face [1/m].
h2 (Number) – Curvature of the exit pole face [1/m].
- property angle: <MagicMock name='mock.Tensor' id='139745955357904'>
- property dk0: <MagicMock name='mock.Tensor' id='139745955357904'>
- property e1: <MagicMock name='mock.Tensor' id='139745955357904'>
- property e2: <MagicMock name='mock.Tensor' id='139745955357904'>
- field_errors = {'k0': 'dk0'}
- property fint: <MagicMock name='mock.Tensor' id='139745955357904'>
- property fintx: <MagicMock name='mock.Tensor' id='139745955357904'>
- flatten() Iterator[SBend]
Retrieve a flat representation of the segment (with sub-segments flattened as well).
- property h1: <MagicMock name='mock.Tensor' id='139745955357904'>
- property h2: <MagicMock name='mock.Tensor' id='139745955357904'>
- property hgap: <MagicMock name='mock.Tensor' id='139745955357904'>
- property k0: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.SBendBody(angle: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], *, beam: dict, dk0: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, **kwargs)
Bases:
Element
The body of a sector bending magnet.
- Parameters
angle (Number) – Bending angle of the dipole [rad].
dk0 (Number) – Normalized dipole field error [rad/m].
- angle: <MagicMock name='mock.Tensor' id='139745955357904'>
- field_errors = {'k0': 'dk0'}
- property k0: <MagicMock name='mock.Tensor' id='139745955357904'>
- makethin(n: int, *, style: Optional[str] = None) Union[Element, ThinElement]
Transform element to a sequence of n thin elements using the requested slicing style.
Important
If optimization of parameters is required then it is important to call makethin before each forward pass in order to always use the up-to-date parameter values from the original elements. Calling makethin only once at the beginning and then reusing the resulting sequence on every iteration would reuse the initial parameter values and hence make the optimization ineffective.
- Parameters
n (int) – The number of slices (thin elements).
style (str, optional) – The slicing style to be used. For available styles see
ThinElement.create_thin_sequence()
.
- Returns
A segment containing the slices (thin elements) separated by drifts.
- Return type
ThinElement
See also
ThinElement.create_thin_sequence()
- update_transfer_map(*, reset=False) None
Update the element’s transfer map coefficients (d, R, T) to correspond to the elements’ parameters.
This method should be called after any of the elements’ parameters have been modified in order to update the transfer map to correspond to the new values.
- Parameters
reset (bool) – If True then the tensors corresponding to transfer map coefficients are replaced by new tensor objects before their values are updated. In this case the resulting tensors guarantee to reflect any change in the elements attribute, parametrized and non-parametrized (see notes below).
Notes
This method guarantees to incorporate the values of all parameters but not for non-parameter attributes (such as the length of an element; these are only guaranteed to be incorporated if
reset=True
). Forreset=False
these non-parameter attributes might be reflected in the transfer map update but this is an implementation detail that should not be relied on. Even though this method is only relevant for elements that cache their transfer map and for others it is a no-op, this caching property also is an implementation detail that should not be relied on. Hence after having modified an element the update_transfer_map method should be called.
- class dipas.elements.Segment(elements: Sequence[Union[CompactElement, PartitionedElement, Element, AlignmentError]])
Bases:
object
Wrapper class representing a sequence of elements (possibly a segment of the lattice).
Elements or sub-segments can be selected via __getitem__, i.e.
segment[item]
notation. Here item can be one of the following:int - indicating the index position in the segment.
str - will be compared for equality against element labels; if a single element with that label is found it is returned otherwise all elements with that label are returned as a list. An exception are strings containing an asterisk which will be interpreted as a shell-style wildcard and converted to a corresponding regex Pattern.
re.Pattern - will be matched against element labels; a list of all matching elements is returned.
instance of
Element
orAlignmentError
- the element itself (possibly wrapped by other AlignmentError instances is returned.subclass of
Element
orAlignmentError
- a list of elements of that type (possibly wrapped by AlignmentError instances) is returned.tuple - must contain two elements, the first being one of the above types and the second an integer; the first element is used to select a list of matching elements and the second integer element is used to select the corresponding element from the resulting list.
slice - start and stop indices can be any of the above types that selects exactly a single element or None; a corresponding sub-Segment is returned. The step parameter of the slice is ignored. In case the stop marker is not None, the corresponding element is included in the selection.
The
GETITEM_CASE_SENSITIVE
class- or instance-level attribute controls whether lookups with strings (without wildcards*
) are case sensitive or not. If no element is found, then aElementNotFoundError
is raised.An element of a segment can be updated by using __setitem__, i.e.
segment[item] = ...
notation, where item can be any of the above types that selects exactly a single element.- elements
- Type
list of
LatticeElement
- GETITEM_CASE_SENSITIVE = True
- apply_unique_labels() None
Ensure that every element in the lattice has a unique label.
If an element’s label is None it will be replaced by a string indicating its position, e.g.
e5
for the fifth element. If an element’s label already appeared before then it will be augmented by_{i+1}
wherei
is the number of times this label has appeared already.This method modifies the element labels in-place.
- Raises
RuntimeError – If the algorithm cannot find a unique labeling, e.g. if labels are
['a', 'a_2', 'a']
then for the last element the algorithm attempts to usea_2
however this label appeared already one element before.
- compute_transfer_maps(method: typing_extensions.Literal[accumulate, reduce, local], *, order: typing_extensions.Literal[1, 2] = 2, index: ~typing.Optional[typing_extensions.Literal[0, 1, 2]] = None, symplectify: bool = True, unfold_alignment_errors: bool = False, d0: ~typing.Optional[<MagicMock name='mock.Tensor' id='139745955357904'>] = None, R0: ~typing.Optional[<MagicMock name='mock.Tensor' id='139745955357904'>] = None, T0: ~typing.Optional[<MagicMock name='mock.Tensor' id='139745955357904'>] = None) ]]
Compute the transfer maps of the element.
- Parameters
method (str) – Determines how the transfer maps are computed (for details see implementing class).
order (int) – Transfer map order used in computations.
index (int) – Only transfer map coefficients up to the specified index are stored in the results; others are None. If None then defaults to order.
symplectify (bool) – Whether to symplectify the first order coefficients (transfer matrix) after second order feed-down terms have been included.
unfold_alignment_errors (bool) – Whether to treat alignment error transformations as separate transfer maps rather than contracting them with the wrapped lattice element.
d0 (Tensor) – Starting values at the beginning of the element (
d0
corresponds to the closed orbit value).R0 (Tensor) – Starting values at the beginning of the element (
d0
corresponds to the closed orbit value).T0 (Tensor) – Starting values at the beginning of the element (
d0
corresponds to the closed orbit value).
- Yields
transfer_map (
TransferMap
) – Depending on the selected method.
- exact(x: <MagicMock name='mock.Tensor' id='139745955357904'>, **kwargs) Tuple]
Exact tracking through the segment.
- flatten() Iterator[Union[CompactElement, PartitionedElement, Element, AlignmentError]]
Retrieve a flat representation of the segment (with sub-segments flattened as well).
- forward(x: <MagicMock name='mock.Tensor' id='139745955357904'>, *, method: ~typing.Union[str, ~typing.Callable[[<MagicMock name='mock.Tensor' id='139745955357904'>], <MagicMock name='mock.Tensor' id='139745955357904'>], ~typing.Tuple[~typing.Optional[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]], int, ~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError, ~typing.Tuple[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]]], int]]], ~typing.Union[str, ~typing.Callable[[<MagicMock name='mock.Tensor' id='139745955357904'>], <MagicMock name='mock.Tensor' id='139745955357904'>]]], ~typing.List[~typing.Tuple[~typing.Optional[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]], int, ~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError, ~typing.Tuple[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]]], int]]], ~typing.Union[str, ~typing.Callable[[<MagicMock name='mock.Tensor' id='139745955357904'>], <MagicMock name='mock.Tensor' id='139745955357904'>]]]], ~typing.Dict[~typing.Optional[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]], int, ~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError, ~typing.Tuple[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]]], int]]], ~typing.Union[str, ~typing.Callable[[<MagicMock name='mock.Tensor' id='139745955357904'>], <MagicMock name='mock.Tensor' id='139745955357904'>]]]], aperture: bool = False, exact_drift: bool = True, observe: ~typing.Optional[~typing.Union[bool, int, str, ~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError, ~typing.Tuple[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]]], int], ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]], ~typing.List[~typing.Union[int, str, ~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError, ~typing.Tuple[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]]], int], ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]]]]]] = None, recloss: ~typing.Optional[~typing.Union[bool, int, str, ~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError, ~typing.Tuple[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]]], int], ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]], ~typing.List[~typing.Union[int, str, ~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError, ~typing.Tuple[~typing.Union[str, ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]]], int], ~typing.Pattern, ~typing.Type[~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError]]]]]] = None, loss_func: ~typing.Optional[~typing.Callable[[<MagicMock name='mock.Tensor' id='139745955357904'>], <MagicMock name='mock.Tensor' id='139745955357904'>]] = None) Tuple]
Track the given particles through the segment.
- Parameters
x (Tensor) – Shape (6, N) where N is the number of particles.
method (
SelectionCriteria
of str or callable) – Method name which will be used for the lattice elements to perform tracking.aperture (bool) – Determines whether aperture checks are performed (and thus particles marked lost / excluded from tracking).
exact_drift (bool) – If true (default) then Drift`s will always be tracked through via `exact, no matter what method is.
observe (sequence of {str or re.Pattern or subclass of Element}) – Indicates relevant observation points; the (intermediary) positions at these places will be returned. Items are matched against element labels (see function match_element).
recloss (bool or “sum” or {str or re.Pattern or subclass of Element} or a sequence thereof) – If “sum” then the particle loss at each element will be recorded and summed into a single variable which will be returned. If a sequence is given it must contain element labels or regex patterns and the loss will be recorded only at the corresponding elements (similar to observe for positions). If True then the loss will be recorded at all elements; if False the loss is not recorded at all. A true value for this parameter will automatically set aperture to True.
loss_func (callable) – This parameter can be used to supply a function for transforming the returned loss at each element. This can be useful if some variation of the loss is to be accumulated into a single tensor. The function receives the loss tensor as returned by Aperture.loss as an input and should return a tensor of any shape. If not supplied this function defaults to torch.sum if recloss == “accumulate” and the identity if
recloss == "history"
. Note that if a function is supplied it needs to cover all the steps, also the summation in caserecloss == "accumulate"
(the default only applies if no function is given).
- Returns
x (Tensor) – Shape (6, M) where M is the number of particles that reached the end of the segment (M can be different from N in case aperture checks are performed).
history (dict) – The (intermediary) positions at the specified observation points. Keys are element labels and values are positions of shape (6, M_i) where M_i is the number of particles that reached that element. This is only returned if observe is true.
loss (Tensor or dict) – If
recloss == "accumulate"
the loss value accumulated for each element (i.e. the sum of all individual loss values) is returned. Otherwise, if recloss is true, a dict mapping element labels to recorded loss values is returned.
- get_element_index(marker: Union[int, str, CompactElement, PartitionedElement, Element, AlignmentError, Tuple[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]]], int]]) int
- insert(index: int, element: Union[CompactElement, PartitionedElement, Element, AlignmentError])
Insert a lattice element at the specified position.
The difference to
segment.elements.insert(index, element)
is, that this method also sets the given element as an instance attribute. This becomes important if the element contains any parameters to be used during optimization. Otherwise there is no difference in behavior.- Parameters
index (int) – The index position where to insert the element.
element (LatticeElement) – The lattice element to be inserted.
- property l: <MagicMock name='mock.Tensor' id='139745955357904'>
- linear(x: <MagicMock name='mock.Tensor' id='139745955357904'>, **kwargs) Tuple]
Linear tracking through the segment.
- makethin(n: Union[int, Tuple[Optional[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]], int, CompactElement, PartitionedElement, Element, AlignmentError, Tuple[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]]], int]]], int], List[Tuple[Optional[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]], int, CompactElement, PartitionedElement, Element, AlignmentError, Tuple[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]]], int]]], int]], Dict[Optional[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]], int, CompactElement, PartitionedElement, Element, AlignmentError, Tuple[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]]], int]]], int]], *, style: Optional[Union[str, Tuple[Optional[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]], int, CompactElement, PartitionedElement, Element, AlignmentError, Tuple[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]]], int]]], str], List[Tuple[Optional[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]], int, CompactElement, PartitionedElement, Element, AlignmentError, Tuple[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]]], int]]], str]], Dict[Optional[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]], int, CompactElement, PartitionedElement, Element, AlignmentError, Tuple[Union[str, Pattern, Type[Union[CompactElement, PartitionedElement, Element, AlignmentError]]], int]]], str]]] = None) Segment
Retrieve a thin representation for each element of the segment except for those indicated by exclude.
- Parameters
n (
SelectionCriteria
of int) –Number of thin slices. If int this applies to all elements. Otherwise must key-value pairs. Keys should be element selectors (see
SingleElementSelector
andMultiElementSelector
) or None for providing a default. Values should be the corresponding number of slices that are applied to the elements that match the key selector. Only the first matching key is considered. If a default value is desired it can be provided in various ways:Using
{None: default_value}
.Using a regex that matches any label (given that all elements have a label different from None).
Using the class Element.
Note that for all options these should appear at the very end of the list of criteria, otherwise they will override any subsequent definitions.
style (
SelectionCriteria
of str) – Slicing style per element. Works similar to the n parameter. SeeElement.makethin()
for more information about available slicing styles.
- Returns
Containing thin elements.
- Return type
See also
find_matching_criterion()
For details about how keys in n can be used to fine-tune the slice number per element.
Element.makethin()
For available slicing styles.
- second_order(x: <MagicMock name='mock.Tensor' id='139745955357904'>, **kwargs) Tuple]
Second order tracking through the segment.
- squeeze(*, labeler: ~typing.Callable[[~typing.List[str]], str] = <built-in method join of str object>) Segment
Return a new segment with consecutive :class:`Drift`s in the original segment being merged into one.
All other elements remain the same as in the original segment. The merged drift space’s length is adjusted via
merged_drift.l += drift.l
for each of the consecutive drifts, i.e. any parameter relations are retained. The label of the merged drift is computed via the labeler parameter.- Parameters
labeler (callable, optional) – A function that computes the new label of the merged drift from the individual labels of the single drifts. This function receives a list of individual labels and should return the new label as a string. Defaults to joining all individual labels by
"_"
.- Returns
segment – The new segment with merged drifts.
- Return type
- transfer_maps(method: typing_extensions.Literal[accumulate, reduce, local], *, order: typing_extensions.Literal[1, 2] = 2, indices: ~typing.Optional[~typing.Union[typing_extensions.Literal[0, 1, 2], ~typing.Tuple[typing_extensions.Literal[0, 1, 2], ...]]] = None, symplectify: bool = True, labels: bool = False, unfold_alignment_errors: bool = False, d0: ~typing.Optional[<MagicMock name='mock.Tensor' id='139745955357904'>] = None, R0: ~typing.Optional[<MagicMock name='mock.Tensor' id='139745955357904'>] = None, T0: ~typing.Optional[<MagicMock name='mock.Tensor' id='139745955357904'>] = None) ]]]]
Process the transfer maps of the segment’s elements according to the specified method.
Note
This does not automatically compute the closed orbit first in order to use it as a starting value for d0. In that case, the closed orbit has to be provided manually in form of the parameter d0.
- Parameters
method (str in {'accumulate', 'reduce', 'local'}) – If “accumulate” then the transfer maps are accumulated by contracting subsequent transfer maps. If “reduce” then the contracted transfer map for the complete segment is returned (this is identical to the last transfer map for “accumulate”). If “local” then the local transfer map of each element is computed, taking into consideration the value of the local closed orbit. The result contains the closed orbit at the exit of each element as the zeroth order coefficient.
order (int) – The order up to which transfer map coefficients (d, R, T) are taken into account for the contraction of two subsequent transfer maps.
indices (int or tuple of int) – Indicates the indices of the processed transfer maps which should be stored in the results. If a single number is given, all indices up to the specified number (inclusive) are considered. E.g. if
indices = 0
andmethod = 'reduce'
then the result will be justd
whered
is the orbit computed to second order but the resulting first and second order coefficients of the reduced transfer maps are discarded. Discarding coefficients of higher orders in the (intermediary) results can save memory and compute time. Note thatmax(indices) <= order
must be fulfilled.symplectify (bool) – Specifies whether the linear term (the transfer matrix) of lattice elements should be symplectified after the addition of second-order feed-down terms. This is only relevant for
order >= 2
.labels (bool) – If True then the element’s labels are returned alongside their transfer maps as 2-tuples (for
method = "reduce"
this parameter is ignored). In case unfold_alignment_errors is True as well, an element’s label is repeated for each alignment error map (at entrance and exit), e.g. for an offset element “e1” it will be[..., ("e1", entrance_map), ("e1", element_map), ("e1", exit_map), ...]
.unfold_alignment_errors (bool) – If True then the entrance and exit transformations of alignment errors are considered as separate transfer maps rather than being contracted with their wrapped element’s map. This increases the number of transfer maps as compared to the length of the segment.
d0 (Tensor, optional) – The value of the closed orbit at the beginning of the segment.
R0 (Tensor, optional) – Initial value for the first order terms.
T0 (Tensor, optional) – Initial value for the second order terms.
- Returns
transfer_maps –
- Depending on the value of method either of the following is returned:
”accumulate” – a list of the accumulated transfer maps along the lattice is returned.
”reduce” – the single transfer map, corresponding to the whole segment, is returned.
”local” – a list of the element-local transfer maps is returned.
- Return type
TransferMap
or list ofTransferMap
- update_transfer_maps(*, reset=False) None
Update the transfer map of each element (see
CompactElement.update_transfer_map()
).
- class dipas.elements.Sextupole(k2: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>], l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], *, beam: dict, dk2: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, **kwargs)
Bases:
Element
Sextupole magnet.
- Parameters
k2 (Number or Parameter) – Normalized sextupole coefficient [1/m^3].
dk2 (Number or Parameter) – Absolute error of k2 [1/m^3].
- field_errors = {'k2': 'dk2'}
- k2: Parameter' id='139745955712976'>]
- makethin(n: int, *, style: Optional[str] = None) Union[Sextupole, ThinElement]
Transform element to a sequence of n thin elements using the requested slicing style.
Important
If optimization of parameters is required then it is important to call makethin before each forward pass in order to always use the up-to-date parameter values from the original elements. Calling makethin only once at the beginning and then reusing the resulting sequence on every iteration would reuse the initial parameter values and hence make the optimization ineffective.
- Parameters
n (int) – The number of slices (thin elements).
style (str, optional) – The slicing style to be used. For available styles see
ThinElement.create_thin_sequence()
.
- Returns
A segment containing the slices (thin elements) separated by drifts.
- Return type
ThinElement
See also
ThinElement.create_thin_sequence()
- update_transfer_map(*, reset=False) None
Update the element’s transfer map coefficients (d, R, T) to correspond to the elements’ parameters.
This method should be called after any of the elements’ parameters have been modified in order to update the transfer map to correspond to the new values.
- Parameters
reset (bool) – If True then the tensors corresponding to transfer map coefficients are replaced by new tensor objects before their values are updated. In this case the resulting tensors guarantee to reflect any change in the elements attribute, parametrized and non-parametrized (see notes below).
Notes
This method guarantees to incorporate the values of all parameters but not for non-parameter attributes (such as the length of an element; these are only guaranteed to be incorporated if
reset=True
). Forreset=False
these non-parameter attributes might be reflected in the transfer map update but this is an implementation detail that should not be relied on. Even though this method is only relevant for elements that cache their transfer map and for others it is a no-op, this caching property also is an implementation detail that should not be relied on. Hence after having modified an element the update_transfer_map method should be called.
- class dipas.elements.TKicker(hkick: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, vkick: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, *, beam: ~typing.Optional[dict] = None, dkh: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, dkv: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, **kwargs)
Bases:
Kicker
Similar to Kicker (see Chapter 10.12, MADX User’s Guide).
- hkick: Parameter' id='139745955712976'>]
- l: <MagicMock name='mock.Tensor' id='139745955357904'>
- vkick: Parameter' id='139745955712976'>]
- class dipas.elements.ThinQuadrupole(k1l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>], *, dk1l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, **kwargs)
Bases:
Element
Thin lens representation of a quadrupole magnet.
- Parameters
k1l (Number or Parameter) – Integrated quadrupole gradient strength [1/m].
dk1l (Number or Parameter) – Absolute error of k1l [1/m].
- field_errors = {'k1l': 'dk1l'}
- k1l: Parameter' id='139745955712976'>]
- makethin(n: int, *, style: Optional[str] = None) NoReturn
Transform element to a sequence of n thin elements using the requested slicing style.
Important
If optimization of parameters is required then it is important to call makethin before each forward pass in order to always use the up-to-date parameter values from the original elements. Calling makethin only once at the beginning and then reusing the resulting sequence on every iteration would reuse the initial parameter values and hence make the optimization ineffective.
- Parameters
n (int) – The number of slices (thin elements).
style (str, optional) – The slicing style to be used. For available styles see
ThinElement.create_thin_sequence()
.
- Returns
A segment containing the slices (thin elements) separated by drifts.
- Return type
ThinElement
See also
ThinElement.create_thin_sequence()
- update_transfer_map(*, reset=False) None
Update the element’s transfer map coefficients (d, R, T) to correspond to the elements’ parameters.
This method should be called after any of the elements’ parameters have been modified in order to update the transfer map to correspond to the new values.
- Parameters
reset (bool) – If True then the tensors corresponding to transfer map coefficients are replaced by new tensor objects before their values are updated. In this case the resulting tensors guarantee to reflect any change in the elements attribute, parametrized and non-parametrized (see notes below).
Notes
This method guarantees to incorporate the values of all parameters but not for non-parameter attributes (such as the length of an element; these are only guaranteed to be incorporated if
reset=True
). Forreset=False
these non-parameter attributes might be reflected in the transfer map update but this is an implementation detail that should not be relied on. Even though this method is only relevant for elements that cache their transfer map and for others it is a no-op, this caching property also is an implementation detail that should not be relied on. Hence after having modified an element the update_transfer_map method should be called.
- class dipas.elements.ThinSextupole(k2l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>], *, dk2l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0, **kwargs)
Bases:
Element
Thin lens representation of a sextupole magnet.
- Parameters
k2l (Number or Parameter) – Integrated sextupole coefficient [1/m^2].
dk2l (Number or Parameter) – Absolute error of k2l [1/m^2].
- field_errors = {'k2l': 'dk2l'}
- k2l: Parameter' id='139745955712976'>]
- makethin(n: int, *, style: Optional[str] = None) NoReturn
Transform element to a sequence of n thin elements using the requested slicing style.
Important
If optimization of parameters is required then it is important to call makethin before each forward pass in order to always use the up-to-date parameter values from the original elements. Calling makethin only once at the beginning and then reusing the resulting sequence on every iteration would reuse the initial parameter values and hence make the optimization ineffective.
- Parameters
n (int) – The number of slices (thin elements).
style (str, optional) – The slicing style to be used. For available styles see
ThinElement.create_thin_sequence()
.
- Returns
A segment containing the slices (thin elements) separated by drifts.
- Return type
ThinElement
See also
ThinElement.create_thin_sequence()
- update_transfer_map(*, reset=False) None
Update the element’s transfer map coefficients (d, R, T) to correspond to the elements’ parameters.
This method should be called after any of the elements’ parameters have been modified in order to update the transfer map to correspond to the new values.
- Parameters
reset (bool) – If True then the tensors corresponding to transfer map coefficients are replaced by new tensor objects before their values are updated. In this case the resulting tensors guarantee to reflect any change in the elements attribute, parametrized and non-parametrized (see notes below).
Notes
This method guarantees to incorporate the values of all parameters but not for non-parameter attributes (such as the length of an element; these are only guaranteed to be incorporated if
reset=True
). Forreset=False
these non-parameter attributes might be reflected in the transfer map update but this is an implementation detail that should not be relied on. Even though this method is only relevant for elements that cache their transfer map and for others it is a no-op, this caching property also is an implementation detail that should not be relied on. Hence after having modified an element the update_transfer_map method should be called.
- class dipas.elements.Tilt(target: ~typing.Union[~dipas.elements.CompactElement, ~dipas.elements.PartitionedElement, ~dipas.elements.Element, ~dipas.elements.AlignmentError], psi: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>] = 0)
Bases:
LongitudinalRoll
The tilt of an element represents the roll about the longitudinal axis.
Note
MADX uses a right-handed coordinate system (see Fig. 1.1, MADX User’s Guide), therefore
x = x*cos(psi) - y*sin(psi)
describes a clockwise rotation of the trajectory.- psi
Rotation angle about s-axis.
- Type
Number or Parameter
Notes
Tilt is only a subclass of AlignmentError for technical reasons and has no meaning beyond that. A Tilt is not considered an alignment error from the simulation point of view.
- psi: Parameter' id='139745955712976'>]
- triggers = ('tilt',)
- class dipas.elements.VKicker(kick: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>, <MagicMock name='mock.nn.Parameter' id='139745955712976'>], l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>] = 0, *, beam: ~typing.Optional[dict] = None, **kwargs)
Bases:
Kicker
Vertical kicker magnet.
- property kick: <MagicMock name='mock.Tensor' id='139745955357904'>
- class dipas.elements.VMonitor(l: ~typing.Union[int, float, <MagicMock name='mock.Tensor' id='139745955357904'>], *, beam: dict, **kwargs)
Bases:
Monitor
Beam position monitor for measuring horizontal beam position.
- l: <MagicMock name='mock.Tensor' id='139745955357904'>
- dipas.elements.configure(*, transfer_map_order: Optional[typing_extensions.Literal[1, 2]] = None) None
Configure element classes globally.
- Parameters
transfer_map_order (int) – Set the order of truncation for transfer map coefficients (see
Element
).