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

class InstructionsFactory(freq_bunch_mhz, default_field_map_folder, load_field, field_maps_in_3d, load_cython_field_maps, elements_to_dump=(), **factory_kw)[source]

Bases: object

Define a factory class to easily create commands and elements.

Parameters:
__init__(freq_bunch_mhz, default_field_map_folder, load_field, field_maps_in_3d, load_cython_field_maps, elements_to_dump=(), **factory_kw)[source]

Instantiate the command and element factories.

Parameters:
  • freq_bunch_mhz (float) – Beam bunch frequency in \(\mathrm{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 (bool) – Whether Field should be created. This is not supported yet for CyEnvelope1D and Envelope3D, but it is mandatory for Envelope1D.

  • field_maps_in_3d (bool) – Whether 3D field maps should be loaded. This is 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 and Envelope3D used with Cython).

  • elements_to_dump (ABCMeta | tuple[ABCMeta, ...], default: ()) – 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.

  • factory_kw (Any) – Other parameters passed to the CommandFactory and ElementFactory.

Return type:

None

run(dat_filecontent)[source]

Create all the elements and commands.

Todo

Check if the return value from apply_commands is necessary.

Parameters:

dat_filecontent (Collection[DatLine]) – List containing all the lines of dat_filepath.

Return type:

list[Instruction]

_call_proper_factory(dat_line, dat_idx=None, **instruction_kw)[source]

Create proper Instruction, or Dummy.

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 – A single line of the DAT file.

  • dat_idx (int | None, default: None) – Line number of the line (starts at 0). If not provided, taken from line.

  • command_fac – A factory to create Command.

  • element_fac – A factory to create Element.

  • instruction_kw (str) – Keywords given to the run method of the proper factory.

  • dat_line (DatLine)

Return type:

Instruction

Returns:

Proper Command or Element, or Dummy, or Comment.

_handle_lattice_and_section(elts)[source]

Ensure that every element has proper lattice, section indexes.

Parameters:

elts (list[Element])

Return type:

None

_check_every_elt_has_lattice_and_section(elts)[source]

Check that every element has a lattice and section index.

Parameters:

elts (list[Element])

Return type:

None

_check_last_lattice_of_every_lattice_is_complete(elts)[source]

Check that last lattice of every section is complete.

Parameters:

elts (Sequence[Element])

Return type:

None

_filter_out_elements_to_dump(elts)[source]

Remove the desired elements.

Parameters:

elts (list[Element])

Return type:

None