optimisation.algorithms.factory module

Define a factory function to create OptimisationAlgorithm.

Todo

Docstrings

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

Check keys that are common between the two dictionaries.

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

_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]

algorithms = ('least_squares', 'least_squares_penalty', 'nsga', 'downhill_simplex', 'downhill_simplex_penalty', 'nelder_mead', 'nelder_mead_penalty', 'differential_evolution', 'explorator', 'experimental')
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