factory module
Define a factory function to create OptimisationAlgorithm.
Todo
Docstrings
- ALGORITHM_SELECTOR: dict[str, ABCMeta] = { 'bayesian_optimization': <class 'lightwin.optimisation.algorithms.bayesian_optimization.BayesianOptimizationLW'>, '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.bayesian_optimization.BayesianOptimizationLW'>, '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'>, 'simulated_annealing': <class 'lightwin.optimisation.algorithms.simulated_annealing.SimulatedAnnealing'>}
Maps the
optimisation_algorithmkey in theTOMLfile to the actualOptimisationAlgorithmwe use.
- ALGORITHMS_T
Implemented optimization algorithms.
alias of
Literal[‘bayesian_optimization’, ‘differential_evolution’, ‘downhill_simplex’, ‘downhill_simplex_penalty’, ‘experimental’, ‘explorator’, ‘least_squares’, ‘least_squares_penalty’, ‘nelder_mead’, ‘nelder_mead_penalty’, ‘nsga’, ‘simulated_annealing’]
- optimisation_algorithm_factory(opti_method, fault, beam_calculator, **wtf)[source]
Create the proper
OptimisationAlgorithminstance.- 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:
- _default_kwargs(fault, run_with_this, cavity_settings_factory)[source]
Set default arguments to instantiate the optimisation algorithm.
The kwargs for
OptimisationAlgorithmthat are defined inFaultScenario._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:
- _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: