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.
- 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
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.
- 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: 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
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.
- Returns:
altered – Contains all the altered cavities.
- Return type:
list[T]
- manual(failed_cavities: Sequence[list[FieldMap]], compensating_cavities: list[list[FieldMap]] | Any) tuple[list[list[FieldMap]], list[list[FieldMap]]]
Associate failed with compensating cavities.
- 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]
- COMPENSATING_SELECTOR = { 'global': <function global_compensation at 0x7fd3c86e1e40>, 'global_downstream': <function global_downstream at 0x7fd3c86e2840>, 'k out of n': <function k_out_of_n at 0x7fd3c86e0540>, 'l neighboring lattices': <function l_neighboring_lattices at 0x7fd3c86e1d00>}