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, fault, beam_calculator, **wtf)[source]

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.

  • wtf (Any)

Returns:

algorithm – Instantiated optimisation algorithm.

Return type:

OptimisationAlgorithm

_default_kwargs(fault, run_with_this, cavity_settings_factory)[source]

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.

  • run_with_this (Callable)

  • cavity_settings_factory (CavitySettingsFactory)

Returns:

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

Return type:

dict[str, Any]

_check_common_keys(user_kwargs, default_kwargs)[source]

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

Return type:

None