driver.py

Define a base class for all Drivers in OpenMDAO.

class openmdao.core.driver.Driver(**kwargs)[source]

Bases: object

Top-level container for the systems and drivers.

Attributes

fail

(bool) Reports whether the driver ran successfully.

iter_count

(int) Keep track of iterations for case recording.

options

(<OptionsDictionary>) Dictionary with general pyoptsparse options.

recording_options

(<OptionsDictionary>) Dictionary with driver recording options.

cite

(str) Listing of relevant citations that should be referenced when publishing work that uses this class.

supports

(<OptionsDictionary>) Provides a consistent way for drivers to declare what features they support.

__init__(self, **kwargs)[source]

Initialize the driver.

Parameters
**kwargsdict of keyword arguments

Keyword arguments that will be mapped into the Driver options.

add_recorder(self, recorder)[source]

Add a recorder to the driver.

Parameters
recorderCaseRecorder

A recorder instance.

cleanup(self)[source]

Clean up resources prior to exit.

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

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.

get_constraint_values(self, ctype='all', lintype='all', driver_scaling=True)[source]

Return constraint values.

Parameters
ctypestring

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

lintypestring

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(self)[source]

Return the design variable values.

Returns
dict

Dictionary containing values of each design variable.

get_objective_values(self, driver_scaling=True)[source]

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.

property msginfo

Return info to prepend to messages.

Returns
str

Info to prepend to messages.

record_iteration(self)[source]

Record an iteration of the current Driver.

run(self)[source]

Execute this driver.

The base Driver just runs the model. All other drivers overload this method.

Returns
boolean

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

set_design_var(self, name, value)[source]

Set the value of a design variable.

Parameters
namestr

Global pathname of the design variable.

valuefloat or ndarray

Value for the design variable.

use_fixed_coloring(self, coloring=<object object at 0x7fdd46258cf0>)[source]

Tell the driver to use a precomputed coloring.

Parameters
coloringstr

A coloring filename. If no arg is passed, filename will be determined automatically.

class openmdao.core.driver.RecordingDebugging(name, iter_count, recording_requester)[source]

Bases: openmdao.recorders.recording_iteration_stack.Recording

A class that acts as a context manager.

Handles doing the case recording and also the Driver debugging printing.

__init__(self, name, iter_count, recording_requester)

Initialize Recording.

Parameters
namestr

Name of object getting recorded.

iter_countint

Current counter of iterations completed.

recording_requesterobject

The object that wants to be recorded.

openmdao.core.driver.record_iteration(requester, prob, case_name)[source]

Record an iteration of the current Problem or Driver.

Parameters
requesterProblem or Driver

The recording requester.

probProblem

The Problem.

case_namestr

The name of this case.