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)
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)
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)
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)
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)
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)
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)
def time_ancestors(self): retworkx.ancestors(self.graph, 10240)