gemseo_pymoo / algos / opt

# lib_pymoo module¶

Pymoo optimization library wrapper.

class gemseo_pymoo.algos.opt.lib_pymoo.PymooAlgorithmDescription(algorithm_name, internal_algorithm_name, library_name='pymoo', description='', website='', handle_integer_variables=True, require_gradient=False, handle_equality_constraints=False, handle_inequality_constraints=True, handle_multiobjective=False, positive_constraints=False, problem_type='non-linear', require_grad=False)[source]

The description of an optimization algorithm from the pymoo library.

Parameters
• algorithm_name (str) –

• internal_algorithm_name (str) –

• library_name (str) –

By default it is set to pymoo.

• description (str) –

By default it is set to .

• website (str) –

By default it is set to .

• handle_integer_variables (bool) –

By default it is set to True.

By default it is set to False.

• handle_equality_constraints (bool) –

By default it is set to False.

• handle_inequality_constraints (bool) –

By default it is set to True.

• handle_multiobjective (bool) –

By default it is set to False.

• positive_constraints (bool) –

By default it is set to False.

• problem_type (str) –

By default it is set to non-linear.

By default it is set to False.

Return type

None

algorithm_name: str

The name of the algorithm in GEMSEO.

description: str = ''

A description of the algorithm.

handle_equality_constraints: bool = False

Whether the optimization algorithm handles equality constraints.

handle_inequality_constraints: bool = True

Whether the optimization algorithm handles inequality constraints.

handle_integer_variables: bool = True

Whether the optimization algorithm handles integer variables.

handle_multiobjective: bool = False

Whether the optimization algorithm handles multiple objectives.

internal_algorithm_name: str

The name of the algorithm in the wrapped library.

library_name: str = 'pymoo'

The name of the wrapped library.

positive_constraints: bool = False

Whether the optimization algorithm requires positive constraints.

problem_type: str = 'non-linear'

The type of problem (see OptimizationProblem.AVAILABLE_PB_TYPES).

Whether the optimization algorithm requires the gradient.

website: str = ''

The website of the wrapped library or algorithm.

class gemseo_pymoo.algos.opt.lib_pymoo.PymooOpt[source]

Pymoo optimization library interface.

Constructor.

Generate the library dict, which contains the list of algorithms with their characteristics:

• does it handle equality constraints

• does it handle inequality constraints

Return type

None

algorithm_handles_eqcstr(algo_name)

Check if an algorithm handles equality constraints.

Parameters

algo_name (str) – The name of the algorithm.

Returns

Whether the algorithm handles equality constraints.

Return type

bool

algorithm_handles_ineqcstr(algo_name)

Check if an algorithm handles inequality constraints.

Parameters

algo_name (str) – The name of the algorithm.

Returns

Whether the algorithm handles inequality constraints.

Return type

bool

deactivate_progress_bar()

Deactivate the progress bar.

Return type

None

driver_has_option(option_name)

Check the existence of an option.

Parameters

option_name (str) – The name of the option.

Returns

Whether the option exists.

Return type

bool

ensure_bounds(orig_func, normalize=True)

Project the design vector onto the design space before execution.

Parameters
• orig_func – The original function.

• normalize

Whether to use the normalized design space.

By default it is set to True.

Returns

A function calling the original function with the input data projected onto the design space.

execute(problem, algo_name=None, eval_obs_jac=False, skip_int_check=False, **options)

Execute the driver.

Parameters
• problem (OptimizationProblem) – The problem to be solved.

• algo_name (str | None) –

The name of the algorithm. If None, use the algo_name attribute which may have been set by the factory.

By default it is set to None.

• eval_obs_jac (bool) –

Whether to evaluate the Jacobian of the observables.

By default it is set to False.

• skip_int_check (bool) –

Whether to skip the integer variable handling check of the selected algorithm.

By default it is set to False.

• **options (DriverLibOptionType) – The options for the algorithm.

Returns

The optimization result.

Raises

ValueError – If algo_name was not either set by the factory or given as an argument.

Return type

OptimizationResult

Filter the algorithms capable of solving the problem.

Parameters

problem (Any) – The problem to be solved.

Returns

The names of the algorithms adapted to this problem.

Return type

list[str]

finalize_iter_observer()

Finalize the iteration observer.

Return type

None

get_optimum_from_database(message=None, status=None)[source]

Retrieve the optimum from the database.

Override the super class method in order to return an OptimizationResult instance adapted for multi-objective results (see MultiObjectiveOptimizationResult).

Parameters
• message (str | None) –

The message from the optimizer.

By default it is set to None.

• status (int | None) –

The status from the optimizer.

By default it is set to None.

Returns

An optimization result object based on the optimum found.

Return type
get_right_sign_constraints()

Transforms the problem constraints into their opposite sign counterpart if the algorithm requires positive constraints.

get_x0_and_bounds_vects(normalize_ds)

Gets x0, bounds, normalized or not depending on algo options, all as numpy arrays.

Parameters

normalize_ds – Whether to normalize the input variables that are not integers, according to the normalization policy of the design space.

Returns

The current value, the lower bounds and the upper bounds.

init_iter_observer(max_iter, message)

Initialize the iteration observer.

It will handle the stopping criterion and the logging of the progress bar.

Parameters
• max_iter (int) – The maximum number of iterations.

• message (str) – The message to display at the beginning.

Raises

ValueError – If the max_iter is not greater than or equal to one.

Return type

None

init_options_grammar(algo_name)

Initialize the options grammar.

Parameters

algo_name (str) – The name of the algorithm.

Return type

gemseo.core.grammars.json_grammar.JSONGrammar

Returns True if the algorithm requires a gradient evaluation.

Parameters

algo_name – The name of the algorithm.

is_algo_requires_positive_cstr(algo_name)

Check if an algorithm requires positive constraints.

Parameters

algo_name (str) – The name of the algorithm.

Returns

Whether the algorithm requires positive constraints.

Return type

bool

static is_algorithm_suited(algorithm_description, problem)

Check if the algorithm is suited to the problem according to its description.

Parameters
Returns

Whether the algorithm is suited to the problem.

Return type

bool

new_iteration_callback(x_vect=None)
Raises
• FtolReached – If the defined relative or absolute function tolerance is reached.

• XtolReached – If the defined relative or absolute x tolerance is reached.

Parameters

x_vect (ndarray | None) –

By default it is set to None.

Return type

None

COMPLEX_STEP_METHOD = 'complex_step'
CROSSOVER_OPERATOR: Final[str] = 'crossover'

The crossover operator’s name.

DIFFERENTIATION_METHODS = ['user', 'complex_step', 'finite_differences']
EQ_TOLERANCE = 'eq_tolerance'
EVAL_OBS_JAC_OPTION = 'eval_obs_jac'
EVOLUTIONARY_OPERATORS: Final[list[str]] = ['crossover', 'mutation', 'sampling', 'selection']

A list with all evolutionary operators available.

FINITE_DIFF_METHOD = 'finite_differences'
F_TOL_ABS = 'ftol_abs'
F_TOL_REL = 'ftol_rel'
HV_TOL_ABS: Final[str] = 'hv_tol_abs'

The tag for the absolute tolerance used in the hypervolume convergence check.

HV_TOL_REL: Final[str] = 'hv_tol_rel'

The tag for the relative tolerance used in the hypervolume convergence check.

INEQ_TOLERANCE = 'ineq_tolerance'
LIBRARY_NAME: Final[str] = 'pymoo'

The library’s name.

LS_STEP_NB_MAX = 'max_ls_step_nb'
LS_STEP_SIZE_MAX = 'max_ls_step_size'
MAX_DS_SIZE_PRINT = 40
MAX_FUN_EVAL = 'max_fun_eval'
MAX_GEN: Final[str] = 'max_gen'

The tag for the maximum number of generations allowed.

MAX_ITER = 'max_iter'
MAX_TIME = 'max_time'
MUTATION_OPERATOR: Final[str] = 'mutation'

The mutation operator’s name.

NORMALIZE_DESIGN_SPACE_OPTION = 'normalize_design_space'
N_PROCESSES: Final[str] = 'n_processes'

The tag for the number of processes to use.

OPTIONS_DIR: Final[str] = 'options'

The name of the directory containing the files of the grammars of the options.

OPTIONS_MAP: dict[str, str] = {}

The names of the options in GEMSEO mapping to those in the wrapped library.

PG_TOL = 'pg_tol'
PYMOO_GA: Final[str] = 'PYMOO_GA'

The GEMSEO alias for the Genetic Algorithm.

PYMOO_NSGA2: Final[str] = 'PYMOO_NSGA2'

The GEMSEO alias for the Non-dominated Sorting Genetic Algorithm II.

PYMOO_NSGA3: Final[str] = 'PYMOO_NSGA3'

The GEMSEO alias for the Non-dominated Sorting Genetic Algorithm III.

PYMOO_RNSGA3: Final[str] = 'PYMOO_RNSGA3'

The GEMSEO alias for the Reference Point Based NSGA-III.

PYMOO_UNSGA3: Final[str] = 'PYMOO_UNSGA3'

The GEMSEO alias for the Unified NSGA-III.

ROUND_INTS_OPTION = 'round_ints'
SAMPLING_OPERATOR: Final[str] = 'sampling'

The sampling operator’s name.

SELECTION_OPERATOR: Final[str] = 'selection'

The selection operator’s name.

STOP_CRIT_NX = 'stop_crit_n_x'
STOP_CRIT_N_HV: Final[str] = 'stop_crit_n_hv'

The tag for the number of generations to account for in the hypervolume check.

USE_DATABASE_OPTION = 'use_database'
VERBOSE = 'verbose'
X_TOL_ABS = 'xtol_abs'
X_TOL_REL = 'xtol_rel'
activate_progress_bar: ClassVar[bool] = True

Whether to activate the progress bar in the optimization log.

algo_name: str | None

The name of the algorithm used currently.

property algorithms: list[str]

The available algorithms.

descriptions: dict[str, AlgorithmDescription]

The description of the algorithms contained in the library.

internal_algo_name: str | None

The internal name of the algorithm used currently.

It typically corresponds to the name of the algorithm in the wrapped library if any.

opt_grammar: JSONGrammar | None

The grammar defining the options of the current algorithm.

problem: Any | None

The problem to be solved.

pymoo_n_gen: int = 10000000

The pymoo’s termination criterion based on the number of generations.