|
26 | 26 | PhaseGate, |
27 | 27 | UnitaryGate, |
28 | 28 | PauliEvolutionGate, |
| 29 | + PauliProductRotationGate, |
29 | 30 | Initialize, |
30 | 31 | U2Gate, |
31 | 32 | CZGate, |
|
43 | 44 | ) |
44 | 45 | from qiskit.circuit.parameter import Parameter |
45 | 46 | from qiskit.transpiler.passes import CommutativeOptimization |
46 | | -from qiskit.quantum_info import Operator, SparsePauliOp, Clifford |
| 47 | +from qiskit.quantum_info import Operator, SparsePauliOp, Clifford, Pauli |
47 | 48 |
|
48 | 49 | from test import QiskitTestCase |
49 | 50 |
|
@@ -313,6 +314,48 @@ def test_not_merge_pauli_evolutions(self): |
313 | 314 |
|
314 | 315 | self.assertEqual(qct, qc) |
315 | 316 |
|
| 317 | + def test_merge_pauli_product_rotations(self): |
| 318 | + """Test that the pass merges PauliProductRotationGates.""" |
| 319 | + |
| 320 | + qc = QuantumCircuit(4) |
| 321 | + qc.append(PauliProductRotationGate(Pauli("XXII"), -1), [0, 1, 2, 3]) |
| 322 | + qc.append(PauliProductRotationGate(Pauli("ZZIY"), 1), [0, 1, 3, 2]) |
| 323 | + qc.append(PauliProductRotationGate(Pauli("ZZYI"), 1), [1, 0, 2, 3]) |
| 324 | + qc.append(PauliProductRotationGate(Pauli("YYXX"), 1), [0, 1, 2, 3]) |
| 325 | + qc.append(PauliProductRotationGate(Pauli("XXII"), 1), [0, 1, 2, 3]) |
| 326 | + |
| 327 | + # The two "XXII" rotations should cancel. |
| 328 | + # The two "ZZIY" rotations (after canonicalizing) should get combined. |
| 329 | + qct = CommutativeOptimization()(qc) |
| 330 | + |
| 331 | + expected = QuantumCircuit(4) |
| 332 | + expected.append(PauliProductRotationGate(Pauli("ZZIY"), 2), [0, 1, 2, 3]) |
| 333 | + expected.append(PauliProductRotationGate(Pauli("YYXX"), 1), [0, 1, 2, 3]) |
| 334 | + |
| 335 | + self.assertEqual(Operator(expected), Operator(qc)) |
| 336 | + self.assertEqual(qct, expected) |
| 337 | + |
| 338 | + def test_merge_parameterized_pauli_product_rotations(self): |
| 339 | + """Test that the pass merges parameterized PauliProductRotationGates.""" |
| 340 | + |
| 341 | + p = Parameter("p") |
| 342 | + q = Parameter("q") |
| 343 | + r = Parameter("r") |
| 344 | + |
| 345 | + qc = QuantumCircuit(4) |
| 346 | + qc.append(PauliProductRotationGate(Pauli("YYXX"), p), [0, 1, 2, 3]) |
| 347 | + qc.append(PauliProductRotationGate(Pauli("YYXX"), q), [0, 1, 2, 3]) |
| 348 | + qc.append(PauliProductRotationGate(Pauli("ZXXX"), r), [0, 1, 2, 3]) |
| 349 | + qc.append(PauliProductRotationGate(Pauli("YYXX"), -1), [0, 1, 2, 3]) |
| 350 | + |
| 351 | + qct = CommutativeOptimization()(qc) |
| 352 | + |
| 353 | + expected = QuantumCircuit(4) |
| 354 | + expected.append(PauliProductRotationGate(Pauli("ZXXX"), r), [0, 1, 2, 3]) |
| 355 | + expected.append(PauliProductRotationGate(Pauli("YYXX"), p + q - 1), [0, 1, 2, 3]) |
| 356 | + |
| 357 | + self.assertEqual(qct, expected) |
| 358 | + |
316 | 359 | def test_2pi_multiples(self): |
317 | 360 | """Test 2pi multiples are handled with the correct phase they introduce.""" |
318 | 361 | for eps in [0, 1e-10, -1e-10]: |
|
0 commit comments