示例#1
0
 def test_ancestors_no_descendants(self):
     dag = retworkx.PyDAG()
     node_a = dag.add_node('a')
     node_b = dag.add_child(node_a, 'b', {'a': 1})
     dag.add_child(node_b, 'c', {'b': 1})
     res = retworkx.ancestors(dag, node_b)
     self.assertEqual([node_a], res)
示例#2
0
 def test_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', {'a': 2})
     res = retworkx.ancestors(dag, node_c)
     self.assertEqual([node_a, node_b], res)
示例#3
0
 def test_ancestors_no_descendants(self):
     dag = retworkx.PyDAG()
     node_a = dag.add_node("a")
     node_b = dag.add_child(node_a, "b", {"a": 1})
     dag.add_child(node_b, "c", {"b": 1})
     res = retworkx.ancestors(dag, node_b)
     self.assertEqual({node_a}, res)
示例#4
0
 def test_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", {"a": 2})
     res = retworkx.ancestors(dag, node_c)
     self.assertEqual({node_a, node_b}, res)
示例#5
0
    def ancestors(self, ops):
        """Ancestors of a given set of operators.

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

        Returns:
            set[Operator]: ancestors of the given operators
        """
        anc = set(
            self._graph.get_node_data(n) for n in set().union(
                # rx.ancestors() returns node indexes instead of node-values
                *(rx.ancestors(self._graph,
                               self._graph.nodes().index(o)) for o in ops)))
        return anc - set(ops)
示例#6
0
 def test_no_ancestors(self):
     dag = retworkx.PyDAG()
     node_a = dag.add_node('a')
     dag.add_child(node_a, 'b', {'a': 1})
     res = retworkx.ancestors(dag, node_a)
     self.assertEqual([], res)
示例#7
0
 def test_no_ancestors(self):
     dag = retworkx.PyDAG()
     node_a = dag.add_node("a")
     dag.add_child(node_a, "b", {"a": 1})
     res = retworkx.ancestors(dag, node_a)
     self.assertEqual(set(), res)
示例#8
0
 def time_ancestors(self):
     retworkx.ancestors(self.graph, 10240)