def setup_reduced_graph(self, inputs=None, outputs=None, drvname=None):
        """Create the graph we need to do the breakdown of the model
        into Systems.
        """
        dgraph = self._depgraph.subgraph(self._depgraph.nodes_iter())

        # keep all states
        # FIXME: I think this should only keep states of comps that are directly relevant...
        keep = set([n for n,d in dgraph.nodes_iter(data=True)
                         if d.get('iotype')=='state'])
                         #if d.get('iotype') in ('state','residual')])

        if self.parent is not None:
            self._derivs_required = self.parent._derivs_required
        else:
            self._derivs_required = False

        # figure out the relevant subgraph based on given inputs and outputs
        if not (inputs is None and outputs is None):
            self._derivs_required = True

        dsrcs, ddests = self._top_driver.get_expr_var_depends(recurse=True)
        keep.add(self._top_driver.name)
        keep.update([c.name for c in self._top_driver.iteration_set()])

        # keep any connected boundary vars
        for u,v in dgraph.list_connections():
            if is_boundary_node(dgraph, u):
                keep.add(u)
            if is_boundary_node(dgraph, v):
                keep.add(v)

        if inputs is None:
            inputs = list(ddests)
        else:
            # fix any single tuples
            inputs = [fix_single_tuple(i) for i in inputs]

            # identify any broadcast inputs
            ins = []
            for inp in inputs:
                if isinstance(inp, basestring):
                    keep.add(inp)
                    ins.append(inp)
                else:
                    keep.update(inp)
                    ins.append(inp[0])
            inputs = ins

        if outputs is None:
            outputs = dsrcs

        dgraph = dgraph._explode_vartrees(self)

        skip = False
        # add any variables requested that don't exist in the graph
        for inp in inputs:
            if not hasattr(self, inp.split('.')[0].split('[')[0]):
                skip = True
                break
            if inp not in dgraph:
                base = base_var(dgraph, inp)
                for n in chain(dgraph.successors(base), dgraph.predecessors(base)):
                    if base_var(dgraph, n) != base:
                        keep.add(base)
                dgraph.add_connected_subvar(inp)

        for out in outputs:
            if not hasattr(self, out.split('.',1)[0].split('[')[0]):
                skip = True
                break
            if out not in dgraph:
                base = base_var(dgraph, out)
                for n in chain(dgraph.successors(base), dgraph.predecessors(base)):
                    if base_var(dgraph, n) != base:
                        keep.add(base)
                dgraph.add_connected_subvar(out)

        if not skip:
            dgraph = dgraph.relevant_subgraph(inputs, outputs, keep)

        dgraph._remove_vartrees(self)

        keep.update(inputs)
        keep.update(outputs)

        dgraph._fix_state_connections(self)

        dgraph._connect_subvars_to_comps()

        # collapse all connections into single nodes.
        collapsed_graph = dgraph.collapse_connections()
        collapsed_graph.fix_duplicate_dests()
        collapsed_graph._consolidate_srcs()
        collapsed_graph.vars2tuples(dgraph)

        self.name2collapsed = collapsed_graph.map_collapsed_nodes()

        # add VarSystems for boundary vars
        for node, data in collapsed_graph.nodes_iter(data=True):
            if 'boundary' in data and 0 > collapsed_graph.degree(node):
                if data.get('iotype') == 'in' and collapsed_graph.in_degree(node) == 0: # input boundary node
                    collapsed_graph.add_node(node[0].split('[',1)[0], comp='invar')
                    collapsed_graph.add_edge(node[0].split('[',1)[0], node)
                elif data.get('iotype') == 'out': # output bndry node
                    collapsed_graph.add_node(node[1][0].split('[',1)[0], comp='outvar')
                    collapsed_graph.add_edge(node, node[1][0].split('[',1)[0])

        # translate kept nodes to collapsed form
        coll_keep = set([self.name2collapsed.get(k,k) for k in keep])

        # remove all vars that don't connect components
        collapsed_graph.prune(coll_keep)

        collapsed_graph.fix_dangling_vars(self)

        if drvname:
            for node in collapsed_graph:
                if collapsed_graph.in_degree(node) > 1 and isinstance(node, tuple):
                    for pred in collapsed_graph.predecessors(node):
                        if pred != drvname:
                            collapsed_graph.remove_edge(pred, node)
                            if collapsed_graph.in_degree(node) == 1:
                                break

        self._reduced_graph = collapsed_graph

        for comp in self.get_comps():
            if has_interface(comp, IDriver) and comp.requires_derivs():
                self._derivs_required = True
            if has_interface(comp, IAssembly):
                comp.setup_reduced_graph(inputs=_get_scoped_inputs(comp, dgraph, inputs),
                                         outputs=_get_scoped_outputs(comp, dgraph, outputs))
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.main/src/openmdao/main/assembly.py/Assembly.setup_reduced_graph/swapped operands of `>`