Пример #1
0
    def test_dagcircuit_basic(self):
        dag = retworkx.PyDAG()
        qr_0_in = dag.add_node("qr[0]")
        qr_0_out = dag.add_node("qr[0]")
        qr_1_in = dag.add_node("qr[1]")
        qr_1_out = dag.add_node("qr[1]")
        cr_0_in = dag.add_node("cr[0]")
        cr_0_out = dag.add_node("cr[0]")
        cr_1_in = dag.add_node("cr[1]")
        cr_1_out = dag.add_node("cr[1]")
        input_nodes = [qr_0_in, qr_1_in, cr_0_in, cr_1_in]

        h_gate = dag.add_child(qr_0_in, "h", "qr[0]")
        cx_gate = dag.add_child(h_gate, "cx", "qr[0]")
        dag.add_edge(qr_1_in, cx_gate, "qr[1]")
        measure_qr_1 = dag.add_child(cx_gate, "measure", "qr[1]")
        dag.add_edge(cr_1_in, measure_qr_1, "cr[1]")
        x_gate = dag.add_child(measure_qr_1, "x", "qr[1]")
        dag.add_edge(measure_qr_1, x_gate, "cr[1]")
        dag.add_edge(cr_0_in, x_gate, "cr[0]")

        measure_qr_0 = dag.add_child(cx_gate, "measure", "qr[0]")
        dag.add_edge(measure_qr_0, qr_0_out, "qr[0]")
        dag.add_edge(measure_qr_0, cr_0_out, "cr[0]")
        dag.add_edge(x_gate, measure_qr_0, "cr[0]")

        measure_qr_1_out = dag.add_child(x_gate, "measure", "cr[1]")
        dag.add_edge(x_gate, measure_qr_1_out, "qr[1]")
        dag.add_edge(measure_qr_1_out, qr_1_out, "qr[1]")
        dag.add_edge(measure_qr_1_out, cr_1_out, "cr[1]")

        res = retworkx.layers(dag, input_nodes)
        expected = [
            ["qr[0]", "qr[1]", "cr[0]", "cr[1]"],
            ["h"],
            ["cx"],
            ["measure"],
            ["x"],
            ["measure", "measure"],
            ["cr[1]", "qr[1]", "cr[0]", "qr[0]"],
        ]
        self.assertEqual(expected, res)
Пример #2
0
 def multigraph_layers(self):
     """Yield layers of the multigraph."""
     first_layer = [x._node_id for x in self.input_map.values()]
     yield from rx.layers(self._multi_graph, first_layer)
Пример #3
0
 def test_first_layer_invalid_node(self):
     dag = retworkx.PyDAG()
     with self.assertRaises(retworkx.InvalidNode):
         retworkx.layers(dag, [42])
Пример #4
0
 def peakmem_layers(self, _):
     retworkx.layers(self.graph, [0])
Пример #5
0
 def time_layers(self, _):
     retworkx.layers(self.graph, [0])