示例#1
0
 def test_descendants_no_ancestors(self):
     dag = retworkx.PyDAG()
     node_a = dag.add_node('a')
     node_b = dag.add_child(node_a, 'b', {'a': 1})
     node_c = dag.add_child(node_b, 'c', {'b': 1})
     res = retworkx.descendants(dag, node_b)
     self.assertEqual([node_c], res)
示例#2
0
 def test_descendants_no_ancestors(self):
     dag = retworkx.PyDAG()
     node_a = dag.add_node("a")
     node_b = dag.add_child(node_a, "b", {"a": 1})
     node_c = dag.add_child(node_b, "c", {"b": 1})
     res = retworkx.descendants(dag, node_b)
     self.assertEqual({node_c}, res)
 def test_descendants(self):
     dag = retworkx.PyDAG()
     node_a = dag.add_node('a')
     node_b = dag.add_child(node_a, 'b', {'a': 1})
     node_c = dag.add_child(node_b, 'c', {'a': 2})
     res = retworkx.descendants(dag, node_a)
     self.assertEqual({node_b, node_c}, res)
示例#4
0
    def descendants(self, ops):
        """Descendants of a given set of operators.

        Args:
            ops (Iterable[Operator]): set of operators in the circuit

        Returns:
            set[Operator]: descendants of the given operators
        """
        des = set(
            self._graph.get_node_data(n) for n in set().union(
                # rx.descendants() returns node indexes instead of node-values
                *(rx.descendants(self._graph,
                                 self._graph.nodes().index(o)) for o in ops)))
        return des - set(ops)
示例#5
0
 def test_no_descendants(self):
     dag = retworkx.PyDAG()
     node_a = dag.add_node('a')
     res = retworkx.descendants(dag, node_a)
     self.assertEqual([], res)
示例#6
0
 def time_descendants(self):
     retworkx.descendants(self.graph, 10240)