core.accelerator.accelerator module
Define Accelerator
, the highest-level class of LightWin.
It holds, well… an accelerator. This accelerator has a
ListOfElements
. For each BeamCalculator
defined, it has a
SimulationOutput
. Additionally, it has a
ParticleInitialState
, which describes energy, phase, etc of the beam
at the entry of its ListOfElements
.
Todo
Compute_transfer_matrices: simplify, add a calculation of missing phi_0 at the end
Todo
Cleaner Accelerator factory (use class, not just a function).
- class Accelerator(name: str, dat_file: Path, accelerator_path: Path, list_of_elements_factory: ListOfElementsFactory)
Bases:
object
Class holding a
ListOfElements
.- __init__(name: str, dat_file: Path, accelerator_path: Path, list_of_elements_factory: ListOfElementsFactory) None
Create object.
- Parameters:
name (str) – Name of the accelerator, used in plots.
dat_file (Path) – Absolute path to the linac
.dat
file.accelerator_path (Path) – Absolute path where results for each
BeamCalculator
will be stored.list_of_elements_factory (ListOfElementsFactory) – A factory to create the list of elements.
- _create_special_getters() dict
Create a dict of aliases that can be accessed w/ the get method.
- elt_at_this_s_idx(s_idx: int, show_info: bool = False) Element | None
Give the element where the given index is.
- equivalent_elt(elt: Element | str) Element
Return element from
self.elts
with the same name aselt
.
- classmethod from_pickle(pickler: MyPickler, path: Path | str) Self
Instantiate object from previously pickled file.
- get(*keys: str, to_numpy: bool = True, none_to_nan: bool = False, elt: str | Element | None = None, **kwargs: bool | str) Any
Shorthand to get attributes from this class or its attributes.
- Parameters:
*keys (str) – Name of the desired attributes.
to_numpy (bool, optional) – If you want the list output to be converted to a np.ndarray. The default is True.
none_to_nan (bool, optional) – To convert None to np.nan. The default is False.
elt (str | Element | None, optional) – If provided, and if the desired keys are in SimulationOutput, the attributes will be given over the Element only. You can provide an Element name, such as
QP1
. If the given Element is not in the Accelerator.ListOfElements, the Element with the same name that is present in this list will be used.**kwargs (bool | str) – Other arguments passed to recursive getter.
- Returns:
out – Attribute(s) value(s).
- Return type:
Any
- has(key: str) bool
Tell if the required attribute is in this class.
- keep_settings(simulation_output: SimulationOutput, output_phase: str) None
Save cavity parameters in Elements and new .dat file.
Todo
Should I reset the sync particle entry phase?
- keep_simulation_output(simulation_output: SimulationOutput, beam_calculator_id: str) None
Save
SimulationOutput
. Store info on currentAccelerator
in it.In particular, we want to save a results path in the
SimulationOutput
so we can study it and save Figures/study results in the proper folder.
- property l_cav
Shortcut to easily get list of cavities.