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.Compensate the \(n\) failed cavities with \(k imes n\) closest cavities [SPK21, YRKT+22].
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[TypeVar(T)]) – All the tunable elements/lattices/sections.failed_elements (
Sequence[TypeVar(T)]) – Failed cavities/lattice.k (
int) – Number of compensating cavity per failure.tie_politics (
str, default:'upstream first') – When two elements have the same position, will you want to have the upstream or the downstream first?shift (
int, default:0) – 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.remove_failed (
bool, default:True)
- Return type:
- Returns:
Contains all the altered elements/lattices. The
nfirst are failed, thek * nfollowing are compensating.
- 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 – Tunable elements sorted by lattice.
failed_elements (
Sequence[TypeVar(T)]) – Failed cavities/lattice.l (
int) – Number of compensating lattice per failure.tie_politics (
str, default:'upstream first') – When two elements have the same position, will you want to have the upstream or the downstream first?shift (
int, default:0) – 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.remove_failed (
bool, default:True) – To remove the failed lattices from the output.min_number_of_cavities_in_lattice (
int, default:1) – 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. 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)]])
- Return type:
- Returns:
Contains all the altered cavities.
- 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 0x75e5169a59e0>, 'global_downstream': <function global_downstream at 0x75e5169a6a20>, 'k out of n': <function k_out_of_n at 0x75e5169a6f20>, 'l neighboring lattices': <function l_neighboring_lattices at 0x75e5169a6fc0>, 'manual': <function manual at 0x75e5169a42c0>}