|
57 | 57 | RYYGate,
|
58 | 58 | RZZGate,
|
59 | 59 | RXXGate,
|
| 60 | + PauliEvolutionGate, |
60 | 61 | )
|
| 62 | +from qiskit.quantum_info import SparsePauliOp |
61 | 63 | from qiskit.circuit import Measure
|
62 | 64 | from qiskit.circuit.controlflow import IfElseOp
|
63 | 65 | from qiskit.circuit import Parameter, Gate
|
@@ -1050,6 +1052,55 @@ def test_qsd(self, opt):
|
1050 | 1052 | qc_transpiled = transpile(qc, target=target, optimization_level=opt)
|
1051 | 1053 | self.assertTrue(np.allclose(mat, Operator(qc_transpiled).data))
|
1052 | 1054 |
|
| 1055 | + def test_3q_with_measure(self): |
| 1056 | + """Test 3-qubit synthesis with measurements.""" |
| 1057 | + backend = FakeBackend5QV2() |
| 1058 | + |
| 1059 | + qc = QuantumCircuit(3, 1) |
| 1060 | + qc.unitary(np.eye(2**3), range(3)) |
| 1061 | + qc.measure(0, 0) |
| 1062 | + |
| 1063 | + qc_transpiled = transpile(qc, backend) |
| 1064 | + self.assertTrue(qc_transpiled.size, 1) |
| 1065 | + self.assertTrue(qc_transpiled.count_ops().get("measure", 0), 1) |
| 1066 | + |
| 1067 | + def test_3q_series(self): |
| 1068 | + """Test a series of 3-qubit blocks.""" |
| 1069 | + backend = GenericBackendV2(5, basis_gates=["u", "cx"]) |
| 1070 | + |
| 1071 | + x = QuantumCircuit(3) |
| 1072 | + x.x(2) |
| 1073 | + x_mat = Operator(x) |
| 1074 | + |
| 1075 | + qc = QuantumCircuit(3) |
| 1076 | + qc.unitary(x_mat, range(3)) |
| 1077 | + qc.unitary(np.eye(2**3), range(3)) |
| 1078 | + |
| 1079 | + tqc = transpile(qc, backend, optimization_level=0, initial_layout=[0, 1, 2]) |
| 1080 | + |
| 1081 | + expected = np.kron(np.eye(2**2), x_mat) |
| 1082 | + self.assertEqual(Operator(tqc), Operator(expected)) |
| 1083 | + |
| 1084 | + def test_3q_measure_all(self): |
| 1085 | + """Regression test of #13586.""" |
| 1086 | + hamiltonian = SparsePauliOp.from_list( |
| 1087 | + [("IXX", 1), ("IYY", 1), ("IZZ", 1), ("XXI", 1), ("YYI", 1), ("ZZI", 1)] |
| 1088 | + ) |
| 1089 | + |
| 1090 | + qc = QuantumCircuit(3) |
| 1091 | + qc.x([1, 2]) |
| 1092 | + op = PauliEvolutionGate(hamiltonian, time=1) |
| 1093 | + qc.append(op.power(8), [0, 1, 2]) |
| 1094 | + qc.measure_all() |
| 1095 | + |
| 1096 | + backend = GenericBackendV2(5, basis_gates=["u", "cx"]) |
| 1097 | + tqc = transpile(qc, backend) |
| 1098 | + |
| 1099 | + ops = tqc.count_ops() |
| 1100 | + self.assertIn("u", ops) |
| 1101 | + self.assertIn("cx", ops) |
| 1102 | + self.assertIn("measure", ops) |
| 1103 | + |
1053 | 1104 |
|
1054 | 1105 | if __name__ == "__main__":
|
1055 | 1106 | unittest.main()
|
0 commit comments