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:

tuple[list[list[FieldMap]], list[list[FieldMap]]]

k_out_of_n(elements, failed_elements, *, k, tie_politics='upstream first', shift=0, remove_failed=True, **kwargs)[source]

Return k compensating cavities per failed in elts_of_interest.

Note

T can represent a Element, or a list of Element. Returned type/data structure will be the same as what was given in arguments. This function is hereby also used by l_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 n first are failed, the k * n following 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 l full lattices, direct neighbors of the errors [BBU14, PB22]. You must provide l. 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.

Parameters:
Return type:

tuple[list[list[FieldMap]], list[list[FieldMap]]]

global_compensation(elements, failed_elements, *, remove_failed=True, **kwargs)[source]

Give all the cavities of the linac.

Parameters:
  • elements (Sequence[T]) – All the tunable elements.

  • failed_elements (Sequence[T]) – Failed cavities.

  • remove_failed (bool, default: True)

Returns:

altered – Contains all the altered elements.

Return type:

list[T]

global_downstream(elements, failed_elements, *, remove_failed=True, **kwargs)[source]

Give all the cavities after failure of the linac.

Parameters:
  • elements (Sequence[T]) – All tunable the elements.

  • failed_elements (Sequence[T]) – Failed cavities.

  • remove_failed (bool, default: True)

Returns:

altered – Contains all the altered elements.

Return type:

list[T]

COMPENSATING_SELECTOR = {   'global': <function global_compensation at 0x70e253a7e340>,     'global_downstream': <function global_downstream at 0x70e253a7ef20>,     'k out of n': <function k_out_of_n at 0x70e2533e7e20>,     'l neighboring lattices': <function l_neighboring_lattices at 0x70e253a7d760>,     'manual': <function manual at 0x70e2533e6660>}