gemseo / algos / opt

lib_snopt module

SNOPT optimization library wrapper

Classes:

SnOpt()

SNOPT optimization library interface.

class gemseo.algos.opt.lib_snopt.SnOpt[source]

Bases: gemseo.algos.opt.opt_lib.OptimizationLibrary

SNOPT optimization library interface.

See OptimizationLibrary.

Constructor.

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

  • does it require gradient

  • does it handle equality constraints

  • does it handle inequality constraints

Attributes:

COMPLEX_STEP_METHOD

DESCRIPTION

DIFFERENTIATION_METHODS

EQ_TOLERANCE

FINITE_DIFF_METHOD

F_TOL_ABS

F_TOL_REL

HANDLE_EQ_CONS

HANDLE_INEQ_CONS

INEQ_TOLERANCE

INTERNAL_NAME

LIB

LIB_COMPUTE_GRAD

LS_STEP_NB_MAX

LS_STEP_SIZE_MAX

MAX_DS_SIZE_PRINT

MAX_FUN_EVAL

MAX_ITER

MAX_TIME

MESSAGES_DICT

NORMALIZE_DESIGN_SPACE_OPTION

OPTIONS_DIR

OPTIONS_MAP

PG_TOL

POSITIVE_CONSTRAINTS

PROBLEM_TYPE

REQUIRE_GRAD

ROUND_INTS_OPTION

STOP_CRIT_NX

USER_DEFINED_GRADIENT

USE_DATABASE_OPTION

VERBOSE

WEBSITE

X_TOL_ABS

X_TOL_REL

algorithms

Return the available algorithms.

Methods:

algorithm_handles_eqcstr(algo_name)

Returns True if the algorithms handles equality constraints.

algorithm_handles_ineqcstr(algo_name)

Returns True if the algorithms handles inequality constraints.

cb_opt_constraints_snoptb(mode, nn_con, …)

Constraints function + constraints gradient of the optimizer for snOpt (from web.stanford.edu/group/SOL/guides/sndoc7.pdf)

cb_opt_objective_snoptb(mode, nn_obj, xn_vect)

Objective function + objective gradient of the optimizer for snOpt (from web.stanford.edu/group/SOL/guides/sndoc7.pdf)

cb_snopt_dummy_func(mode, nn_con, nn_jac, …)

Dummy function required for unconstrained problem.

driver_has_option(option_key)

Checks if the option key exists.

ensure_bounds(orig_func[, normalize])

Project the design vector onto the design space before execution.

execute(problem[, algo_name])

Executes the driver.

filter_adapted_algorithms(problem)

Filters the algorithms capable of solving the problem.

finalize_iter_observer()

Finalize the iteration observer.

get_optimum_from_database([message, status])

Retrieves the optimum from the database and builds an optimization result object from it.

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.

init_iter_observer(max_iter, message)

Initialize the iteration observer.

init_options_grammar(algo_name)

Initializes the options grammar.

is_algo_requires_grad(algo_name)

Returns True if the algorithm requires a gradient evaluation.

is_algo_requires_positive_cstr(algo_name)

Returns True if the algorithm requires positive constraints False otherwise.

is_algorithm_suited(algo_dict, problem)

Checks if the algorithm is suited to the problem according to its algo dict.

new_iteration_callback()

Callback called at each new iteration, ie every time a design vector that is not already in the database is proposed by the optimizer.

COMPLEX_STEP_METHOD = 'complex_step'
DESCRIPTION = 'description'
DIFFERENTIATION_METHODS = ['user', 'complex_step', 'finite_differences']
EQ_TOLERANCE = 'eq_tolerance'
FINITE_DIFF_METHOD = 'finite_differences'
F_TOL_ABS = 'ftol_abs'
F_TOL_REL = 'ftol_rel'
HANDLE_EQ_CONS = 'handle_equality_constraints'
HANDLE_INEQ_CONS = 'handle_inequality_constraints'
INEQ_TOLERANCE = 'ineq_tolerance'
INTERNAL_NAME = 'internal_algo_name'
LIB = 'lib'
LIB_COMPUTE_GRAD = False
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_ITER = 'max_iter'
MAX_TIME = 'max_time'
MESSAGES_DICT = {1: 'optimality conditions satisfied', 2: 'feasible point found', 3: 'requested accuracy could not be achieved', 11: 'infeasible linear constraints', 12: 'infeasible linear equalities', 13: 'nonlinear infeasibilities minimized', 14: 'infeasibilities minimized', 21: 'unbounded objective', 22: 'constraint violation limit reached', 31: 'iteration limit reached', 32: 'major iteration limit reached', 33: 'the superbasics limit is too small', 41: 'current point cannot be improved ', 42: 'singular basis', 43: 'cannot satisfy the general constraints', 44: 'ill-conditioned null-space basis', 51: 'incorrect objective derivatives', 52: 'incorrect constraint derivatives', 61: 'undefined function at the first feasible point', 62: 'undefined function at the initial point', 63: 'unable to proceed into undefined region', 72: 'terminated during constraint evaluation', 73: 'terminated during objective evaluation', 74: 'terminated from monitor routine', 81: 'work arrays must have at least 500 elements', 82: 'not enough character storage', 83: 'not enough integer storage', 84: 'not enough real storage', 91: 'invalid input argument', 92: 'basis file dimensions do not match this problem', 141: 'wrong number of basic variables', 142: 'error in basis package'}
NORMALIZE_DESIGN_SPACE_OPTION = 'normalize_design_space'
OPTIONS_DIR = 'options'
OPTIONS_MAP = {'max_iter': 'Iteration_limit'}
PG_TOL = 'pg_tol'
POSITIVE_CONSTRAINTS = 'positive_constraints'
PROBLEM_TYPE = 'problem_type'
REQUIRE_GRAD = 'require_grad'
ROUND_INTS_OPTION = 'round_ints'
STOP_CRIT_NX = 'stop_crit_n_x'
USER_DEFINED_GRADIENT = 'user'
USE_DATABASE_OPTION = 'use_database'
VERBOSE = 'verbose'
WEBSITE = 'website'
X_TOL_ABS = 'xtol_abs'
X_TOL_REL = 'xtol_rel'
algorithm_handles_eqcstr(algo_name)

Returns True if the algorithms handles equality constraints.

Parameters

algo_name – the name of the algorithm

Returns

True or False

algorithm_handles_ineqcstr(algo_name)

Returns True if the algorithms handles inequality constraints.

Parameters

algo_name – the name of the algorithm

Returns

True or False

property algorithms

Return the available algorithms.

cb_opt_constraints_snoptb(mode, nn_con, nn_jac, ne_jac, xn_vect, n_state)[source]

Constraints function + constraints gradient of the optimizer for snOpt (from web.stanford.edu/group/SOL/guides/sndoc7.pdf)

Parameters
  • mode – indicates whether obj or gradient or both must be assigned during the present call of function (0 ≤ mode ≤ 2). mode = 2, assign obj and the known components of gradient mode = 1, assign the known components of gradient. obj is ignored. mode = 0, only obj need be assigned; gradient is ignored.

  • nn_con – number of non-linear constraints

  • nn_jac – number of dv involved in non-linear constraint functions

  • ne_jac – number of non-zero elements in constraints gradient. dcstr is 2D ==> ne_jac = nn_con*nn_jac

  • xn_vect – normalized design vector

  • n_state – indicator for first and last call to current function n_state = 0: NTR n_state = 1: first call to driver.cb_opt_objective_snoptb n_state > 1, snOptB is calling subroutine for the last time and: n_state = 2 and the current x is optimal n_state = 3, the problem appears to be infeasible n_state = 4, the problem appears to be unbounded; n_state = 5, an iterations limit was reached.

Returns

status: may be used to indicate that you are unable to evaluate cstr or its gradients at the current x. (For example, the problem functions may not be defined there). cstr: constraints function (except perhaps if mode = 1) dcstr constraints jacobian array (except perhaps if mode = 0)

Return type

integer, np array, np array

cb_opt_objective_snoptb(mode, nn_obj, xn_vect, n_state=0)[source]

Objective function + objective gradient of the optimizer for snOpt (from web.stanford.edu/group/SOL/guides/sndoc7.pdf)

Parameters
  • mode – indicates whether obj or gradient or both must be assigned during the present call of function (0 \(\leq\) mode \(\leq\) 2). mode = 2, assign obj and the known components of gradient mode = 1, assign the known components of gradient. obj is ignored. mode = 0, only obj need be assigned; gradient is ignored.

  • nn_obj – number of design variables

  • xn_vect – normalized design vector

  • n_state – indicator for first and last call to current function n_state = 0: NTR n_state = 1: first call to driver.cb_opt_objective_snoptb n_state > 1, snOptB is calling subroutine for the last time and: n_state = 2 and the current x is optimal n_state = 3, the problem appears to be infeasible n_state = 4, the problem appears to be unbounded; n_state = 5, an iterations limit was reached. (Default value = 0)

Returns

status: may be used to indicate that you are unable to evaluate obj_f or its gradients at the current x. (For example, the problem functions may not be defined there). obj_f, objective function (except perhaps if mode = 1) objective jacobian array (except perhaps if mode = 0)

Return type

integer, np array, np array

static cb_snopt_dummy_func(mode, nn_con, nn_jac, ne_jac, xn_vect, n_state)[source]

Dummy function required for unconstrained problem.

Parameters
  • mode – param nn_con:

  • nn_jac – param ne_jac:

  • xn_vect – param n_state:

  • nn_con

  • ne_jac

  • n_state

driver_has_option(option_key)

Checks if the option key exists.

Parameters

option_key – the name of the option

Returns

True if the option is in the grammar

ensure_bounds(orig_func, normalize=True)

Project the design vector onto the design space before execution.

Parameters
  • orig_func – the original function

  • normalize – if True, use the normalized design space

Returns

the wrapped function

execute(problem, algo_name=None, **options)

Executes the driver.

Parameters
  • problem – the problem to be solved

  • algo_name – name of the algorithm if None, use self.algo_name which may have been set by the factory (Default value = None)

  • options – the options dict for the algorithm

filter_adapted_algorithms(problem)

Filters the algorithms capable of solving the problem.

Parameters

problem – the opt_problem to be solved

Returns

the list of adapted algorithms names

finalize_iter_observer()

Finalize the iteration observer.

get_optimum_from_database(message=None, status=None)

Retrieves the optimum from the database and builds an optimization result object from it.

Parameters
  • message – Default value = None)

  • status – Default value = None)

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 – if True, normalizes all input vars that are not integers, according to design space normalization policy

Returns

x, lower bounds, 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 – maximum number of calls

  • message – message to display at the beginning

init_options_grammar(algo_name)

Initializes the options grammar.

Parameters

algo_name – name of the algorithm

is_algo_requires_grad(algo_name)

Returns True if the algorithm requires a gradient evaluation.

Parameters

algo_name – name of the algorithm

is_algo_requires_positive_cstr(algo_name)

Returns True if the algorithm requires positive constraints False otherwise.

Parameters

algo_name – the name of the algorithm

Returns

True if constraints must be positive

Return type

logical

static is_algorithm_suited(algo_dict, problem)

Checks if the algorithm is suited to the problem according to its algo dict.

Parameters
  • algo_dict – the algorithm characteristics

  • problem – the opt_problem to be solved

new_iteration_callback()

Callback called at each new iteration, ie every time a design vector that is not already in the database is proposed by the optimizer.

Iterates the progress bar, implements the stop criteria