jacobian.py#
Define the base Jacobian class.
- openmdao.jacobians.jacobian.AssembledJacobian
alias of
SplitJacobian
- class openmdao.jacobians.jacobian.CSCJacobian(system)[source]
Bases:
SplitJacobian
Assemble sparse global <Jacobian> in Compressed Col Storage format.
- Parameters:
- systemSystem
Parent system to this jacobian.
- __contains__(key)
Return whether there is a subjac for the given promoted or relative name pair.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- bool
return whether sub-Jacobian has been defined.
- __getitem__(key)
Get sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- ndarray or sparse matrix
sub-Jacobian as an array or sparse matrix.
- __init__(system)[source]
Initialize all attributes.
- __iter__()
Yield next name pair of sub-Jacobian.
- Yields:
- str
- __setitem__(key, subjac)
Set sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- subjacfloat or ndarray or sparse matrix
sub-Jacobian as a scalar, array, or sparse matrix.
- create_dr_do_subjac(conns, abs_key, src, meta, dtype, src_indices=None, factor=None)
Create a subjacobian for a square internal jacobian (d(residual)/d(source)).
- Parameters:
- connsdict
Global connection dictionary.
- abs_keytuple
The absolute key for the subjacobian.
- srcstr or None
Source name for the subjacobian.
- metadict
Metadata for the subjacobian.
- dtypedtype
The dtype of the subjacobian.
- src_indicesarray or None
Source indices for the subjacobian.
- factorfloat or None
Factor for the subjacobian.
- Returns:
- Subjac
The created subjacobian.
- create_subjac(abs_key, meta, dtype)
Create a subjacobian.
- Parameters:
- abs_keytuple
The absolute key for the subjacobian.
- metadict
Metadata for the subjacobian.
- dtypedtype
The dtype of the subjacobian.
- Returns:
- Subjac
The created subjacobian,.
- get_dr_di_matrix()
Get the dr/di matrix.
- Returns:
- Matrix
The dr/di matrix.
- get_dr_do_matrix()
Get the dr/do matrix.
- Returns:
- Matrix
The dr/do matrix.
- get_metadata(key)
Get metadata for the given key.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- dict
Metadata dict for the given key.
- items()
Yield name pair and value of sub-Jacobian.
- Yields:
- str
- keys()
Yield next name pair of sub-Jacobian.
- Yields:
- str
- set_col(system, icol, column)
Set a column of the jacobian.
The column is assumed to be the same size as a column of the jacobian.
This also assumes that the column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- icolint
Column index.
- columnndarray
Column value.
- set_csc_jac(system, jac)
Assign a CSC jacobian to this jacobian.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jaccsc_matrix
CSC jacobian.
- set_dense_jac(system, jac)
Assign a dense jacobian to this jacobian.
This assumes that any column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jacndarray
Dense jacobian.
- todense()
Return a dense version of the jacobian.
- Returns:
- ndarray
Dense version of the jacobian.
- class openmdao.jacobians.jacobian.CSRJacobian(system)[source]
Bases:
SplitJacobian
Assemble sparse global <Jacobian> in Compressed Col Storage format.
- Parameters:
- systemSystem
Parent system to this jacobian.
- __contains__(key)
Return whether there is a subjac for the given promoted or relative name pair.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- bool
return whether sub-Jacobian has been defined.
- __getitem__(key)
Get sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- ndarray or sparse matrix
sub-Jacobian as an array or sparse matrix.
- __init__(system)[source]
Initialize all attributes.
- __iter__()
Yield next name pair of sub-Jacobian.
- Yields:
- str
- __setitem__(key, subjac)
Set sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- subjacfloat or ndarray or sparse matrix
sub-Jacobian as a scalar, array, or sparse matrix.
- create_dr_do_subjac(conns, abs_key, src, meta, dtype, src_indices=None, factor=None)
Create a subjacobian for a square internal jacobian (d(residual)/d(source)).
- Parameters:
- connsdict
Global connection dictionary.
- abs_keytuple
The absolute key for the subjacobian.
- srcstr or None
Source name for the subjacobian.
- metadict
Metadata for the subjacobian.
- dtypedtype
The dtype of the subjacobian.
- src_indicesarray or None
Source indices for the subjacobian.
- factorfloat or None
Factor for the subjacobian.
- Returns:
- Subjac
The created subjacobian.
- create_subjac(abs_key, meta, dtype)
Create a subjacobian.
- Parameters:
- abs_keytuple
The absolute key for the subjacobian.
- metadict
Metadata for the subjacobian.
- dtypedtype
The dtype of the subjacobian.
- Returns:
- Subjac
The created subjacobian,.
- get_dr_di_matrix()
Get the dr/di matrix.
- Returns:
- Matrix
The dr/di matrix.
- get_dr_do_matrix()
Get the dr/do matrix.
- Returns:
- Matrix
The dr/do matrix.
- get_metadata(key)
Get metadata for the given key.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- dict
Metadata dict for the given key.
- items()
Yield name pair and value of sub-Jacobian.
- Yields:
- str
- keys()
Yield next name pair of sub-Jacobian.
- Yields:
- str
- set_col(system, icol, column)
Set a column of the jacobian.
The column is assumed to be the same size as a column of the jacobian.
This also assumes that the column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- icolint
Column index.
- columnndarray
Column value.
- set_csc_jac(system, jac)
Assign a CSC jacobian to this jacobian.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jaccsc_matrix
CSC jacobian.
- set_dense_jac(system, jac)
Assign a dense jacobian to this jacobian.
This assumes that any column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jacndarray
Dense jacobian.
- todense()
Return a dense version of the jacobian.
- Returns:
- ndarray
Dense version of the jacobian.
- class openmdao.jacobians.jacobian.DenseJacobian(system)[source]
Bases:
SplitJacobian
Assemble dense global <Jacobian>.
- Parameters:
- systemSystem
Parent system to this jacobian.
- __contains__(key)
Return whether there is a subjac for the given promoted or relative name pair.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- bool
return whether sub-Jacobian has been defined.
- __getitem__(key)
Get sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- ndarray or sparse matrix
sub-Jacobian as an array or sparse matrix.
- __init__(system)[source]
Initialize all attributes.
- __iter__()
Yield next name pair of sub-Jacobian.
- Yields:
- str
- __setitem__(key, subjac)
Set sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- subjacfloat or ndarray or sparse matrix
sub-Jacobian as a scalar, array, or sparse matrix.
- create_dr_do_subjac(conns, abs_key, src, meta, dtype, src_indices=None, factor=None)
Create a subjacobian for a square internal jacobian (d(residual)/d(source)).
- Parameters:
- connsdict
Global connection dictionary.
- abs_keytuple
The absolute key for the subjacobian.
- srcstr or None
Source name for the subjacobian.
- metadict
Metadata for the subjacobian.
- dtypedtype
The dtype of the subjacobian.
- src_indicesarray or None
Source indices for the subjacobian.
- factorfloat or None
Factor for the subjacobian.
- Returns:
- Subjac
The created subjacobian.
- create_subjac(abs_key, meta, dtype)
Create a subjacobian.
- Parameters:
- abs_keytuple
The absolute key for the subjacobian.
- metadict
Metadata for the subjacobian.
- dtypedtype
The dtype of the subjacobian.
- Returns:
- Subjac
The created subjacobian,.
- get_dr_di_matrix()
Get the dr/di matrix.
- Returns:
- Matrix
The dr/di matrix.
- get_dr_do_matrix()
Get the dr/do matrix.
- Returns:
- Matrix
The dr/do matrix.
- get_metadata(key)
Get metadata for the given key.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- dict
Metadata dict for the given key.
- items()
Yield name pair and value of sub-Jacobian.
- Yields:
- str
- keys()
Yield next name pair of sub-Jacobian.
- Yields:
- str
- set_col(system, icol, column)
Set a column of the jacobian.
The column is assumed to be the same size as a column of the jacobian.
This also assumes that the column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- icolint
Column index.
- columnndarray
Column value.
- set_csc_jac(system, jac)
Assign a CSC jacobian to this jacobian.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jaccsc_matrix
CSC jacobian.
- set_dense_jac(system, jac)
Assign a dense jacobian to this jacobian.
This assumes that any column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jacndarray
Dense jacobian.
- todense()
Return a dense version of the jacobian.
- Returns:
- ndarray
Dense version of the jacobian.
- class openmdao.jacobians.jacobian.GroupJacobianUpdateContext(group)[source]
Bases:
object
Within this context, the Jacobian may be updated.
- Ways to update:
set_col, during computation of approximate derivatives
full subjac update after recursive linearization of children
- Parameters:
- groupGroup
The group that owns this jacobian.
- Attributes:
- groupGroup
The group that owns this jacobian.
- jacJacobian
The jacobian that is being updated.
- __init__(group)[source]
Initialize the context.
- Parameters:
- groupGroup
The group that owns this jacobian.
- class openmdao.jacobians.jacobian.Jacobian(system)[source]
Bases:
object
Base Jacobian class.
This class provides a dictionary interface for sub-Jacobians and performs matrix-vector products when apply_linear is called.
- Parameters:
- systemSystem
Parent system to this jacobian.
- Attributes:
- _subjacs_infodict
Dictionary of the sub-Jacobian metadata keyed by absolute names.
- _subjacsdict
Dictionary of the sub-Jacobian objects keyed by absolute names.
- _under_complex_stepbool
When True, this Jacobian is under complex step, using a complex jacobian.
- _abs_keysdict
A cache dict for key to absolute key.
- _col_mapperRangeMapper
Maps variable names to column indices and vice versa.
- _problem_metadict
Problem metadata.
- _resolver<Resolver>
Resolver for this system.
- _output_slicesdict
Maps output names to slices of the output vector.
- _input_slicesdict
Maps input names to slices of the input vector.
- _has_approxbool
Whether the system has an approximate jacobian.
- _is_explicitcompbool
Whether the system is explicit.
- _ordered_subjac_keyslist
List of subjac keys in order of appearance.
- _initializedbool
Whether the jacobian has been initialized.
- dtypedtype
The dtype of the jacobian.
- shapetuple
Full shape of the jacobian, including dr/do and dr/di.
- __contains__(key)[source]
Return whether there is a subjac for the given promoted or relative name pair.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- bool
return whether sub-Jacobian has been defined.
- __getitem__(key)[source]
Get sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- ndarray or sparse matrix
sub-Jacobian as an array or sparse matrix.
- __init__(system)[source]
Initialize all attributes.
- __iter__()[source]
Yield next name pair of sub-Jacobian.
- Yields:
- str
- __setitem__(key, subjac)[source]
Set sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- subjacfloat or ndarray or sparse matrix
sub-Jacobian as a scalar, array, or sparse matrix.
- create_subjac(abs_key, meta, dtype)[source]
Create a subjacobian.
- Parameters:
- abs_keytuple
The absolute key for the subjacobian.
- metadict
Metadata for the subjacobian.
- dtypedtype
The dtype of the subjacobian.
- Returns:
- Subjac
The created subjacobian,.
- get_metadata(key)[source]
Get metadata for the given key.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- dict
Metadata dict for the given key.
- items()[source]
Yield name pair and value of sub-Jacobian.
- Yields:
- str
- keys()[source]
Yield next name pair of sub-Jacobian.
- Yields:
- str
- set_col(system, icol, column)[source]
Set a column of the jacobian.
The column is assumed to be the same size as a column of the jacobian.
This also assumes that the column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- icolint
Column index.
- columnndarray
Column value.
- set_csc_jac(system, jac)[source]
Assign a CSC jacobian to this jacobian.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jaccsc_matrix
CSC jacobian.
- set_dense_jac(system, jac)[source]
Assign a dense jacobian to this jacobian.
This assumes that any column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jacndarray
Dense jacobian.
- todense()[source]
Return a dense version of the full jacobian.
This includes the combined dr/do and dr/di matrices.
- Returns:
- ndarray
Dense version of the full jacobian.
- class openmdao.jacobians.jacobian.JacobianUpdateContext(system)[source]
Bases:
object
Within this context, the Jacobian may be updated.
- Ways to update:
__setitem__, during component compute_jacvec_product or linearize
set_col, during computation of approximate derivatives
set_dense_jac, during linearization of jax components
- Parameters:
- systemSystem
The system that owns this jacobian.
- Attributes:
- systemSystem
The system that owns this jacobian.
- jacJacobian
The jacobian that is being updated.
- __init__(system)[source]
Initialize the context.
- Parameters:
- systemSystem
The system that owns this jacobian.
- class openmdao.jacobians.jacobian.SplitJacobian(matrix_class, system)[source]
Bases:
Jacobian
A Jacobian that is split into dr/do and dr/di parts.
The dr/di matrix contains the derivatives of the residuals with respect to the inputs. In fwd mode it is applied to the dinputs vector and the result updates the dresiduals vector. In rev mode its transpose is applied to the dresiduals vector and the result updates the dinputs vector.
The dr/do matrix contains the derivatives of the residuals with respect to the outputs. In fwd mode it is applied to the doutputs vector and the result updates the dresiduals vector. In rev mode its transpose is applied to the dresiduals vector and the result updates the doutputs vector. It is always square and can be used by a direct solver to perform a linear solve.
Explicit components use only the dr/di matrix since the dr/do matrix in the explicit case is constant and equal to negative identity so its effects can be applied without creating the matrix at all.
Implicit components and Groups use both matrices.
- Parameters:
- matrix_classMatrix
The matrix class to use for the dr/do and dr/di matrices.
- systemSystem
System that is updating this jacobian.
- Attributes:
- _dr_do_subjacsdict
Dictionary containing subjacobians of residuals with respect to outputs, keyed by (of, wrt) tuples containing absolute names.
- _dr_di_subjacsdict
Dictionary containing subjacobians of residuals with respect to inputs, keyed by (of, wrt) tuples containing absolute names.
- _dr_do_mtxMatrix
Matrix containing the dr/do subjacs.
- _dr_di_mtxMatrix
Matrix containing the dr/di subjacs.
- _mask_cachesdict
Dictionary containing mask caches for the dr/di matrix.
- __contains__(key)
Return whether there is a subjac for the given promoted or relative name pair.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- bool
return whether sub-Jacobian has been defined.
- __getitem__(key)
Get sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- ndarray or sparse matrix
sub-Jacobian as an array or sparse matrix.
- __init__(matrix_class, system)[source]
Initialize the SplitJacobian.
- Parameters:
- matrix_classMatrix
The matrix class to use for the dr/do and dr/di matrices.
- systemSystem
The system that owns this jacobian.
- __iter__()
Yield next name pair of sub-Jacobian.
- Yields:
- str
- __setitem__(key, subjac)
Set sub-Jacobian.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- subjacfloat or ndarray or sparse matrix
sub-Jacobian as a scalar, array, or sparse matrix.
- create_dr_do_subjac(conns, abs_key, src, meta, dtype, src_indices=None, factor=None)[source]
Create a subjacobian for a square internal jacobian (d(residual)/d(source)).
- Parameters:
- connsdict
Global connection dictionary.
- abs_keytuple
The absolute key for the subjacobian.
- srcstr or None
Source name for the subjacobian.
- metadict
Metadata for the subjacobian.
- dtypedtype
The dtype of the subjacobian.
- src_indicesarray or None
Source indices for the subjacobian.
- factorfloat or None
Factor for the subjacobian.
- Returns:
- Subjac
The created subjacobian.
- create_subjac(abs_key, meta, dtype)
Create a subjacobian.
- Parameters:
- abs_keytuple
The absolute key for the subjacobian.
- metadict
Metadata for the subjacobian.
- dtypedtype
The dtype of the subjacobian.
- Returns:
- Subjac
The created subjacobian,.
- get_dr_di_matrix()[source]
Get the dr/di matrix.
- Returns:
- Matrix
The dr/di matrix.
- get_dr_do_matrix()[source]
Get the dr/do matrix.
- Returns:
- Matrix
The dr/do matrix.
- get_metadata(key)
Get metadata for the given key.
- Parameters:
- key(str, str)
Promoted or relative name pair of sub-Jacobian.
- Returns:
- dict
Metadata dict for the given key.
- items()
Yield name pair and value of sub-Jacobian.
- Yields:
- str
- keys()
Yield next name pair of sub-Jacobian.
- Yields:
- str
- set_col(system, icol, column)
Set a column of the jacobian.
The column is assumed to be the same size as a column of the jacobian.
This also assumes that the column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- icolint
Column index.
- columnndarray
Column value.
- set_csc_jac(system, jac)
Assign a CSC jacobian to this jacobian.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jaccsc_matrix
CSC jacobian.
- set_dense_jac(system, jac)
Assign a dense jacobian to this jacobian.
This assumes that any column does not attempt to set any nonzero values that are outside of specified sparsity patterns for any of the subjacs.
- Parameters:
- systemSystem
The system that owns this jacobian.
- jacndarray
Dense jacobian.
- todense()[source]
Return a dense version of the jacobian.
- Returns:
- ndarray
Dense version of the jacobian.