def test_isomorphic_compare_nodes_identical(self): dag_a = retworkx.PyDAG() node_a = dag_a.add_node("a_1") dag_a.add_child(node_a, "a_2", "a_1") dag_a.add_child(node_a, "a_3", "a_2") dag_b = copy.deepcopy(dag_a) self.assertTrue( retworkx.is_isomorphic_node_match(dag_a, dag_b, lambda x, y: x == y))
def test_isomorphic_compare_nodes_mismatch_node_data(self): dag_a = retworkx.PyDAG() dag_b = retworkx.PyDAG() node_a = dag_a.add_node('a_1') dag_a.add_child(node_a, 'a_2', 'a_1') dag_a.add_child(node_a, 'a_3', 'a_2') node_b = dag_b.add_node('b_1') dag_b.add_child(node_b, 'b_2', 'b_1') dag_b.add_child(node_b, 'b_3', 'b_2') self.assertFalse( retworkx.is_isomorphic_node_match(dag_a, dag_b, lambda x, y: x == y))
def test_isomorphic_compare_nodes_identical(self): dag_a = retworkx.PyDAG() dag_b = retworkx.PyDAG() node_a = dag_a.add_node('a_1') dag_a.add_child(node_a, 'a_2', 'a_1') dag_a.add_child(node_a, 'a_3', 'a_2') node_b = dag_b.add_node('a_1') dag_b.add_child(node_b, 'a_2', 'a_1') dag_b.add_child(node_b, 'a_3', 'a_2') self.assertTrue( retworkx.is_isomorphic_node_match(dag_a, dag_b, lambda x, y: x == y))
def test_isomorphic_compare_nodes_with_removals_deepcopy(self): dag_a = retworkx.PyDAG() dag_b = retworkx.PyDAG() qr_0_in = dag_a.add_node('qr[0]') qr_1_in = dag_a.add_node('qr[1]') cr_0_in = dag_a.add_node('cr[0]') qr_0_out = dag_a.add_node('qr[0]') qr_1_out = dag_a.add_node('qr[1]') cr_0_out = dag_a.add_node('qr[0]') cu1 = dag_a.add_child(qr_0_in, 'cu1', 'qr[0]') dag_a.add_edge(qr_1_in, cu1, 'qr[1]') measure_0 = dag_a.add_child(cr_0_in, 'measure', 'cr[0]') dag_a.add_edge(cu1, measure_0, 'qr[0]') measure_1 = dag_a.add_child(cu1, 'measure', 'qr[1]') dag_a.add_edge(measure_0, measure_1, 'cr[0]') dag_a.add_edge(measure_1, qr_1_out, 'qr[1]') dag_a.add_edge(measure_1, cr_0_out, 'cr[0]') dag_a.add_edge(measure_0, qr_0_out, 'qr[0]') dag_a.remove_node(cu1) dag_a.add_edge(qr_0_in, measure_0, 'qr[0]') dag_a.add_edge(qr_1_in, measure_1, 'qr[1]') qr_0_in = dag_b.add_node('qr[0]') qr_1_in = dag_b.add_node('qr[1]') cr_0_in = dag_b.add_node('cr[0]') qr_0_out = dag_b.add_node('qr[0]') qr_1_out = dag_b.add_node('qr[1]') cr_0_out = dag_b.add_node('qr[0]') measure_0 = dag_b.add_child(cr_0_in, 'measure', 'cr[0]') dag_b.add_edge(qr_0_in, measure_0, 'qr[0]') measure_1 = dag_b.add_child(qr_1_in, 'measure', 'qr[1]') dag_b.add_edge(measure_1, qr_1_out, 'qr[1]') dag_b.add_edge(measure_1, cr_0_out, 'cr[0]') dag_b.add_edge(measure_0, measure_1, 'cr[0]') dag_b.add_edge(measure_0, qr_0_out, 'qr[0]') self.assertTrue( retworkx.is_isomorphic_node_match(copy.deepcopy(dag_a), copy.deepcopy(dag_b), lambda x, y: x == y))
def __eq__(self, other): # TODO this works but is a horrible way to do this slf = copy.deepcopy(self._multi_graph) oth = copy.deepcopy(other._multi_graph) return rx.is_isomorphic_node_match(slf, oth, DAGNode.semantic_eq)