core.instructions_factory module
Define methods to easily create Command
or Element
.
Todo
Instantiate this in BeamCalculator
. It could be initialized with
the load_electromagnetic_files
flag (False for TraceWin), the list of
implemented elements/commands (ex Envelope3D, not everything is set).
Todo
maybe ElementFactory and CommandFactory should be instantiated from this? Or from another class, but they do have a lot in common
Todo
for now, forcing loading of cython field maps
- class InstructionsFactory(freq_bunch_mhz: float, default_field_map_folder: Path, load_field_maps: bool, field_maps_in_3d: bool, load_cython_field_maps: bool, elements_to_dump: ABCMeta | tuple[ABCMeta, ...] = (), **factory_kw: Any)
Bases:
object
Define a factory class to easily create commands and elements.
- __init__(freq_bunch_mhz: float, default_field_map_folder: Path, load_field_maps: bool, field_maps_in_3d: bool, load_cython_field_maps: bool, elements_to_dump: ABCMeta | tuple[ABCMeta, ...] = (), **factory_kw: Any) None
Instantiate the command and element factories.
- Parameters:
freq_bunch_mhz (float) – Beam bunch frequency in MHz.
default_field_map_folder (Path) – Where to look for field maps when no
FIELD_MAP_PATH
is precised. This is also the folder where the.dat
is.load_field_maps (bool) – To load or not the field maps (useless to do it with
TraceWin
).field_maps_in_3d (bool) – To load or not the field maps in 3D (useful only with
Envelope3D
… Except that this is not supported yet, so it is never useful.load_cython_field_maps (bool) – To load or not the field maps for Cython (useful only with
Envelope1D
andEnvelope3D
used with Cython).elements_to_dump (ABCMeta | tuple[ABCMeta, ...], optional) – Class of Elements that you want to remove. If you want to skip an Element because it is not implemented, prefer assigning it to a
DummyElement
. The default is an empty tuple.factory_kw (Any) – Other parameters passed to the
CommandFactory
andElementFactory
.
- _call_proper_factory(line: list[str], dat_idx: int, **instruction_kw: str) Instruction
Create proper
Instruction
, orDummy
.We go across every word of
line
, and create the first instruction that we find. If we do not recognize it, we return a dummy instruction instead.- Parameters:
line (list[str]) – A single line of the
.dat
file.dat_idx (int) – Line number of the line (starts at 0).
command_fac (CommandFactory) – A factory to create
Command
.element_fac (ElementFactory) – A factory to create
Element
.instruction_kw (dict) – Keywords given to the
run
method of the proper factory.
- Returns:
- Return type:
- _check_every_elt_has_lattice_and_section(elts: list[Element]) None
Check that every element has a lattice and section index.
- _check_last_lattice_of_every_lattice_is_complete(elts: Sequence[Element]) None
Check that last lattice of every section is complete.
- _handle_lattice_and_section(elts: list[Element]) None
Ensure that every element has proper lattice, section indexes.
- run(dat_content: Collection[list[str]]) list[Instruction]
Create all the elements and commands.
Todo
Check if the return value from
apply_commands
is necessary.- Parameters:
dat_content (Collection[list[str]]) – List containing all the lines of
dat_filepath
.