interface module

Define functions for TraceWin command-line interface.

variables_to_command(warn_skipped: bool = False, **kwargs: str | float | int) list[str]

Generate a TraceWin command from the input dictionary.

If the value of the dict is None, only corresponding key is added (behavior for hide command).

If value is np.nan, it is ignored.

Else, the pair key-value is added as key=value string.

beam_calculator_to_command(executable: Path, ini_path: Path, path_cal: Path, **kwargs: str | int | float | bool | None) list[str]

Give command calling TraceWin according to BeamCalculator attribs.

list_of_elements_to_command(dat_filepath: Path) list[str]

Return a command from ListOfElements attributes.

ParticleInitialState and BeamParameters have their own method, they are not called from here.

beam_parameters_to_command(eps_x: float, alpha_x: float, beta_x: float, eps_y: float, alpha_y: float, beta_y: float, eps_z: float, alpha_z: float, beta_z: float) list[str]

Return a TraceWin command from the attributes of a BeamParameters.

particle_initial_state_to_command(w_kin: float) list[str]

Return a TraceWin command from attributes of ParticleInitialState.

We could use the zp command to modify the phase at the entry of the first element (when it is not the first element of the linac). We rather keep the absolute phase at the beginning of the zone to 0. and modify the .dat file in subset_of_pre_existing_list_of_elements function in order to always keep the same relative phi_0.

set_of_cavity_settings_to_command(set_of_cavity_settings: SetOfCavitySettings, phi_bunch_first_element: float, idx_first_element: int) list[str]

Return the ele commands for SetOfCavitySettings.

Parameters:
  • set_of_cavity_settings (SetOfCavitySettings) – All the new cavity settings.

  • phi_bunch_first_element (float) – Phase of synchronous particle at entry of first element of ListOfElements under study.

  • idx_first_element (int) – Index of first element of ListOfElements under study.

Returns:

Full command that will alter the TraceWin exection to match the desired set_of_cavity_settings.

Return type:

list[str]

_cavity_settings_to_command(field_map: FieldMap, cavity_settings: CavitySettings, delta_phi_bunch: float = 0.0, delta_index: int = 0) list[str]

Convert cavity_settings into TraceWin CLI arguments.

Parameters:
  • field_map (FieldMap) – Cavity under study.

  • cavity_settings (CavitySettings) – Settings to try.

  • delta_phi_bunch (float, optional) – Phase at entry of first element of ListOfElements under study. The default is 0.

  • delta_index (int, optional) – Index of the first element of ListOfElements under study. The default is 0.

Returns:

command – Piece of command to alter field_map with cavity_settings.

Return type:

list[str]

ARGS_POSITIONS = {'k_e': 6, 'phi_0': 3}
_alter_element(index: int, alter_kwargs: dict[str, float | int]) list[str]

Create the command piece to modify the element at index.

Parameters:
  • index – Position of the element to modify in LightWin referential (first element has index 0).

  • alter_kwargs – Key-pair values, where key is the LightWin name of the parameter to update, and value the new value to set. Key-pair value is skipped if value is np.nan. Key must be in ARGS_POSITIONS.

Returns:

The ele[i][j]=val command altering the given element.

Return type:

list[str]

_proper_type(key: str, value: str | int | float, not_in_dict_warning: bool = True) str | int | float | None

Check if type of value is consistent and try to correct otherwise.