def test_circuit_depth_snap3(self):
     """Test circuit depth for snapshots #3."""
     q = QuantumRegister(4, "q")
     c = ClassicalRegister(4, "c")
     circ = QuantumCircuit(q, c)
     circ.h(0)
     circ.cx(0, 1)
     circ.append(Snapshot("snap0", num_qubits=4), [0, 1, 2, 3])
     circ.append(Snapshot("snap1", num_qubits=4), [0, 1, 2, 3])
     circ.h(2)
     circ.cx(2, 3)
     self.assertEqual(circ.depth(), 4)
Пример #2
0
 def test_circuit_depth_snap2(self):
     """Test circuit depth for snapshots #2.
     """
     q = QuantumRegister(4, 'q')
     c = ClassicalRegister(4, 'c')
     circ = QuantumCircuit(q, c)
     circ.h(0)
     circ.append(Snapshot('snap0', num_qubits=4), [0, 1, 2, 3])
     circ.cx(0, 1)
     circ.append(Snapshot('snap1', num_qubits=4), [0, 1, 2, 3])
     circ.h(2)
     circ.append(Snapshot('snap2', num_qubits=4), [0, 1, 2, 3])
     circ.cx(2, 3)
     self.assertEqual(circ.depth(), 4)
 def test_unroll_snapshot(self):
     """test unroll snapshot"""
     num_qubits = self.circuit.num_qubits
     instr = Snapshot("0", num_qubits=num_qubits)
     self.circuit.append(instr, range(num_qubits))
     self.ref_circuit.append(instr, range(num_qubits))
     self.compare_dags()
Пример #4
0
    def test_circuit_size_ignores_barriers_snapshots(self):
        """Circuit.size should not count barriers or snapshots."""
        q = QuantumRegister(4, 'q')
        c = ClassicalRegister(4, 'c')
        qc = QuantumCircuit(q, c)

        qc.h(q[0])
        qc.cx(q[0], q[1])
        self.assertEqual(qc.size(), 2)
        qc.barrier(q)
        self.assertEqual(qc.size(), 2)
        qc.append(Snapshot('snapshot_label', num_qubits=4), [0, 1, 2, 3])
        self.assertEqual(qc.size(), 2)
    def test_circuit_depth_snap3(self):
        """Test circuit depth for snapshots #3."""

        #      ┌───┐      ░  ░
        # q_0: ┤ H ├──■───░──░───────────
        #      └───┘┌─┴─┐ ░  ░
        # q_1: ─────┤ X ├─░──░───────────
        #           └───┘ ░  ░ ┌───┐
        # q_2: ───────────░──░─┤ H ├──■──
        #                 ░  ░ └───┘┌─┴─┐
        # q_3: ───────────░──░──────┤ X ├
        #                 ░  ░      └───┘
        q = QuantumRegister(4, "q")
        c = ClassicalRegister(4, "c")
        circ = QuantumCircuit(q, c)
        circ.h(0)
        circ.cx(0, 1)
        circ.append(Snapshot("snap0", num_qubits=4), [0, 1, 2, 3])
        circ.append(Snapshot("snap1", num_qubits=4), [0, 1, 2, 3])
        circ.h(2)
        circ.cx(2, 3)
        self.assertEqual(circ.depth(), 4)