factory module

Define a factory function to create OptimisationAlgorithm.

Todo

Docstrings

ALGORITHM_SELECTOR: dict[str, ABCMeta] = {   'differential_evolution': <class 'lightwin.optimisation.algorithms.differential_evolution.DifferentialEvolution'>,     'downhill_simplex': <class 'lightwin.optimisation.algorithms.downhill_simplex.DownhillSimplex'>,     'downhill_simplex_penalty': <class 'lightwin.optimisation.algorithms.downhill_simplex_penalty.DownhillSimplexPenalty'>,     'experimental': <class 'lightwin.optimisation.algorithms.explorator.Explorator'>,     'explorator': <class 'lightwin.optimisation.algorithms.explorator.Explorator'>,     'least_squares': <class 'lightwin.optimisation.algorithms.least_squares.LeastSquares'>,     'least_squares_penalty': <class 'lightwin.optimisation.algorithms.least_squares_penalty.LeastSquaresPenalty'>,     'nelder_mead': <class 'lightwin.optimisation.algorithms.downhill_simplex.DownhillSimplex'>,     'nelder_mead_penalty': <class 'lightwin.optimisation.algorithms.downhill_simplex_penalty.DownhillSimplexPenalty'>,     'nsga': <class 'lightwin.optimisation.algorithms.nsga.NSGA'>}
optimisation_algorithm_factory(opti_method: str, fault: Fault, beam_calculator: BeamCalculator, **wtf: Any) OptimisationAlgorithm

Create the proper OptimisationAlgorithm instance.

Parameters:
  • opti_method (str) – Name of the desired optimisation algorithm.

  • fault (Fault) – Fault that will be compensated by the optimisation algorithm.

  • beam_calculator (BeamCalculator) – Object that will be used to computte propagation of the beam.

  • kwargs – Other keyword arguments that will be passed to the OptimisationAlgorithm.

Returns:

algorithm – Instantiated optimisation algorithm.

Return type:

OptimisationAlgorithm

_default_kwargs(fault: Fault, run_with_this: Callable, cavity_settings_factory: CavitySettingsFactory) dict[str, Any]

Set default arguments to instantiate the optimisation algorithm.

The kwargs for OptimisationAlgorithm that are defined in FaultScenario._set_optimisation_algorithms() will override the ones defined here.

Parameters:
  • fault (Fault) – Fault that will be compensated by the optimisation algorithm.

  • compute_beam_propagation (Callable) – Function that takes in a set of cavity settings and a list of elements, computes the beam propagation with these, and returns a simulation output.

Returns:

default_kwargs – A dictionary of keyword arguments for the initialisation of OptimisationAlgorithm.

Return type:

dict[str, Any]

_check_common_keys(user_kwargs: dict[str, Any], default_kwargs: dict[str, Any]) None

Check keys that are common between the two dictionaries.

Todo

Redocument default_kwargs.

Parameters:
  • user_kwargs (dict[str, Any]) – kwargs as defined in the FaultScenario._set_optimisation_algorithms() (they have precedence).

  • default_kwargs ([str, Any]) – kwargs as defined in the _optimisation_algorithm_kwargs (they will be overriden as they are considered as “default” or “fallback” values).