pyoptsparse_driver.py

pyoptsparse_driver.py#

OpenMDAO Wrapper for pyoptsparse.

pyoptsparse is based on pyOpt, which is an object-oriented framework for formulating and solving nonlinear constrained optimization problems, with additional MPI capability.

exception openmdao.drivers.pyoptsparse_driver.UserRequestedException[source]

Bases: Exception

User Requested Exception.

This exception indicates that the user has requested that SNOPT/pyoptsparse ceases model execution and reports to SNOPT that execution should be terminated.

__init__(*args, **kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class openmdao.drivers.pyoptsparse_driver.pyOptSparseDriver(**kwargs)[source]

Bases: Driver

Driver wrapper for pyoptsparse.

Pyoptsparse is based on pyOpt, which is an object-oriented framework for formulating and solving nonlinear constrained optimization problems, with additional MPI capability. pypptsparse has interfaces to the following optimizers: ALPSO, CONMIN, FSQP, IPOPT, NLPQLP, NSGA2, PSQP, SLSQP, SNOPT, NLPY_AUGLAG, NOMAD, ParOpt. Note that some of these are not open source and therefore not included in the pyoptsparse source code.

pyOptSparseDriver supports the following:

equality_constraints

inequality_constraints

two_sided_constraints

Parameters:
**kwargsdict of keyword arguments

Keyword arguments that will be mapped into the Driver options.

Attributes:
failbool

Flag that indicates failure of most recent optimization.

opt_settingsdict

Dictionary for setting optimizer-specific options.

pyopt_solutionSolution

Pyopt_sparse solution object.

_fill_NANsbool

Used internally to control when to return NANs for a bad evaluation.

_check_jacbool

Used internally to control when to perform singular checks on computed total derivs.

_exc_info3 item tuple

Storage for exception and traceback information for exception that was raised in the _objfunc or _gradfunc callbacks.

_in_user_function :bool

This is set to True at the start of a pyoptsparse callback to _objfunc and _gradfunc, and restored to False at the finish of each callback.

_indep_listlist

List of design variables.

_quantitieslist

Contains the objectives plus nonlinear constraints.

_signal_cache<Function>

Cached function pointer that was assigned as handler for signal defined in option user_terminate_signal.

_total_jac_sparsitydict, str, or None

Specifies sparsity of sub-jacobians of the total jacobian.

_user_termination_flagbool

This is set to True when the user sends a signal to terminate the job.

_model_ranbool

This is set to True after the full model has been run at least once.

__init__(**kwargs)[source]

Initialize pyopt.

add_recorder(recorder)

Add a recorder to the driver.

Parameters:
recorderCaseRecorder

A recorder instance.

check_relevance()

Check if there are constraints that don’t depend on any design vars.

This usually indicates something is wrong with the problem formulation.

cleanup()

Clean up resources prior to exit.

declare_coloring(num_full_jacs=3, tol=1e-25, orders=None, perturb_size=1e-09, min_improve_pct=5.0, show_summary=True, show_sparsity=False, use_scaling=False)

Set options for total deriv coloring.

Parameters:
num_full_jacsint

Number of times to repeat partial jacobian computation when computing sparsity.

tolfloat

Tolerance used to determine if an array entry is nonzero during sparsity determination.

ordersint

Number of orders above and below the tolerance to check during the tolerance sweep.

perturb_sizefloat

Size of input/output perturbation during generation of sparsity.

min_improve_pctfloat

If coloring does not improve (decrease) the number of solves more than the given percentage, coloring will not be used.

show_summarybool

If True, display summary information after generating coloring.

show_sparsitybool

If True, display sparsity with coloring info after generating coloring.

use_scalingbool

If True, use driver scaling when generating the sparsity.

get_constraint_values(ctype='all', lintype='all', driver_scaling=True)

Return constraint values.

Parameters:
ctypestr

Default is ‘all’. Optionally return just the inequality constraints with ‘ineq’ or the equality constraints with ‘eq’.

lintypestr

Default is ‘all’. Optionally return just the linear constraints with ‘linear’ or the nonlinear constraints with ‘nonlinear’.

driver_scalingbool

When True, return values that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is True.

Returns:
dict

Dictionary containing values of each constraint.

get_design_var_values(get_remote=True, driver_scaling=True)

Return the design variable values.

Parameters:
get_remotebool or None

If True, retrieve the value even if it is on a remote process. Note that if the variable is remote on ANY process, this function must be called on EVERY process in the Problem’s MPI communicator. If False, only retrieve the value if it is on the current process, or only the part of the value that’s on the current process for a distributed variable.

driver_scalingbool

When True, return values that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is True.

Returns:
dict

Dictionary containing values of each design variable.

get_driver_derivative_calls()[source]

Return number of derivative evaluations made during a driver run.

Returns:
int

Number of derivative evaluations made during a driver run.

get_driver_objective_calls()[source]

Return number of objective evaluations made during a driver run.

Returns:
int

Number of objective evaluations made during a driver run.

get_exit_status()

Return exit status of driver run.

Returns:
str

String indicating result of driver run.

get_objective_values(driver_scaling=True)

Return objective values.

Parameters:
driver_scalingbool

When True, return values that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is True.

Returns:
dict

Dictionary containing values of each objective.

get_reports_dir()

Get the path to the directory where the report files should go.

If it doesn’t exist, it will be created.

Returns:
str

The path to the directory where reports should be written.

property hist_file

Get the ‘hist_file’ option for this driver.

property hotstart_file

Get the ‘hotstart_file’ option for this driver.

property msginfo

Return info to prepend to messages.

Returns:
str

Info to prepend to messages.

record_derivatives()

Record the current total jacobian.

record_iteration()

Record an iteration of the current Driver.

run()[source]

Excute pyOptsparse.

Note that pyOpt controls the execution, and the individual optimizers (e.g., SNOPT) control the iteration.

Returns:
bool

Failure flag; True if failed to converge, False is successful.

scaling_report(outfile='driver_scaling_report.html', title=None, show_browser=True, jac=True)

Generate a self-contained html file containing a detailed connection viewer.

Optionally pops up a web browser to view the file.

Parameters:
outfilestr, optional

The name of the output html file. Defaults to ‘driver_scaling_report.html’.

titlestr, optional

Sets the title of the web page.

show_browserbool, optional

If True, pop up a browser to view the generated html file. Defaults to True.

jacbool

If True, show jacobian information.

Returns:
dict

Data used to create html file.

set_design_var(name, value, set_remote=True)

Set the value of a design variable.

‘name’ can be a promoted output name or an alias.

Parameters:
namestr

Global pathname of the design variable.

valuefloat or ndarray

Value for the design variable.

set_remotebool

If True, set the global value of the variable (value must be of the global size). If False, set the local value of the variable (value must be of the local size).

use_fixed_coloring(coloring=<object object>)

Tell the driver to use a precomputed coloring.

Parameters:
coloringstr or Coloring

A coloring filename or a Coloring object. If no arg is passed, filename will be determined automatically.