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) –ListOfElementsfrom 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 inPOSITION_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, default:False) – If you want the compensation zone to encompass full lattices only. It is a little bit slower as moreElementare calculated. Plus, it has no impact even withTraceWinsolver. 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 futureBeamCalculator.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:
- Returns:
elts_of_compensation_zone –
Elementobjects of the compensation zone.objective_elements – Where objectives are evaluated.
- _end_last_altered_lattice(elts, fault_idx, comp_idx)[source]
Evaluate obj at the end of the last lattice w/ an altered cavity.
- _one_lattice_after_last_altered_lattice(elts, fault_idx, comp_idx)[source]
Evaluate objective one lattice after the last comp or failed cav.
- _end_last_failed_lattice(elts, fault_idx, comp_idx)[source]
Evaluate obj at the end of the last lattice w/ a failed cavity.
- Parameters:
elts (
ListOfElements)fault_idx (
Collection[int])comp_idx (
Collection[int])
- Return type:
- _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:
elts (
ListOfElements)fault_idx (
Collection[int])comp_idx (
Collection[int])
- Return type:
- _end_linac(elts, fault_idx, comp_idx)[source]
Evaluate objective at the end of the linac.
- Parameters:
elts (
ListOfElements)fault_idx (
Any)comp_idx (
Any)
- Return type:
- _reduce_idx_start_to_include_full_lattice(idx, elts)[source]
Force compensation zone to start at the 1st element of lattice.
- Parameters:
idx (
int)elts (
ListOfElements)
- Return type:
- _end_of_every_altered_lattice(elts, fault_idx, comp_idx)[source]
- Parameters:
elts (
ListOfElements)fault_idx (
Collection[int])comp_idx (
Collection[int])
- Return type:
- 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>}