optimisation.algorithms.explorator module

Define Explorator, a module to explore the design space.

In order to be consistent with the ABC OptimisationAlgorithm, it also returns the solution with the lowest residue value – hence it is also a “brute-force” optimisation algorithm.

Todo

Make this class more robust. In particular: save all objectives (not just the norm), handle export when there is more than two variables, also save complementary data (e.g.: always save phi_s even it is not in the constraints nor variables).

Todo

Allow for different number of points according to variable.

class Explorator(compute_constraints: Callable[[SimulationOutput], ndarray])

Bases: OptimisationAlgorithm

Method that tries all the possible solutions.

Notes

Very inefficient for optimisation. It is however useful to study a specific case.

All the attributes but solution are inherited from the Abstract Base Class OptimisationAlgorithm.

__init__(compute_constraints: Callable[[SimulationOutput], ndarray]) None

Instantiate the object.

_abc_impl = <_abc._abc_data object>
_add_the_best_point(axes: Axes3D, var: ndarray, obj: ndarray) None

Add the best solution to the plot.

_algorithm_parameters() dict

Create the kwargs for the optimisation.

_array_of_values_to_mesh(objectives_values: ndarray, n_points: int = 10, **kwargs) ndarray

Reformat the results for plotting purposes.

_check_dimensions() bool

Check that we have proper number of vars and objectives.

_generate_combinations(n_points: int = 10, **kwargs) tuple[ndarray, ndarray]

Generate all the possible combinations of the variables.

_plot_design_space(variable_mesh: ndarray, objective_mesh: ndarray, constraint_mesh: ndarray) Axes3D

Plot the design space.

_save_optimization_history(filepath: Path, hist_X: ndarray | None = None, hist_F: ndarray | None = None, hist_G: ndarray | None = None, n_phi: int = 10, **info: ndarray) None
_take_best_solution(variable_comb: ndarray, objectives_values: ndarray, criterion: str) tuple[ndarray | None, ndarray | None]

Take the “best” of the calculated solutions.

Parameters:
  • variable_comb (np.ndarray) – All the set of variables (cavity parameters) that were tried.

  • objectives_values (np.ndarray) – The values of the objective corresponding to variable_comb.

  • criterion ({'minimize norm of objective', }) – Name of the criterion that will determine which solution is the “best”. Only one is implemented for now, may add others in the future.

Returns:

  • best_solution (np.ndarray | None) – “Best” solution.

  • best_objective (np.ndarray | None) – Objective values corresponding to best_solution.

_wrapper_residuals(var: ndarray) tuple[float, bool]

Give norm of residual and if phi_s constraint is respected.

compute_constraints: Callable[[SimulationOutput], ndarray]
optimise(keep_history: bool = True, save_history: bool = True) tuple[bool, SetOfCavitySettings | None, OptiInfo]

Set up the optimisation and solve the problem.

Returns:

  • success (bool) – Tells if the optimisation algorithm managed to converge.

  • optimized_cavity_settings (SetOfCavitySettings | None) – Best solution found by the optimization algorithm.

  • info (OptiInfo) – Gives list of solutions, corresponding objective, convergence violation if applicable, etc.

supports_constraints: bool = True