list_of_elements module
Define a list of Element, with some additional methods.
Two objects can have a ListOfElements as attribute:
Accelerator: holds all theElementof the linac.Fault: it holds only a fraction of the linacElement. Beam will be propagated a huge number of times during optimisation process, so we recompute only the strict necessary.
Todo
Delete dat_filecontent, which does the same thing as elts_n_cmds but
less good
- class FilesInfo[source]
Bases:
TypedDictKeep information on the loaded dat file.
-
elts_n_cmds:
list[Instruction]
-
elts_n_cmds:
- class ListOfElements(elts, input_particle, input_beam, tm_cumul_in, files, first_init=True)[source]
Bases:
listClass holding the elements of a fraction or of the whole linac.
- Parameters:
input_particle (
ParticleInitialState)input_beam (
InitialBeamParameters)tm_cumul_in (
ndarray)files (
FilesInfo)first_init (
bool, default:True)
- __init__(elts, input_particle, input_beam, tm_cumul_in, files, first_init=True)[source]
Create the object, encompassing all the linac or only a fraction.
The first case is when you initialize an Accelerator and compute the baseline energy, phase, etc values. The second case is when you only recompute a fraction of the linac, which is part of the optimisation process.
- Parameters:
input_particle (
ParticleInitialState) – An object to hold initial energy and phase of the particle at the entry of the first element.input_beam (
InitialBeamParameters) – An object to hold emittances, Twiss, sigma beam matrix, etc at the entry of the first element.first_init (
bool, default:True) – To indicate if this a full linac or only a portion (fit process).files (
FilesInfo) –A dictionary to hold information on the source and output files/folders of the object.
dat_file: absolute path to theDATfileelts_n_cmds: list of objects representing dat contentaccelerator_path: where calculation results for eachBeamCalculatorwill be stored.dat_filecontent: list of list of str, holding content of theDAT.
tm_cumul_in (
ndarray)
- property w_kin_in
Get kinetic energy at entry of first element of self.
- property phi_abs_in
Get absolute phase at entry of first element of self.
- property tunable_cavities: list[FieldMap]
All the elements that can be used for compensation.
For now, only
FieldMap. But in the future… Who knows?
- property tracewin_command: list[str]
Create the command to give proper initial parameters to TraceWin.
- get(*keys, to_numpy=True, none_to_nan=False, remove_first=False, **kwargs)[source]
Get attributes from this class or its contained elements.
If the desired attribute belongs to
GETTABLE_ELTorGETTABLE_FIELD_MAP, we concatenate the value of every element in a single list.- Parameters:
*keys (
Literal['accelerator_path','dat_file','dat_filecontent','elts_n_cmds','files','input_beam','input_particle','tm_cumul_in'] |Literal['aperture_flag','field_map_filename','field_map_folder','geometry'] |Literal['e_spat','n_cell','n_z','starting_position','section_idx'] |Literal['dat_idx','elt_idx','idx','idx_in_lattice','lattice','length_m','name','nature','section'] |Literal['abs_mesh','d_z','n_steps','rel_mesh','s_in','s_out','transf_mat_function'] |Literal['acceptance_energy','acceptance_phi','field','freq_cavity_mhz','k_e','omega_0_rf','phi_ref','phi_rf','phi_s','reference','rf_field','status','v_cav_mv'] |Literal['phi_0_abs','phi_0_rel','phi_s'] |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']) – Names of the desired attributes.to_numpy (
bool, default:True) – Convert list outputs to NumPy arrays.none_to_nan (
bool, default:False) – ReplaceNonevalues withnp.nan.remove_first (
bool, default:False) – Remove the first item of each element’s attribute except for the first element itself.**kwargs (
Any) – Passed to recursive getter orElement.get().
- Returns:
A single value or tuple of values.
- Return type:
Any
- force_reference_phases_to(reference)[source]
Change the reference phase of the cavities in
self.This method is called by the
BeamCalculator. It is used after the first propagation of the beam in the fullListOfElements, to force everyCavitySettingsto use the reference phase specified by thebeam_calculatorentry of theTOML.
- store_settings_in_dat(dat_file, exported_phase, save=True)[source]
Update the
DATfile, save it if asked.This method is called several times:
It is also called by
Accelerator.keep()method.- Parameters:
- Return type:
Note
LightWin rephases cavities if the first
Elementinselfis not the first of the linac. This way, the beam enters each cavity with the intended phase inTraceWin(no effect if the phases are exported as relative phase).- Raises:
NotImplementedError – If
which_phaseis"as_in_original_dat".- Parameters:
exported_phase (
Literal['phi_0_abs','phi_0_rel','phi_s'] |Literal['as_in_original_dat'] |Literal['as_in_settings'])
- 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.