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 stored in Accelerator.simulation_outputs. Additionally, it has a ParticleInitialState, which describes energy, phase, etc of the beam at the entry of its ListOfElements.

class Accelerator(name, dat_file, accelerator_path, list_of_elements_factory, e_mev, sigma, **kwargs)[source]

Bases: object

Class holding a ListOfElements.

Parameters:
__init__(name, dat_file, accelerator_path, list_of_elements_factory, e_mev, sigma, **kwargs)[source]

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.

  • e_mev (float) – Initial beam energy in \(\mathrm{MeV}\).

  • sigma (ndarray) – Initial beam \(\sigma\) matrix in \(\mathrm{m}\) and \(\mathrm{rad}\).

simulation_outputs: dict[str, SimulationOutput]

Every SimulationOutput instance, associated with the name of the BeamCalculator that created it. This dictionary is filled by keep_simulation_output().

elts: ListOfElements

The list of elements contained in the accelerator.

property l_cav

Shortcut to easily get list of cavities.

has(key)[source]

Tell if the required attribute is in this class.

Parameters:

key (str)

Return type:

bool

get(*keys, to_numpy=True, none_to_nan=False, elt=None, **kwargs)[source]

Get attributes from this instance or its attributes.

Note

It is recommended to use the SimulationOutput.get() method to retrieve simulation-related data. While Accelerator.get() will generally return the same results when the simulation_outputs attribute contains only one SimulationOutput object, its behavior is undefined if multiple outputs are present.

Parameters:
  • *keys (Literal['accelerator_path', 'elts', 'name', 'simulation_outputs'] | Literal['accelerator_path', 'dat_file', 'dat_filecontent', 'elts_n_cmds', 'files', 'input_beam', 'input_particle', 'tm_cumul_in'] | Literal['dat_idx', 'elt_idx', 'idx', 'idx_in_lattice', 'lattice', 'length_m', 'nature', 'section'] | Literal['abs_mesh', 'd_z', 'n_steps', 'rel_mesh', 's_in', 's_out', 'transf_mat_function'] | Literal['beta', 'gamma', 'phi_abs', 'synchronous', 'w_kin', 'z_in'] | Literal['e_mev', 'e_rest_mev', 'f_bunch_mhz', 'i_milli_a', 'q_adim', 'sigma', 'inv_e_rest_mev', 'gamma_init', 'omega_0_bunch', 'lambda_bunch', 'q_over_m', 'm_over_q'] | Literal['alpha_phiw', 'beta_phiw', 'envelope_energy_phiw', 'envelope_pos_phiw', 'eps_phiw', 'eps_no_normalization_phiw', 'eps_normalized_phiw', 'gamma_phiw', 'sigma_phiw', 'twiss_phiw', 'alpha_phiw99', 'beta_phiw99', 'envelope_energy_phiw99', 'envelope_pos_phiw99', 'eps_phiw99', 'eps_no_normalization_phiw99', 'eps_normalized_phiw99', 'gamma_phiw99', 'sigma_phiw99', 'twiss_phiw99', 'alpha_t', 'beta_t', 'envelope_energy_t', 'envelope_pos_t', 'eps_t', 'eps_no_normalization_t', 'eps_normalized_t', 'gamma_t', 'sigma_t', 'twiss_t', 'alpha_x', 'beta_x', 'envelope_energy_x', 'envelope_pos_x', 'eps_x', 'eps_no_normalization_x', 'eps_normalized_x', 'gamma_x', 'sigma_x', 'twiss_x', 'alpha_x99', 'beta_x99', 'envelope_energy_x99', 'envelope_pos_x99', 'eps_x99', 'eps_no_normalization_x99', 'eps_normalized_x99', 'gamma_x99', 'sigma_x99', 'twiss_x99', 'alpha_y', 'beta_y', 'envelope_energy_y', 'envelope_pos_y', 'eps_y', 'eps_no_normalization_y', 'eps_normalized_y', 'gamma_y', 'sigma_y', 'twiss_y', 'alpha_y99', 'beta_y99', 'envelope_energy_y99', 'envelope_pos_y99', 'eps_y99', 'eps_no_normalization_y99', 'eps_normalized_y99', 'gamma_y99', 'sigma_y99', 'twiss_y99', 'alpha_z', 'beta_z', 'envelope_energy_z', 'envelope_pos_z', 'eps_z', 'eps_no_normalization_z', 'eps_normalized_z', 'gamma_z', 'sigma_z', 'twiss_z', 'alpha_zdelta', 'beta_zdelta', 'envelope_energy_zdelta', 'envelope_pos_zdelta', 'eps_zdelta', 'eps_no_normalization_zdelta', 'eps_normalized_zdelta', 'gamma_zdelta', 'sigma_zdelta', 'twiss_zdelta'] | Literal['alpha', 'beta', 'beta_kin', 'envelope_energy', 'envelope_pos', 'eps', 'eps_no_normalization', 'eps_normalized', 'gamma', 'gamma_kin', 'sigma', 'twiss', 'z_abs'] | Literal['phiw', 'phiw99', 't', 'x', 'x99', 'y', 'y99', 'z', 'zdelta']) – Name of the desired attributes.

  • to_numpy (bool, default: True) – If you want the list output to be converted to a numpy array.

  • none_to_nan (bool, default: False) – To convert None to np.nan.

  • elt (str | Element | None, default: None) – 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 elts, 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

_create_special_getters()[source]

Create a dict of aliases that can be accessed w/ the get method.

Return type:

dict

keep_settings(simulation_output, exported_phase)[source]

Save cavity parameters in Elements and new .dat file.

Parameters:
Return type:

None

keep_simulation_output(simulation_output, beam_calculator_id)[source]

Save SimulationOutput in simulation_outputs.

Also store info on current Accelerator in this object. 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.

Parameters:
Return type:

None

elt_at_this_s_idx(s_idx, show_info=False)[source]

Give the element where the given index is.

Parameters:
  • s_idx (int)

  • show_info (bool, default: False)

Return type:

Element | None

equivalent_elt(elt)[source]

Return element from self.elts with the same name as elt.

Parameters:

elt (Element | str)

Return type:

Element

pickle(pickler, path=None)[source]

Pickle (save) the object.

This is useful for debug and temporary saves; do not use it for long time saving.

Parameters:
Return type:

Path

classmethod from_pickle(pickler, path)[source]

Instantiate object from previously pickled file.

Parameters:
Return type:

Self