algorithm module
Define the Abstract Base Class of optimisation algorithms.
Abstract methods are mandatory and a TypeError will be raised if you try to
create your own algorithm and omit them.
When you add you own optimisation algorithm, do not forget to add it to the
list of implemented algorithms in the algorithm module.
Todo
Check if it is necessary to pass out the whole elts to
OptimisationAlgorithm?
Todo
Methods and flags to keep the optimisation history or not, and also to save
it or not. See Explorator.
Todo
Better handling of the attribute folder. In particular, a correct value
should be set at the OptimisationAlgorithm instanciation.
- class OptimisationAlgorithm(compensating_elements: Collection[Element], elts: ListOfElements, objectives: Collection[Objective], variables: Collection[Variable], compute_beam_propagation: Callable[[SetOfCavitySettings], SimulationOutput], compute_residuals: Callable[[SimulationOutput], Any], cavity_settings_factory: CavitySettingsFactory, constraints: Collection[Constraint] | None = None, compute_constraints: Callable[[SimulationOutput], ndarray] | None = None, folder: Path | None = None, optimisation_algorithm_kwargs: dict[str, Any] | None = None, **kwargs)
Bases:
ABCHolds the optimisation parameters, the methods to optimize.
- Parameters:
compensating_elements (list[Element]) – Cavity objects used to compensate for the faults.
elts (ListOfElements) – Holds the whole compensation zone under study.
objectives (list[Objective]) – Holds objectives, initial values, bounds.
variables (list[Variable]) – Holds variables, their initial values, their limits.
constraints (list[Constraint] | None, optional) – Holds constraints and their limits. The default is None.
solution (dict) – Holds information on the solution that was found.
supports_constraints (bool) – If the method handles constraints or not.
compute_beam_propagation (ComputeBeamPropagationT) – Method to compute propagation of the beam with the given settings. Defined by a
BeamCalculator.run_with_this()method, the positional argumenteltsbeing set by afunctools.partial.compute_residuals (ComputeResidualsT) – Method to compute residuals from a
SimulationOutput.compute_constraints (ComputeConstraintsT | None, optional) – Method to compute constraint violation. The default is None.
folder (str | None, optional) – Where history, phase space and other optimisation information will be saved if necessary. The default is None.
cavity_settings_factory (CavitySettingsFactory) – A factory to easily create the cavity settings to try at each iteration of the optimisation algorithm.
- __init__(compensating_elements: Collection[Element], elts: ListOfElements, objectives: Collection[Objective], variables: Collection[Variable], compute_beam_propagation: Callable[[SetOfCavitySettings], SimulationOutput], compute_residuals: Callable[[SimulationOutput], Any], cavity_settings_factory: CavitySettingsFactory, constraints: Collection[Constraint] | None = None, compute_constraints: Callable[[SimulationOutput], ndarray] | None = None, folder: Path | None = None, optimisation_algorithm_kwargs: dict[str, Any] | None = None, **kwargs) None
Instantiate the object.
- abstract optimise(keep_history: bool = False, save_history: bool = False) tuple[bool, SetOfCavitySettings | None, OptiInfo]
Set up optimisation parameters and solve the problem.
- Parameters:
- Returns:
success (bool) – Tells if the optimisation algorithm managed to converge.
optimized_cavity_settings (SetOfCavitySettings) – Best solution found by the optimization algorithm. None if no satisfactory solution was found.
info (OptiInfo) – Gives list of solutions, corresponding objective, convergence violation if applicable, etc.
- _format_constraints() Any
Adapt all
Constraintto this optimisation algorithm.
- _norm_wrapper_residuals(var: ndarray) float
Compute norm of residues vector from an array of variable values.
- _create_set_of_cavity_settings(var: ndarray, status: str = 'compensate (in progress)') SetOfCavitySettings
Transform
varinto genericSetOfCavitySettings.- Parameters:
var – An array holding the variables to try.
status (str, optional) – mmmh
- Returns:
Object holding the settings of all the cavities.
- Return type:
- _abc_impl = <_abc._abc_data object at 0x7fd3c8ad36c0>