gemseo / utils / testing

Hide inherited members

opt_lib_test_base module

Common tools for testing opt libraries.

class gemseo.utils.testing.opt_lib_test_base.OptLibraryTestBase[source]

Bases: object

Main testing class.

static create_test(problem, opt_library, algo_name, options)[source]

Create a function to run and test an optimization algorithm.

Parameters:
  • problem (OptimizationProblem) – The optimization problem.

  • opt_library (str) – The name of the optimization library.

  • algo_name (str) – The name of the optimization algorithm.

  • options (dict[str, Any]) – The options of the optimization algorithm.

Returns:

The error message if the optimizer cannot find the solution, otherwise None.

static generate_error_test(opt_lib_name, algo_name, **options)[source]

Solve the Power 2 problem with an optimization library.

This optimization problem has constraints.

This problem raises an error when calling the objective.

Parameters:
  • opt_lib_name – The name of the optimization library.

  • algo_name – The name of the optimization algorithm.

  • **options – The options of the optimization algorithm.

Returns:

An optimization library after the resolution of the Rosenbrock problem.

static generate_one_test(opt_lib_name, algo_name, **options)[source]

Solve the Power 2 problem with an optimization library.

This optimization problem has equality constraints.

Parameters:
  • opt_lib_name (str) – The name of the optimization library.

  • algo_name (str) – The name of the optimization algorithm.

  • **options (Any) – The options of the optimization algorithm.

Returns:

An optimization library after the resolution of the Power 2 problem.

Return type:

OptimizationLibrary

static generate_one_test_unconstrained(opt_lib_name, algo_name, **options)[source]

Solve the Rosenbrock problem with an optimization library.

This optimization problem has no constraints.

Parameters:
  • opt_lib_name – The name of the optimization library.

  • algo_name – The name of the optimization algorithm.

  • **options – The options of the optimization algorithm.

Returns:

An optimization library after the resolution of the Rosenbrock problem.

generate_test(opt_lib_name, get_options=None, get_problem_options=None)[source]

Generates the tests for an opt library Filters algorithms adapted to the benchmark problems.

Parameters:
  • opt_lib_name – The name of the optimization library.

  • get_options – A function to get the options of the algorithm.

  • get_problem_options – A function to get the options of the problem.

Returns!

The test methods to be attached to a unitest class.

static get_pb_instance(pb_name, pb_options=None)[source]

Return an optimization problem.

Parameters:
  • pb_name (str) – The name of the optimization problem.

  • pb_options (dict[str, Any] | None) – The options to be passed to the optimization problem.

Raises:

ValueError – When the problem is not available.

Return type:

Rosenbrock | Power2 | Rastrigin

static norm(x)[source]

Compute the Euclidean norm of a vector.

Parameters:

x (NDArray[float]) – The vector.

Returns:

The Euclidean norm of the vector.

Return type:

float

static relative_norm(x, x_ref)[source]

Compute a relative Euclidean norm between to vectors.

Parameters:
  • x (NDArray[float]) – The vector.

  • x_ref (NDArray[float]) – The reference vector.

Returns:

The relative Euclidean norm between two vectors.

Return type:

float

static run_and_test_problem(problem, opt_library, algo_name, **options)[source]

Run and test an optimization algorithm.

Parameters:
  • problem (OptimizationProblem) – The optimization problem.

  • opt_library (str) – The name of the optimization library.

  • algo_name (str) – The name of the optimization algorithm.

  • **options (Any) – The options of the optimization algorithm.

Returns:

The error message if the optimizer cannot find the solution, otherwise None.

Return type:

str | None