openmdao/core/group.py
def _setup_jacobians(self, recurse=True):
        """
        Set and populate jacobians down through the system tree.

        In <Group>, we only need to prepare for Group finite difference. However, to be efficient,
        we need to find the minimum set of inputs and outputs to approximate.

        Parameters
        ----------
        recurse : bool
            If True, setup jacobians in all descendants.
        """
        if not self._use_derivatives:
            return

        # Group finite difference or complex step.
        # TODO: Does this work under or over an AssembledJacobian (and does that make sense)
        if self._owns_approx_jac:
            self._jacobian = DictionaryJacobian(system=self)

            method = list(self._approx_schemes.keys())[0]
            approx = self._approx_schemes[method]
            pro2abs = self._var_allprocs_prom2abs_list
            abs2meta = self._var_allprocs_abs2meta

            if self._owns_approx_of:
                of = self._owns_approx_of
            else:
                of = set(var[0] for var in pro2abs['output'].values())

            if self._owns_approx_wrt:
                candidate_wrt = self._owns_approx_wrt
            else:
                candidate_wrt = list(var[0] for var in pro2abs['input'].values())

            from openmdao.core.indepvarcomp import IndepVarComp
            wrt = set()
            ivc = set()
            for var in candidate_wrt:

                # Weed out inputs connected to anything inside our system unless the source is an
                # indepvarcomp.
                if var in self._conn_abs_in2out:
                    src = self._conn_abs_in2out[var]
                    compname = src.rsplit('.', 1)[0]
                    comp = self._get_subsystem(compname)
                    if isinstance(comp, IndepVarComp):
                        wrt.add(src)
                        ivc.add(src)
                else:
                    wrt.add(var)

            for key in product(of, wrt.union(of)):
                if key in self._subjacs_info:
                    meta = self._subjacs_info[key]
                else:
                    meta = SUBJAC_META_DEFAULTS.copy()
                    if key[0] == key[1]:
                        size = self._var_allprocs_abs2meta[key[0]]['size']
                        meta['rows'] = meta['cols'] = np.arange(size)
                        # All group approximations are treated as explicit components, so we
                        # have a -1 on the diagonal.
                        meta['value'] = np.full(size, -1.0)

                meta['method'] = method

                # A group under approximation needs all keys from below, so set dependent to
                # True.
                # TODO: Maybe just need a subset of keys (those that go to the boundaries.)
                meta['dependent'] = True

                meta.update(self._owns_approx_jac_meta)

                # Create approximations, but only for the ones we need.
                if meta['dependent']:

                    # Skip indepvarcomp res wrt other srcs
                    if key[0] in ivc:
                        continue

                    # Skip explicit res wrt outputs
                    if key[1] in of and key[1] not in ivc:

                        # Support for specifying a desvar as an obj/con.
                        if key[1] not in wrt or key[0] == key[1]:
                            continue

                    approx.add_approximation(key, meta)

                if meta['value'] is None:
                    shape = (abs2meta[key[0]]['size'], abs2meta[key[1]]['size'])
                    meta['shape'] = shape
                    meta['value'] = np.zeros(shape)

                self._subjacs_info[key] = meta

        super(Group, self)._setup_jacobians(recurse=recurse)

        Set and populate jacobians down through the system tree.

        In <Group>, we only need to prepare for Group finite difference. However, to be efficient,
        we need to find the minimum set of inputs and outputs to approximate.

        Parameters
        ----------
        recurse : bool
            If True, setup jacobians in all descendants.
        
Set and populate jacobians down through the system tree.
In , we only need to prepare for Group finite difference. However, to be efficient,
we need to find the minimum set of inputs and outputs to approximate.

Parameters

recurse : bool
If True, setup jacobians in all descendants.
Set and populate jacobians down through the system tree . In we only need to prepare for Group finite difference . However to be efficient we need to find the minimum set of inputs and outputs to approximate . Parameters recurse : bool If True setup jacobians in all descendants .
def _setup_jacobians(self, recurse=True):
        if not self._use_derivatives:
            return
        if self._owns_approx_jac:
            self._jacobian = DictionaryJacobian(system=self)
            method = list(self._approx_schemes.keys())[0]
            approx = self._approx_schemes[method]
            pro2abs = self._var_allprocs_prom2abs_list
            abs2meta = self._var_allprocs_abs2meta
            if self._owns_approx_of:
                of = self._owns_approx_of
            else:
                of = set(var[0] for var in pro2abs['output'].values())
            if self._owns_approx_wrt:
                candidate_wrt = self._owns_approx_wrt
            else:
                candidate_wrt = list(var[0] for var in pro2abs['input'].values())
            from openmdao.core.indepvarcomp import IndepVarComp
            wrt = set()
            ivc = set()
            for var in candidate_wrt:
                if var in self._conn_abs_in2out:
                    src = self._conn_abs_in2out[var]
                    compname = src.rsplit('.', 1)[0]
                    comp = self._get_subsystem(compname)
                    if isinstance(comp, IndepVarComp):
                        wrt.add(src)
                        ivc.add(src)
                else:
                    wrt.add(var)
            for key in product(of, wrt.union(of)):
                if key in self._subjacs_info:
                    meta = self._subjacs_info[key]
                else:
                    meta = SUBJAC_META_DEFAULTS.copy()
                    if key[0] == key[1]:
                        size = self._var_allprocs_abs2meta[key[0]]['size']
                        meta['rows'] = meta['cols'] = np.arange(size)
                        meta['value'] = np.full(size, -1.0)
                meta['method'] = method
                meta['dependent'] = True
                meta.update(self._owns_approx_jac_meta)
                if meta['dependent']:
                    if key[0] in ivc:
                        continue
                    if key[1] in of and key[1] not in ivc:
                        if key[1] not in wrt or key[0] == key[1]:
                            continue
                    approx.add_approximation(key, meta)
                if meta['value'] is None:
                    shape = (abs2meta[key[0]]['size'], abs2meta[key[1]]['size'])
                    meta['shape'] = shape
                    meta['value'] = np.zeros(shape)
                self._subjacs_info[key] = meta
        super(Group, self)._setup_jacobians(recurse=recurse)
def _setup_jacobians ( self , recurse = True ) : if not self . _use_derivatives : return if self . _owns_approx_jac : self . _jacobian = DictionaryJacobian ( system = self ) method = list ( self . _approx_schemes . keys ( ) ) [ 0 ] approx = self . _approx_schemes [ method ] pro2abs = self . _var_allprocs_prom2abs_list abs2meta = self . _var_allprocs_abs2meta if self . _owns_approx_of : of = self . _owns_approx_of else : of = set ( var [ 0 ] for var in pro2abs [ 'output' ] . values ( ) ) if self . _owns_approx_wrt : candidate_wrt = self . _owns_approx_wrt else : candidate_wrt = list ( var [ 0 ] for var in pro2abs [ 'input' ] . values ( ) ) from openmdao . core . indepvarcomp import IndepVarComp wrt = set ( ) ivc = set ( ) for var in candidate_wrt : if var in self . _conn_abs_in2out : src = self . _conn_abs_in2out [ var ] compname = src . rsplit ( '.' , 1 ) [ 0 ] comp = self . _get_subsystem ( compname ) if isinstance ( comp , IndepVarComp ) : wrt . add ( src ) ivc . add ( src ) else : wrt . add ( var ) for key in product ( of , wrt . union ( of ) ) : if key in self . _subjacs_info : meta = self . _subjacs_info [ key ] else : meta = SUBJAC_META_DEFAULTS . copy ( ) if key [ 0 ] == key [ 1 ] : size = self . _var_allprocs_abs2meta [ key [ 0 ] ] [ 'size' ] meta [ 'rows' ] = meta [ 'cols' ] = np . arange ( size ) meta [ 'value' ] = np . full ( size , - 1.0 ) meta [ 'method' ] = method meta [ 'dependent' ] = True meta . update ( self . _owns_approx_jac_meta ) if meta [ 'dependent' ] : if key [ 0 ] in ivc : continue if key [ 1 ] in of and key [ 1 ] not in ivc : if key [ 1 ] not in wrt or key [ 0 ] == key [ 1 ] : continue approx . add_approximation ( key , meta ) if meta [ 'value' ] is None : shape = ( abs2meta [ key [ 0 ] ] [ 'size' ] , abs2meta [ key [ 1 ] ] [ 'size' ] ) meta [ 'shape' ] = shape meta [ 'value' ] = np . zeros ( shape ) self . _subjacs_info [ key ] = meta super ( Group , self ) . _setup_jacobians ( recurse = recurse )
Set and populate jacobians down through the system tree.
Set and populate jacobians down through the system tree .
"""
        Set and populate jacobians down through the system tree.

        In <Group>, we only need to prepare for Group finite difference. However, to be efficient,
        we need to find the minimum set of inputs and outputs to approximate.

        Parameters
        ----------
        recurse : bool
            If True, setup jacobians in all descendants.
        """ # Group finite difference or complex step. # TODO: Does this work under or over an AssembledJacobian (and does that make sense) # Weed out inputs connected to anything inside our system unless the source is an # indepvarcomp. # All group approximations are treated as explicit components, so we # have a -1 on the diagonal. # A group under approximation needs all keys from below, so set dependent to # True. # TODO: Maybe just need a subset of keys (those that go to the boundaries.) # Create approximations, but only for the ones we need. # Skip indepvarcomp res wrt other srcs # Skip explicit res wrt outputs # Support for specifying a desvar as an obj/con.
self
recurse