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, objective_position_preset, fault_idx, comp_idx, full_lattices=False, full_linac=False, start_at_beginning_of_linac=False)[source]

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[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']]) – 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, default: False) – 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, default: False) – To compute full linac at every step of the optimisation process. Can be very time-consuming, but may be necessary with some future BeamCalculator.

  • start_at_beginning_of_linac (bool, default: False) – To make compensation zone start at the beginning of the linac. The default is False.

Return type:

tuple[list[Element], list[Element]]

Returns:

  • elts_of_compensation_zoneElement objects of the compensation zone.

  • objective_elements – Where objectives are evaluated.

_zone(preset, *args)[source]

Give compensation zone, and position where objectives are checked.

Parameters:

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'])

Return type:

list[int]

_end_last_altered_lattice(elts, fault_idx, comp_idx)[source]

Evaluate obj at the end of the last lattice w/ an altered cavity.

Parameters:
Return type:

int

_one_lattice_after_last_altered_lattice(elts, fault_idx, comp_idx)[source]

Evaluate objective one lattice after the last comp or failed cav.

Parameters:
Return type:

int

_end_last_failed_lattice(elts, fault_idx, comp_idx)[source]

Evaluate obj at the end of the last lattice w/ a failed cavity.

Parameters:
Return type:

int

_one_lattice_after_last_failed_lattice(elts, fault_idx, comp_idx)[source]

Evaluate 1 lattice after end of the last lattice w/ a failed cavity.

Parameters:
Return type:

int

_end_linac(elts, fault_idx, comp_idx)[source]

Evaluate objective at the end of the linac.

Parameters:
Return type:

int

_reduce_idx_start_to_include_full_lattice(idx, elts)[source]

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

Parameters:
Return type:

int

_end_of_every_altered_lattice(elts, fault_idx, comp_idx)[source]
Parameters:
Return type:

list[int]

POSITION_TO_INDEX = {   'end of every altered lattice': <function _end_of_every_altered_lattice at 0x7318fa52c720>,     'end of last altered lattice': <function _end_last_altered_lattice at 0x7318fa304180>,     'end of last failed lattice': <function _end_last_failed_lattice at 0x7318fa306c00>,     'end of linac': <function _end_linac at 0x7318fa52f060>,     'one lattice after last altered lattice': <function _one_lattice_after_last_altered_lattice at 0x7318fa304220>,     'one lattice after last failed lattice': <function _one_lattice_after_last_failed_lattice at 0x7318fa52e2a0>}