position module
Define functions to determine the compensation zone.
In most cases, we need to study only a fraction of the linac during optimisation process. This zone should be as small as possible to reduce computation time, it should encompass all failed cavities, all compensating cavities, as well as the place where objectives are evaluated.
Important
In this module, the indexes are element indexes, not cavity.
Todo
end_section, elt.name
Todo
full_linac seems useless. Could be a strategy instead of an override
setting. Would need to edit the ObjectiveFactory too.
Note
[*a, *b] will concatenate the two Iterable a and b. Same as
a + b but will work with every Iterable, not just list.
- zone_to_recompute(broken_elts: ListOfElements, objective_position_preset: Collection[Literal['end of last altered lattice', 'one lattice after last altered lattice', 'end of last failed lattice', 'one lattice after last failed lattice', 'end of linac', 'end of every altered lattice']], fault_idx: Iterable[int], comp_idx: Iterable[int], full_lattices: bool = False, full_linac: bool = False, start_at_beginning_of_linac: bool = False) tuple[list[Element], list[Element]]
Determine the elements from the zone to recompute.
We use in this routine element indexes, not cavity indexes.
- Parameters:
broken_elts (ListOfElements) –
ListOfElementsfrom the broken linac.objective_position_preset (Collection[str]) – Short strings that must be in
POSITION_TO_INDEXdictionary to determine where the objectives should be evaluated.fault_idx (Iterable[int]) – Cavity index of the faults and compensating cavities, directly converted to element index in the routine.
comp_idx (Iterable[int]) – Cavity index of the faults and compensating cavities, directly converted to element index in the routine.
full_lattices (bool, optional) – If you want the compensation zone to encompass full lattices only. It is a little bit slower as more
Elementare calculated. Plus, it has no impact even withTraceWinsolver. Keeping it in case it has an impact that I did not see.full_linac (bool, optional) – To compute full linac at every step of the optimisation process. Can be very time-consuming, but may be necessary with some future
BeamCalculator. The default is False.start_at_beginning_of_linac (bool, optional) – To make compensation zone start at the beginning of the linac. The default is False.
- Returns:
elts_of_compensation_zone (list[Element]) –
Elementobjects of the compensation zone.objective_elements (list[Element]) – Where objectives are evaluated.
- _zone(preset: Literal['end of last altered lattice', 'one lattice after last altered lattice', 'end of last failed lattice', 'one lattice after last failed lattice', 'end of linac', 'end of every altered lattice'], *args) list[int]
Give compensation zone, and position where objectives are checked.
- _end_last_altered_lattice(elts: ListOfElements, fault_idx: Iterable[int], comp_idx: Iterable[int]) int
Evaluate obj at the end of the last lattice w/ an altered cavity.
- _one_lattice_after_last_altered_lattice(elts: ListOfElements, fault_idx: Iterable[int], comp_idx: Iterable[int]) int
Evaluate objective one lattice after the last comp or failed cav.
- _end_last_failed_lattice(elts: ListOfElements, fault_idx: Collection[int], comp_idx: Collection[int]) int
Evaluate obj at the end of the last lattice w/ a failed cavity.
- _one_lattice_after_last_failed_lattice(elts: ListOfElements, fault_idx: Collection[int], comp_idx: Collection[int]) int
Evaluate 1 lattice after end of the last lattice w/ a failed cavity.
- _end_linac(elts: ListOfElements, fault_idx: Any, comp_idx: Any) int
Evaluate objective at the end of the linac.
- _reduce_idx_start_to_include_full_lattice(idx: int, elts: ListOfElements) int
Force compensation zone to start at the 1st element of lattice.
- _end_of_every_altered_lattice(elts: ListOfElements, fault_idx: Collection[int], comp_idx: Collection[int]) list[int]
- POSITION_TO_INDEX = { 'end of every altered lattice': <function _end_of_every_altered_lattice at 0x7f36f78c04a0>, 'end of last altered lattice': <function _end_last_altered_lattice at 0x7f36f78c00e0>, 'end of last failed lattice': <function _end_last_failed_lattice at 0x7f36f78c0220>, 'end of linac': <function _end_linac at 0x7f36f78c0360>, 'one lattice after last altered lattice': <function _one_lattice_after_last_altered_lattice at 0x7f36f78c0180>, 'one lattice after last failed lattice': <function _one_lattice_after_last_failed_lattice at 0x7f36f78c02c0>}