optimisation.objective.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.

_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.

_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.

_end_linac(elts: ListOfElements, fault_idx: Any, comp_idx: Any) int

Evaluate objective at the end of the linac.

_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.

_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.

_reduce_idx_start_to_include_full_lattice(idx: int, elts: ListOfElements) int

Force compensation zone to start at the 1st element of lattice.

_zone(preset: str, *args) int

Give compensation zone, and position where objectives are checked.

zone_to_recompute(broken_elts: ListOfElements, objective_position_preset: Collection[str], fault_idx: Iterable[int], comp_idx: Iterable[int], full_lattices: bool = False, full_linac: bool = False, start_at_beginning_of_linac: bool = False) list[Element]

Determine the elements from the zone to recompute.

We use in this routine element indexes, not cavity indexes.

Parameters:
  • broken_elts (ListOfElements) – ListOfElements from the broken linac.

  • objective_position_preset (Collection[str]) – Short strings that must be in POSITION_TO_INDEX dictionary 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 Element are calculated. Plus, it has no impact even with TraceWin solver. 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_zoneElement objects of the compensation zone.

Return type:

list[Element]