failures.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 config.wtf
module.
- failed_and_compensating(elts: ListOfElements, failed: Sequence[int] | Sequence[str] | Sequence[Sequence[int]] | Sequence[Sequence[str]], id_nature: Literal['cavity', 'element', 'name'], strategy: str, compensating_manual: Sequence[Sequence[int]] | Sequence[Sequence[str]] | None = None, **wtf: Any) tuple[list[list[FieldMap]], list[list[FieldMap]]]
Determine the compensating cavities for every failure.
- global_compensation(elements: Sequence, failed_elements: Sequence, *, remove_failed: bool = True, **kwargs) Sequence
Give all the cavities of the linac.
- Parameters:
elements (Sequence[T]) – All the tunable elements.
failed_elements (Sequence[T]) – Failed cavities.
- Returns:
altered – Contains all the altered elements.
- Return type:
list[T]
- global_downstream(elements: Sequence, failed_elements: Sequence, *, remove_failed: bool = True, **kwargs) Sequence
Give all the cavities after failure of the linac.
- Parameters:
elements (Sequence[T]) – All tunable the elements.
failed_elements (Sequence[T]) – Failed cavities.
- Returns:
altered – Contains all the altered elements.
- Return type:
list[T]
- k_out_of_n(elements: Sequence, failed_elements: Sequence, *, k: int, tie_politics: str = 'upstream first', shift: int = 0, remove_failed: bool = True, **kwargs) Sequence
Return
k
compensating cavities per failed inelts_of_interest
.Note
T
can 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 ({'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.
- Returns:
altered – Contains all the altered elements/lattices. The
n
first are failed, thek * n
following are compensating.- Return type:
list[T]
- l_neighboring_lattices(elements_gathered_by_lattice: Sequence[Sequence], failed_elements: Sequence, *, l: int, tie_politics: str = 'upstream first', shift: int = 0, remove_failed: bool = True, min_number_of_cavities_in_lattice: int = 1, **kwargs) Sequence
Select full lattices neighboring the failed cavities.
Every fault will be compensated by
l
full lattices, direct neighbors of the errors [1, 2]. You must providel
. Non-failed cavities in the same lattice as the failure are also used.References
- elements_by_latticeSequence[Sequence[T]]
Tunable elements sorted by lattice.
- failed_elementsSequence[T]
Failed cavities/lattice.
- lint
Number of compensating lattice per failure.
- tie_politics{‘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"
.- shiftint, 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_failedbool, optional
To remove the failed lattices from the output. The default is True.
- min_number_of_cavities_in_latticeint, 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.
- Returns:
altered – Contains all the altered cavities.
- Return type:
list[T]