lib_nlopt module¶
NLopt library wrapper.
Warning
If the objective, or a constraint, of the OptimizationProblem
returns a value of type int
then nlopt.opt.optimize
will terminate with
ValueError: nlopt invalid argument
.
This behavior has been identified as a bug internal to NLopt 2.7.1 and has been fixed in the development version of NLopt.
Until a new version of NLopt including the bugfix is released,
the user of GEMSEO shall provide objective and constraint functions
that return values of type float
and NDArray[float]
.
- class gemseo.algos.opt.lib_nlopt.NLoptAlgorithmDescription(algorithm_name, internal_algorithm_name, library_name='NLopt', description='', website='', handle_integer_variables=False, require_gradient=False, handle_equality_constraints=False, handle_inequality_constraints=False, handle_multiobjective=False, positive_constraints=False, problem_type=ProblemType.NON_LINEAR)[source]
Bases:
OptimizationAlgorithmDescription
The description of an optimization algorithm from the NLopt library.
- Parameters:
algorithm_name (str) –
internal_algorithm_name (str) –
library_name (str) –
By default it is set to “NLopt”.
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 False.
require_gradient (bool) –
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 False.
handle_multiobjective (bool) –
By default it is set to False.
positive_constraints (bool) –
By default it is set to False.
problem_type (OptimizationProblem.ProblemType) –
By default it is set to “non-linear”.
- algorithm_name: str
The name of the algorithm in GEMSEO.
- internal_algorithm_name: str
The name of the algorithm in the wrapped library.
- library_name: str = 'NLopt'
The name of the wrapped library.
- class gemseo.algos.opt.lib_nlopt.Nlopt[source]
Bases:
OptimizationLibrary
NLopt optimization library interface.
See OptimizationLibrary.
Notes
The missing current values of the
DesignSpace
attached to theOptimizationProblem
are automatically initialized with the methodDesignSpace.initialize_missing_current_values()
.- CTOL_ABS = 'ctol_abs'
- FAILURE = 'NLOPT_FAILURE: Generic failure code'
- FORCED_STOP = "NLOPT_FORCED_STOP: Halted because of a forced termination: the user called nlopt_force_stop(opt) on the optimization's nlopt_opt object opt from the user's objective function or constraints."
- FTOL_REACHED = 'NLOPT_FTOL_REACHED: Optimization stopped because ftol_rel or ftol_abs (above) was reached'
- INIT_STEP = 'init_step'
- INNER_MAXEVAL = 'inner_maxeval'
- INVALID_ARGS = 'NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).'
- LIB_COMPUTE_GRAD = False
- MAXEVAL_REACHED = 'NLOPT_MAXEVAL_REACHED: Optimization stopped because maxeval (above) was reached'
- MAXTIME_REACHED = 'NLOPT_MAXTIME_REACHED: Optimization stopped because maxtime (above) was reached'
- NLOPT_MESSAGES: ClassVar[dict[int, str]] = {-5: "NLOPT_FORCED_STOP: Halted because of a forced termination: the user called nlopt_force_stop(opt) on the optimization's nlopt_opt object opt from the user's objective function or constraints.", -4: 'NLOPT_ROUNDOFF_LIMITED: Halted because roundoff errors limited progress. (In this case, the optimization still typically returns a useful result.)', -3: 'OUT_OF_MEMORY: Ran out of memory', -2: 'NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).', -1: 'NLOPT_FAILURE: Generic failure code', 1: 'NLOPT_SUCCESS: Generic success return value', 2: 'NLOPT_STOPVAL_REACHED: Optimization stopped because stopval (above) was reached', 3: 'NLOPT_FTOL_REACHED: Optimization stopped because ftol_rel or ftol_abs (above) was reached', 4: 'NLOPT_XTOL_REACHED Optimization stopped because xtol_rel or xtol_abs (above) was reached', 5: 'NLOPT_MAXEVAL_REACHED: Optimization stopped because maxeval (above) was reached', 6: 'NLOPT_MAXTIME_REACHED: Optimization stopped because maxtime (above) was reached'}
- OUT_OF_MEMORY = 'OUT_OF_MEMORY: Ran out of memory'
- ROUNDOFF_LIMITED = 'NLOPT_ROUNDOFF_LIMITED: Halted because roundoff errors limited progress. (In this case, the optimization still typically returns a useful result.)'
- STOPVAL = 'stopval'
- STOPVAL_REACHED = 'NLOPT_STOPVAL_REACHED: Optimization stopped because stopval (above) was reached'
- SUCCESS = 'NLOPT_SUCCESS: Generic success return value'
- XTOL_REACHED = 'NLOPT_XTOL_REACHED Optimization stopped because xtol_rel or xtol_abs (above) was reached'
- 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: OptimizationProblem
The optimization problem the driver library is bonded to.