openmdao/core/group.py
def _setup_global_connections(self, recurse=True, conns=None):
        """
        Compute dict of all connections between this system's inputs and outputs.

        The connections come from 4 sources:
        1. Implicit connections owned by the current system
        2. Explicit connections declared by the current system
        3. Explicit connections declared by parent systems
        4. Implicit / explicit from subsystems

        Parameters
        ----------
        recurse : bool
            Whether to call this method in subsystems.
        conns : dict
            Dictionary of connections passed down from parent group.
        """
        global_abs_in2out = self._conn_global_abs_in2out

        allprocs_prom2abs_list_in = self._var_allprocs_prom2abs_list['input']
        allprocs_prom2abs_list_out = self._var_allprocs_prom2abs_list['output']
        abs2meta = self._var_abs2meta
        pathname = self.pathname

        abs_in2out = {}

        if pathname == '':
            path_len = 0
            nparts = 0
        else:
            path_len = len(pathname) + 1
            nparts = len(pathname.split('.'))

        new_conns = defaultdict(dict)

        if conns is not None:
            for abs_in, abs_out in iteritems(conns):
                inparts = abs_in.split('.')
                outparts = abs_out.split('.')

                if inparts[:nparts] == outparts[:nparts]:
                    global_abs_in2out[abs_in] = abs_out

                    # if connection is contained in a subgroup, add to conns
                    # to pass down to subsystems.
                    if inparts[:nparts + 1] == outparts[:nparts + 1]:
                        new_conns[inparts[nparts]][abs_in] = abs_out

        # Add implicit connections (only ones owned by this group)
        for prom_name in allprocs_prom2abs_list_out:
            if prom_name in allprocs_prom2abs_list_in:
                abs_out = allprocs_prom2abs_list_out[prom_name][0]
                out_subsys = abs_out[path_len:].split('.', 1)[0]
                for abs_in in allprocs_prom2abs_list_in[prom_name]:
                    in_subsys = abs_in[path_len:].split('.', 1)[0]
                    if out_subsys != in_subsys:
                        abs_in2out[abs_in] = abs_out

        # Add explicit connections (only ones declared by this group)
        for prom_in, (prom_out, src_indices, flat_src_indices) in \
                iteritems(self._manual_connections):

            # throw an exception if either output or input doesn't exist
            # (not traceable to a connect statement, so provide context)
            if (prom_out not in allprocs_prom2abs_list_out and
                    prom_out not in self._var_allprocs_discrete['output']):
                raise NameError(
                    "Output '%s' does not exist for connection in '%s' from '%s' to '%s'." %
                    (prom_out, self.pathname, prom_out, prom_in))

            if (prom_in not in allprocs_prom2abs_list_in and
                    prom_in not in self._var_allprocs_discrete['input']):
                raise NameError(
                    "Input '%s' does not exist for connection in '%s' from '%s' to '%s'." %
                    (prom_in, self.pathname, prom_out, prom_in))

            # Throw an exception if output and input are in the same system
            # (not traceable to a connect statement, so provide context)
            # and check if src_indices is defined in both connect and add_input.
            abs_out = allprocs_prom2abs_list_out[prom_out][0]
            outparts = abs_out.split('.')
            out_subsys = outparts[:-1]

            for abs_in in allprocs_prom2abs_list_in[prom_in]:
                inparts = abs_in.split('.')
                in_subsys = inparts[:-1]
                if out_subsys == in_subsys:
                    raise RuntimeError("Output and input are in the same System " +
                                       "for connection in '%s' from '%s' to '%s'." %
                                       (self.pathname, prom_out, prom_in))

                if src_indices is not None and abs_in in abs2meta:
                    meta = abs2meta[abs_in]
                    if meta['src_indices'] is not None:
                        raise RuntimeError("%s: src_indices has been defined "
                                           "in both connect('%s', '%s') "
                                           "and add_input('%s', ...)." %
                                           (self.pathname, prom_out,
                                            prom_in, prom_in))
                    meta['src_indices'] = np.atleast_1d(src_indices)
                    meta['flat_src_indices'] = flat_src_indices

                if abs_in in abs_in2out:
                    raise RuntimeError("Input '%s' cannot be connected to '%s' because it's already"
                                       " connected to '%s'" % (abs_in, abs_out, abs_in2out[abs_in]))

                abs_in2out[abs_in] = abs_out

                # if connection is contained in a subgroup, add to conns to pass down to subsystems.
                if inparts[:nparts + 1] == outparts[:nparts + 1]:
                    new_conns[inparts[nparts]][abs_in] = abs_out

        # Recursion
        if recurse:
            for subsys in self._subgroups_myproc:
                if subsys.name in new_conns:
                    subsys._setup_global_connections(recurse=recurse,
                                                     conns=new_conns[subsys.name])
                else:
                    subsys._setup_global_connections(recurse=recurse)

        # Compute global_abs_in2out by first adding this group's contributions,
        # then adding contributions from systems above/below, then allgathering.
        conn_list = list(iteritems(global_abs_in2out))
        conn_list.extend(iteritems(abs_in2out))
        global_abs_in2out.update(abs_in2out)

        for subsys in self._subgroups_myproc:
            global_abs_in2out.update(subsys._conn_global_abs_in2out)
            conn_list.extend(iteritems(subsys._conn_global_abs_in2out))

        if len(conn_list) > len(global_abs_in2out):
            dupes = [n for n, val in iteritems(Counter(tgt for tgt, src in conn_list)) if val > 1]
            dup_info = defaultdict(set)
            for tgt, src in conn_list:
                for dup in dupes:
                    if tgt == dup:
                        dup_info[tgt].add(src)
            dup_info = [(n, srcs) for n, srcs in iteritems(dup_info) if len(srcs) > 1]
            if dup_info:
                msg = ["%s from %s" % (tgt, sorted(srcs)) for tgt, srcs in dup_info]
                raise RuntimeError("The following inputs have multiple connections: %s" %
                                   ", ".join(msg))

        # If running in parallel, allgather
        if self.comm.size > 1:
            if self._subsystems_myproc and self._subsystems_myproc[0].comm.rank == 0:
                raw = global_abs_in2out
            else:
                raw = {}
            gathered = self.comm.allgather(raw)

            for myproc_global_abs_in2out in gathered:
                global_abs_in2out.update(myproc_global_abs_in2out)

        Compute dict of all connections between this system's inputs and outputs.

        The connections come from 4 sources:
        1. Implicit connections owned by the current system
        2. Explicit connections declared by the current system
        3. Explicit connections declared by parent systems
        4. Implicit / explicit from subsystems

        Parameters
        ----------
        recurse : bool
            Whether to call this method in subsystems.
        conns : dict
            Dictionary of connections passed down from parent group.
        
Compute dict of all connections between this system's inputs and outputs.
The connections come from 4 sources:
1. Implicit connections owned by the current system
2. Explicit connections declared by the current system
3. Explicit connections declared by parent systems
4. Implicit / explicit from subsystems

Parameters

recurse : bool
Whether to call this method in subsystems.
conns : dict
Dictionary of connections passed down from parent group.
Compute dict of all connections between this system ' s inputs and outputs . The connections come from 4 sources : 1 . Implicit connections owned by the current system 2 . Explicit connections declared by the current system 3 . Explicit connections declared by parent systems 4 . Implicit / explicit from subsystems Parameters recurse : bool Whether to call this method in subsystems . conns : dict Dictionary of connections passed down from parent group .
def _setup_global_connections(self, recurse=True, conns=None):
        global_abs_in2out = self._conn_global_abs_in2out
        allprocs_prom2abs_list_in = self._var_allprocs_prom2abs_list['input']
        allprocs_prom2abs_list_out = self._var_allprocs_prom2abs_list['output']
        abs2meta = self._var_abs2meta
        pathname = self.pathname
        abs_in2out = {}
        if pathname == '':
            path_len = 0
            nparts = 0
        else:
            path_len = len(pathname) + 1
            nparts = len(pathname.split('.'))
        new_conns = defaultdict(dict)
        if conns is not None:
            for abs_in, abs_out in iteritems(conns):
                inparts = abs_in.split('.')
                outparts = abs_out.split('.')
                if inparts[:nparts] == outparts[:nparts]:
                    global_abs_in2out[abs_in] = abs_out
                    if inparts[:nparts + 1] == outparts[:nparts + 1]:
                        new_conns[inparts[nparts]][abs_in] = abs_out
        for prom_name in allprocs_prom2abs_list_out:
            if prom_name in allprocs_prom2abs_list_in:
                abs_out = allprocs_prom2abs_list_out[prom_name][0]
                out_subsys = abs_out[path_len:].split('.', 1)[0]
                for abs_in in allprocs_prom2abs_list_in[prom_name]:
                    in_subsys = abs_in[path_len:].split('.', 1)[0]
                    if out_subsys != in_subsys:
                        abs_in2out[abs_in] = abs_out
        for prom_in, (prom_out, src_indices, flat_src_indices) in \
                iteritems(self._manual_connections):
            if (prom_out not in allprocs_prom2abs_list_out and
                    prom_out not in self._var_allprocs_discrete['output']):
                raise NameError(
                    "Output '%s' does not exist for connection in '%s' from '%s' to '%s'." %
                    (prom_out, self.pathname, prom_out, prom_in))
            if (prom_in not in allprocs_prom2abs_list_in and
                    prom_in not in self._var_allprocs_discrete['input']):
                raise NameError(
                    "Input '%s' does not exist for connection in '%s' from '%s' to '%s'." %
                    (prom_in, self.pathname, prom_out, prom_in))
            abs_out = allprocs_prom2abs_list_out[prom_out][0]
            outparts = abs_out.split('.')
            out_subsys = outparts[:-1]
            for abs_in in allprocs_prom2abs_list_in[prom_in]:
                inparts = abs_in.split('.')
                in_subsys = inparts[:-1]
                if out_subsys == in_subsys:
                    raise RuntimeError("Output and input are in the same System " +
                                       "for connection in '%s' from '%s' to '%s'." %
                                       (self.pathname, prom_out, prom_in))
                if src_indices is not None and abs_in in abs2meta:
                    meta = abs2meta[abs_in]
                    if meta['src_indices'] is not None:
                        raise RuntimeError("%s: src_indices has been defined "
                                           "in both connect('%s', '%s') "
                                           "and add_input('%s', ...)." %
                                           (self.pathname, prom_out,
                                            prom_in, prom_in))
                    meta['src_indices'] = np.atleast_1d(src_indices)
                    meta['flat_src_indices'] = flat_src_indices
                if abs_in in abs_in2out:
                    raise RuntimeError("Input '%s' cannot be connected to '%s' because it's already"
                                       " connected to '%s'" % (abs_in, abs_out, abs_in2out[abs_in]))
                abs_in2out[abs_in] = abs_out
                 to pass down to subsystems.
                if inparts[:nparts + 1] == outparts[:nparts + 1]:
                    new_conns[inparts[nparts]][abs_in] = abs_out
        if recurse:
            for subsys in self._subgroups_myproc:
                if subsys.name in new_conns:
                    subsys._setup_global_connections(recurse=recurse,
                                                     conns=new_conns[subsys.name])
                else:
                    subsys._setup_global_connections(recurse=recurse)
        conn_list = list(iteritems(global_abs_in2out))
        conn_list.extend(iteritems(abs_in2out))
        global_abs_in2out.update(abs_in2out)
        for subsys in self._subgroups_myproc:
            global_abs_in2out.update(subsys._conn_global_abs_in2out)
            conn_list.extend(iteritems(subsys._conn_global_abs_in2out))
        if len(conn_list) > len(global_abs_in2out):
            dupes = [n for n, val in iteritems(Counter(tgt for tgt, src in conn_list)) if val > 1]
            dup_info = defaultdict(set)
            for tgt, src in conn_list:
                for dup in dupes:
                    if tgt == dup:
                        dup_info[tgt].add(src)
            dup_info = [(n, srcs) for n, srcs in iteritems(dup_info) if len(srcs) > 1]
            if dup_info:
                msg = ["%s from %s" % (tgt, sorted(srcs)) for tgt, srcs in dup_info]
                raise RuntimeError("The following inputs have multiple connections: %s" %
                                   ", ".join(msg))
        if self.comm.size > 1:
            if self._subsystems_myproc and self._subsystems_myproc[0].comm.rank == 0:
                raw = global_abs_in2out
            else:
                raw = {}
            gathered = self.comm.allgather(raw)
            for myproc_global_abs_in2out in gathered:
                global_abs_in2out.update(myproc_global_abs_in2out)
def _setup_global_connections ( self , recurse = True , conns = None ) : global_abs_in2out = self . _conn_global_abs_in2out allprocs_prom2abs_list_in = self . _var_allprocs_prom2abs_list [ 'input' ] allprocs_prom2abs_list_out = self . _var_allprocs_prom2abs_list [ 'output' ] abs2meta = self . _var_abs2meta pathname = self . pathname abs_in2out = { } if pathname == '' : path_len = 0 nparts = 0 else : path_len = len ( pathname ) + 1 nparts = len ( pathname . split ( '.' ) ) new_conns = defaultdict ( dict ) if conns is not None : for abs_in , abs_out in iteritems ( conns ) : inparts = abs_in . split ( '.' ) outparts = abs_out . split ( '.' ) if inparts [ : nparts ] == outparts [ : nparts ] : global_abs_in2out [ abs_in ] = abs_out if inparts [ : nparts + 1 ] == outparts [ : nparts + 1 ] : new_conns [ inparts [ nparts ] ] [ abs_in ] = abs_out for prom_name in allprocs_prom2abs_list_out : if prom_name in allprocs_prom2abs_list_in : abs_out = allprocs_prom2abs_list_out [ prom_name ] [ 0 ] out_subsys = abs_out [ path_len : ] . split ( '.' , 1 ) [ 0 ] for abs_in in allprocs_prom2abs_list_in [ prom_name ] : in_subsys = abs_in [ path_len : ] . split ( '.' , 1 ) [ 0 ] if out_subsys != in_subsys : abs_in2out [ abs_in ] = abs_out for prom_in , ( prom_out , src_indices , flat_src_indices ) in iteritems ( self . _manual_connections ) : if ( prom_out not in allprocs_prom2abs_list_out and prom_out not in self . _var_allprocs_discrete [ 'output' ] ) : raise NameError ( "Output '%s' does not exist for connection in '%s' from '%s' to '%s'." % ( prom_out , self . pathname , prom_out , prom_in ) ) if ( prom_in not in allprocs_prom2abs_list_in and prom_in not in self . _var_allprocs_discrete [ 'input' ] ) : raise NameError ( "Input '%s' does not exist for connection in '%s' from '%s' to '%s'." % ( prom_in , self . pathname , prom_out , prom_in ) ) abs_out = allprocs_prom2abs_list_out [ prom_out ] [ 0 ] outparts = abs_out . split ( '.' ) out_subsys = outparts [ : - 1 ] for abs_in in allprocs_prom2abs_list_in [ prom_in ] : inparts = abs_in . split ( '.' ) in_subsys = inparts [ : - 1 ] if out_subsys == in_subsys : raise RuntimeError ( "Output and input are in the same System " + "for connection in '%s' from '%s' to '%s'." % ( self . pathname , prom_out , prom_in ) ) if src_indices is not None and abs_in in abs2meta : meta = abs2meta [ abs_in ] if meta [ 'src_indices' ] is not None : raise RuntimeError ( "%s: src_indices has been defined " "in both connect('%s', '%s') " "and add_input('%s', ...)." % ( self . pathname , prom_out , prom_in , prom_in ) ) meta [ 'src_indices' ] = np . atleast_1d ( src_indices ) meta [ 'flat_src_indices' ] = flat_src_indices if abs_in in abs_in2out : raise RuntimeError ( "Input '%s' cannot be connected to '%s' because it's already" " connected to '%s'" % ( abs_in , abs_out , abs_in2out [ abs_in ] ) ) abs_in2out [ abs_in ] = abs_out if inparts [ : nparts + 1 ] == outparts [ : nparts + 1 ] : new_conns [ inparts [ nparts ] ] [ abs_in ] = abs_out if recurse : for subsys in self . _subgroups_myproc : if subsys . name in new_conns : subsys . _setup_global_connections ( recurse = recurse , conns = new_conns [ subsys . name ] ) else : subsys . _setup_global_connections ( recurse = recurse ) conn_list = list ( iteritems ( global_abs_in2out ) ) conn_list . extend ( iteritems ( abs_in2out ) ) global_abs_in2out . update ( abs_in2out ) for subsys in self . _subgroups_myproc : global_abs_in2out . update ( subsys . _conn_global_abs_in2out ) conn_list . extend ( iteritems ( subsys . _conn_global_abs_in2out ) ) if len ( conn_list ) > len ( global_abs_in2out ) : dupes = [ n for n , val in iteritems ( Counter ( tgt for tgt , src in conn_list ) ) if val > 1 ] dup_info = defaultdict ( set ) for tgt , src in conn_list : for dup in dupes : if tgt == dup : dup_info [ tgt ] . add ( src ) dup_info = [ ( n , srcs ) for n , srcs in iteritems ( dup_info ) if len ( srcs ) > 1 ] if dup_info : msg = [ "%s from %s" % ( tgt , sorted ( srcs ) ) for tgt , srcs in dup_info ] raise RuntimeError ( "The following inputs have multiple connections: %s" % ", " . join ( msg ) ) if self . comm . size > 1 : if self . _subsystems_myproc and self . _subsystems_myproc [ 0 ] . comm . rank == 0 : raw = global_abs_in2out else : raw = { } gathered = self . comm . allgather ( raw ) for myproc_global_abs_in2out in gathered : global_abs_in2out . update ( myproc_global_abs_in2out )
Compute dict of all connections between this system's inputs and outputs.
Compute dict of all connections between this system ' s inputs and outputs .
"""
        Compute dict of all connections between this system's inputs and outputs.

        The connections come from 4 sources:
        1. Implicit connections owned by the current system
        2. Explicit connections declared by the current system
        3. Explicit connections declared by parent systems
        4. Implicit / explicit from subsystems

        Parameters
        ----------
        recurse : bool
            Whether to call this method in subsystems.
        conns : dict
            Dictionary of connections passed down from parent group.
        """ # if connection is contained in a subgroup, add to conns # to pass down to subsystems. # Add implicit connections (only ones owned by this group) # Add explicit connections (only ones declared by this group) # throw an exception if either output or input doesn't exist # (not traceable to a connect statement, so provide context) # Throw an exception if output and input are in the same system # (not traceable to a connect statement, so provide context) # and check if src_indices is defined in both connect and add_input. # if connection is contained in a subgroup, add to conns to pass down to subsystems. # Recursion # Compute global_abs_in2out by first adding this group's contributions, # then adding contributions from systems above/below, then allgathering. # If running in parallel, allgather
self
recurse
conns