particleflow.build module¶
Functionality for building an accelerator lattice using PyTorch as a backend.
-
particleflow.build.
from_file
(f_name: str, *, beam: dict = None, errors: Union[bool, <MagicMock name='mock.DataFrame' id='140244238855472'>] = True, padding: Union[float, Tuple[float, ...], Dict[Union[str, Pattern[AnyStr], Type[Element], None], Union[float, Tuple[float, ...]]]] = None) → particleflow.elements.Segment¶ Build lattice from MADX script file.
Uses the first beam command and the first sequence encountered via USE when parsing the script. If no USE command is found then the first SEQUENCE in the script is considered.
- Parameters
f_name (str) – File path pointing to the MADX script.
beam (dict, optional) – Beam specification similar to the MADX command beam. If not provided then the script will be searched for a beam command instead. Otherwise the user provided beam specification will override any specification in the script.
errors (bool or str) –
- Whether and how to assign alignment errors to lattice elements. The following options are available:
False - Ignore error specifications in the script.
True - Apply error specifications from the script, interpreting any involved expressions. In case no random functions are involved in error specification the final values will be the same (when comparing the thus built lattice and MADX). However if random functions are involved then, even if the same seed for the random number generator (RNG) is used, the final values are likely to differ because MADX uses a different RNG than the present parser. Hence this option will result in alignment errors for the same elements and values from the same random variates, but not exactly the same values.
- pd.DataFrame - For details about the structure see
apply_errors()
. Using a data frame the exact same values (from MADX) will be assigned. In order to ensure compatibility across multiple runs of the script, make sure to also set
eoption, seed = <rng_seed>
.
- pd.DataFrame - For details about the structure see
padding (float or tuple or dict) – Additional padding applied to lattice elements. See
elements.Aperture
.
- Returns
lattice
- Return type
-
particleflow.build.
from_script
(script: str, *, beam: dict = None, errors: Union[bool, <MagicMock name='mock.DataFrame' id='140244238855472'>] = True, padding: Union[float, Tuple[float, ...], Dict[Union[str, Pattern[AnyStr], Type[Element], None], Union[float, Tuple[float, ...]]]] = None) → particleflow.elements.Segment¶ Build lattice from MADX script (for details see
from_file()
).
-
particleflow.build.
create_script
(beam: dict, *, sequence: Union[str, particleflow.elements.Segment], track: str = '', errors: str = '') → str¶ Create a MADX script that can be used for particle tracking in the given sequence.
Note
The sequence string must start with the sequence’s label.
- Parameters
beam (dict) – Beam configuration that will be transformed to the “beam” command.
sequence (str or Segment) – Part of the script describing the sequence.
track (str) – Part of the script describing the tracking.
errors (str) – Part of the script describing error definitions.
- Returns
script – The compound MADX script.
- Return type
str
- Raises
SerializerError – If the sequence string does not start with a label.
-
particleflow.build.
sequence_script
(lattice: particleflow.elements.Segment, label: str = 'seq', *, markup: str = 'madx') → str¶ Convert the given lattice to a corresponding MADX sequence script or HTML file.
Important
The sequence must not assume implicit drift spaces; elements are laid out as presented.
- Parameters
lattice (Segment) – The lattice to be converted. Elements are placed one after another (no implicit drifts).
label (str, optional) – The label of the sequence to be used in the script.
markup (str, optional) – The markup language which is used for dumping the sequence; one of {“madx”, “html”}.
- Returns
script
- Return type
str
-
particleflow.build.
error_script
(lattice: particleflow.elements.Segment) → str¶ Convert error definitions in form of AlignmentError to a corresponding MADX script.
Important
Elements which have associated errors must have a (unique) label (uniqueness is not checked for).
- Parameters
lattice (Segment) –
- Returns
script – The corresponding MADX statements for assigning the associated errors.
- Return type
str
- Raises
SerializerError – If an element with associated errors has no label.
-
particleflow.build.
track_script
(particles: Union[<MagicMock name='mock.ndarray' id='140244239839752'>, <MagicMock name='mock.Tensor' id='140244238396048'>], observe: Sequence[str], aperture: bool = True, recloss: bool = True, turns: int = 1, maxaper: Union[tuple, list] = (0.1, 0.01, 0.1, 0.01, 1.0, 0.1)) → str¶ Convert particle array / tensor to corresponding MADX track script.
Uses
onetable = true
and hence the results will be available at the file “trackone”.- Parameters
particles (array) – Array / tensor of shape (6, N) where N is the number of particles.
observe (list or tuple) – Labels of places where to observe.
aperture (bool) –
recloss (bool) –
turns (int) –
maxaper (tuple or list) –
- Returns
script
- Return type
str