strategy module
Define the function related to the strategy key of wtf.
In particular, it answers the question: Given this set of faults, which compensating cavities will be used?
Note
In order to add a compensation strategy, you must add it to the
COMPENSATING_SELECTOR dict, and also to the list of supported
strategies in optimisation.wtf_specs module.
- failed_and_compensating(elts, failed, id_nature, strategy, compensating_manual=None, **wtf)[source]
Determine the compensating cavities for every failure.
- Parameters:
- Return type:
- k_out_of_n(elements, failed_elements, *, k, tie_politics='upstream first', shift=0, remove_failed=True, **kwargs)[source]
Return
kcompensating cavities per failed inelts_of_interest.Note
Tcan represent aElement, or a list ofElement. Returned type/data structure will be the same as what was given in arguments. This function is hereby also used byl_neighboring_lattices()which gives in lattices.- Parameters:
elements (Sequence[T]) – All the tunable elements/lattices/sections.
failed_elements (Sequence[T]) – Failed cavities/lattice.
k (int) – Number of compensating cavity per failure.
tie_politics (Literal['upstream first', 'downstream first'], optional) – When two elements have the same position, will you want to have the upstream or the downstream first? The default is
"upstream first".shift (int, optional) – Distance increase for downstream elements (
shift < 0) or upstream elements (shift > 0). Used to have a window of compensating cavities which is not centered around the failed elements. The default is 0.remove_failed (
bool, default:True)
- Returns:
altered – Contains all the altered elements/lattices. The
nfirst are failed, thek * nfollowing are compensating.- Return type:
list[T]
- l_neighboring_lattices(elements_gathered_by_lattice, failed_elements, *, l, tie_politics='upstream first', shift=0, remove_failed=True, min_number_of_cavities_in_lattice=1, **kwargs)[source]
Select full lattices neighboring the failed cavities.
Every fault will be compensated by
lfull lattices, direct neighbors of the errors [BBU14, PB22]. You must providel. Non-failed cavities in the same lattice as the failure are also used.- Parameters:
elements_by_lattice (Sequence[Sequence[T]]) – Tunable elements sorted by lattice.
failed_elements (Sequence[T]) – Failed cavities/lattice.
l (int) – Number of compensating lattice per failure.
tie_politics (Literal['upstream first', 'downstream first'], optional) – When two elements have the same position, will you want to have the upstream or the downstream first? The default is
"upstream first".shift (int, optional) – Distance increase for downstream elements (
shift < 0) or upstream elements (shift > 0). Used to have a window of compensating cavities which is not centered around the failed elements. The default is 0.remove_failed (bool, optional) – To remove the failed lattices from the output. The default is True.
min_number_of_cavities_in_lattice (int, optional) – If a lattice has less than this number of functional cavities, we look for another lattice. This is designed to removed lattices which have no cavities (default value: 1). Note that lattices that have some functional cavities but not enough will be used for compensation anyway.
elements_gathered_by_lattice (
Sequence[Sequence[TypeVar(T)]])
- Returns:
altered – Contains all the altered cavities.
- Return type:
list[T]
- manual(failed_cavities, compensating_cavities)[source]
Associate failed with compensating cavities.
- global_compensation(elements, failed_elements, *, remove_failed=True, **kwargs)[source]
Give all the cavities of the linac.
- global_downstream(elements, failed_elements, *, remove_failed=True, **kwargs)[source]
Give all the cavities after failure of the linac.
- COMPENSATING_SELECTOR = { 'global': <function global_compensation at 0x73df42c8e8e0>, 'global_downstream': <function global_downstream at 0x73df42c8cd60>, 'k out of n': <function k_out_of_n at 0x73df42c8c680>, 'l neighboring lattices': <function l_neighboring_lattices at 0x73df42c8d4e0>, 'manual': <function manual at 0x73df42c8d300>}