problem.py

OpenMDAO Problem class defintion.

class openmdao.core.problem.Problem(root=None, driver=None, impl=None, comm=None, debug=False)[source]

Bases: object

The Problem is always the top object for running an OpenMDAO model.

Args:

root : Group, optional

The top-level Group for the Problem. If not specified, a default Group will be created

driver : Driver, optional

The top-level Driver for the Problem. If not specified, a default “Run Once” Driver will be used

impl : BasicImpl or PetscImpl, optional

The vector and data transfer implementation for the Problem. For parallel processing support using MPI, PetscImpl is required. If not specified, the default BasicImpl will be used.

comm : an MPI communicator (real or fake), optional

A communicator that can be used for distributed operations when running under MPI. If not specified, the default “COMM_WORLD” will be used.

debug : bool(False)

If set to True, all numpy floating point errors raise exceptions and the variable locations that go to inf or nan are printed when they can be determined.

calc_gradient(indep_list, unknown_list, mode='auto', return_format='array', dv_scale=None, cn_scale=None, sparsity=None, use_check=False, inactives=None)[source]

Returns the gradient for the system that is specified in self.root. This function is used by the optimizer but also can be used for testing derivatives on your model.

Args:

indep_list : iter of strings

Iterator of independent variable names that derivatives are to be calculated with respect to. All params must have a IndepVarComp.

unknown_list : iter of strings

Iterator of output or state names that derivatives are to be calculated for. All must be valid unknowns in OpenMDAO.

mode : string, optional

Deriviative direction, can be ‘fwd’, ‘rev’, ‘fd’, or ‘auto’. Default is ‘auto’, which uses mode specified on the linear solver in root.

return_format : string, optional

Format for the derivatives, can be ‘array’ or ‘dict’.

dv_scale : dict, optional

Dictionary of driver-defined scale factors on the design variables.

cn_scale : dict, optional

Dictionary of driver-defined scale factors on the constraints.

sparsity : dict, optional

Dictionary that gives the relevant design variables for each constraint. This option is only supported in the dict return format.

use_check : bool(False)

This is only set to True when called from check_total_derivatives, and is used to make the FD calculation use the check options instead of the regular ones.

inactives : dict, optional

Dictionary of all inactive constraints. Gradient calculation is skipped for these in adjoine mode. Key is the constraint name, and value is the indices that are inactive.

Returns:

ndarray or dict

Jacobian of unknowns with respect to params.

check_partial_derivatives(out_stream=<open file '<stdout>', mode 'w'>, comps=None, compact_print=False, abs_err_tol=1e-06, rel_err_tol=1e-06, global_options=None)[source]

Checks partial derivatives comprehensively for all components in your model.

Args:

out_stream : file_like

Where to send human readable output. Default is sys.stdout. Set to None to suppress.

comps : None or list_like

List of component names to check the partials of (all others will be skipped). Set to None (default) to run all components

compact_print : bool

Set to True to just print the essentials, one line per unknown-param pair.

abs_err_tol : float

Threshold value for absolute error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Default is 1.0E-6.

rel_err_tol : float

Threshold value for relative error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Note at times there may be a significant relative error due to a minor absolute error. Default is 1.0E-6.

global_options : dict

Dictionary of options that override options specified in ALL components. Only ‘check_form’, ‘check_step_size’, ‘check_step_calc’, and ‘check_type’ can be specified in this way.

Returns:

Dict of Dicts of Dicts

First key is the component name;

2nd key is the (output, input) tuple of strings;

third key is one of [‘rel error’, ‘abs error’, ‘magnitude’, ‘J_fd’, ‘J_fwd’, ‘J_rev’];

For ‘rel error’, ‘abs error’, ‘magnitude’ the value is:

A tuple containing norms for forward - fd, adjoint - fd, forward - adjoint using the best case fdstep

For ‘J_fd’, ‘J_fwd’, ‘J_rev’ the value is:

A numpy array representing the computed Jacobian for the three different methods of computation

check_setup(out_stream=<open file '<stdout>', mode 'w'>)[source]

Write a report to the given stream indicating any potential problems found with the current configuration of this Problem.

Args:

out_stream : a file-like object, optional

Stream where report will be written.

check_total_derivatives(out_stream=<open file '<stdout>', mode 'w'>, abs_err_tol=1e-06, rel_err_tol=1e-06)[source]

Checks total derivatives for problem defined at the top.

Args:

out_stream : file_like

Where to send human readable output. Default is sys.stdout. Set to None to suppress.

abs_err_tol : float

Threshold value for absolute error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Default is 1.0E-6.

rel_err_tol : float

Threshold value for relative error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Note at times there may be a significant relative error due to a minor absolute error. Default is 1.0E-6.

Returns:

Dict of Dicts of Tuples of Floats

First key is the (output, input) tuple of strings; second key is one

of [‘rel error’, ‘abs error’, ‘magnitude’, ‘fdstep’]; Tuple contains

norms for forward - fd, adjoint - fd, forward - adjoint using the

best case fdstep.

cleanup()[source]

Clean up resources prior to exit.

find_subsystem(name)[source]

Returns a reference to a named subsystem within this problem. Raises an exception if the given name doesn’t reference a subsystem.

Args:

name : str

Name of the subsystem to retrieve.

Returns:

System

A reference to the named subsystem.

get_req_procs()[source]
Returns:

tuple

A tuple of the form (min_procs, max_procs), indicating the min and max processors usable by this Problem.

pre_run_check()[source]

Last chance for some checks. The checks that should be performed here are those that would generate a cryptic error message. We can raise a readable error for the user.

print_all_convergence(level=2, depth=1e+99)[source]

Sets iprint to True for all solvers and subsolvers in the model.

Args:

level : int(2)

iprint level. Set to 2 to print residuals each iteration; set to 1 to print just the iteration totals; set to 0 to disable all printing except for failures.

depth : int(1e99)

How deep to recurse. For example, you can set this to 0 if you only want to print the top level linear and nonlinear solver messages. Default prints everything.

run()[source]

Runs the Driver in self.driver.

run_once()[source]

Execute run_once in the driver, executing the model at the the current design point.

setup(check=True, out_stream=<open file '<stdout>', mode 'w'>)[source]

Performs all setup of vector storage, data transfer, etc., necessary to perform calculations.

Args:

check : bool, optional

Check for potential issues after setup is complete (the default is True)

out_stream : a file-like object, optional

Stream where report will be written if check is performed.