problem.py

OpenMDAO Problem class defintion.

class openmdao.core.problem.Problem(root=None, driver=None, impl=None, comm=None)[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.

Options:

fd_options[‘force_fd’] : bool(False)

Set to True to finite difference this system.

fd_options[‘form’] : str(‘forward’)

Finite difference mode. (forward, backward, central) You can also set to ‘complex_step’ to peform the complex step method if your components support it.

fd_options[‘step_size’] : float(1e-06)

Default finite difference stepsize

fd_options[‘step_type’] : str(‘absolute’)

Set to absolute, relative

fd_options[‘extra_check_partials_form’] : None or str

Finite difference mode: (“forward”, “backward”, “central”, “complex_step”) During check_partial_derivatives, you can optionally do a second finite difference with a different mode.

fd_options[‘linearize’] : bool(False)

Set to True if you want linearize to be called even though you are using FD.

calc_gradient(indep_list, unknown_list, mode='auto', return_format='array', dv_scale=None, cn_scale=None, sparsity=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.

Returns:

ndarray or dict

Jacobian of unknowns with respect to params.

check_partial_derivatives(out_stream=<open file '<stdout>', mode 'w'>)[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.

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'>)[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.

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.

print_all_convergence()[source]

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

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.