factory module

Define a factory function to create OptimisationAlgorithm.

ALGORITHM_SELECTOR: dict[str, ABCMeta] = {   'NSGA-III': <class 'lightwin.optimisation.algorithms.nsga.NSGA3Algorithm'>,     'NSGA-III Multi-threaded': <class 'lightwin.optimisation.algorithms.nsga.NSGA3AlgorithmMulti'>,     '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'>,     'simulated_annealing': <class 'lightwin.optimisation.algorithms.simulated_annealing.SimulatedAnnealing'>}

Maps the optimisation_algorithm key in the TOML file to the actual OptimisationAlgorithm we 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-III’, ‘NSGA-III Multi-threaded’, ‘simulated_annealing’]

class OptimisationAlgorithmFactory(opti_method, beam_calculator, reference_simulation_output, accelerator_id, **wtf)[source]

Bases: object

Holds methods to easily create OptimisationAlgorithm.

Parameters:
  • opti_method (Literal['bayesian_optimization', 'differential_evolution', 'downhill_simplex', 'downhill_simplex_penalty', 'experimental', 'explorator', 'least_squares', 'least_squares_penalty', 'nelder_mead', 'nelder_mead_penalty', 'NSGA-III', 'NSGA-III Multi-threaded', 'simulated_annealing'])

  • beam_calculator (BeamCalculator)

  • reference_simulation_output (SimulationOutput)

  • accelerator_id (str)

  • wtf (Any)

__init__(opti_method, beam_calculator, reference_simulation_output, accelerator_id, **wtf)[source]

Save properties common to every optimization algorithhm.

Parameters:
  • opti_method (Literal['bayesian_optimization', 'differential_evolution', 'downhill_simplex', 'downhill_simplex_penalty', 'experimental', 'explorator', 'least_squares', 'least_squares_penalty', 'nelder_mead', 'nelder_mead_penalty', 'NSGA-III', 'NSGA-III Multi-threaded', 'simulated_annealing']) – Name of the desired optimisation algorithm.

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

  • reference_simulation_output (SimulationOutput) – Simulation of the nominal accelerator.

  • accelerator_id (str) – Associated solution Accelerator.id. Looks like: 0000001_Solution.

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

  • wtf (Any)

Return type:

None

create(compensating_elements, objective_factory, design_space, subset_elts)[source]

Instantiate an optimisation algorithm for a given fault.

Parameters:
Return type:

OptimisationAlgorithm

create_from_preset(compensating_elements, objective_factory, design_space, subset_elts, predefined_cavity_settings, predefined_simulation_output=None)[source]

Instantiate a fake optimization algorithm bypassing the solver.

Parameters:
Return type:

PredefinedSolution

_make_default_kwargs(compensating_elements, objective_factory, design_space, subset_elts)[source]

Build default arguments for OptimisationAlgorithm.

The kwargs for OptimisationAlgorithm that are defined in Fault.optimisation_algorithm will override the ones defined here.

Return type:

dict[str, Any]

Returns:

A dictionary of keyword arguments for the initialisation of OptimisationAlgorithm.

Parameters:
_log_common_keys(user_kwargs, default_kwargs)[source]

Log when user-provided and default kwargs overlap.

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

  • default_kwargs (dict[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