|
15 | 15 |
|
16 | 16 | from typing import AbstractSet, Sequence, Union
|
17 | 17 |
|
18 |
| -import numpy as np |
19 |
| - |
20 | 18 | import cirq
|
21 | 19 |
|
22 | 20 |
|
@@ -103,19 +101,19 @@ def _decompose_single_qubit(self, operation: cirq.Operation) -> cirq.OP_TREE:
|
103 | 101 | yield gate(qubit)
|
104 | 102 |
|
105 | 103 | def _decompose_two_qubit(self, operation: cirq.Operation) -> cirq.OP_TREE:
|
106 |
| - """Decomposes a two qubit gate into XXPow, YYPow, and ZZPow plus single qubit gates.""" |
| 104 | + """Decomposes a two qubit unitary operation into ZPOW, XPOW, and CNOT.""" |
107 | 105 | mat = cirq.unitary(operation)
|
108 |
| - kak = cirq.kak_decomposition(mat, check_preconditions=False) |
109 |
| - |
110 |
| - for qubit, mat in zip(operation.qubits, kak.single_qubit_operations_before): |
111 |
| - gates = cirq.single_qubit_matrix_to_gates(mat, self.atol) |
112 |
| - for gate in gates: |
113 |
| - yield gate(qubit) |
114 |
| - |
115 |
| - two_qubit_gates = [cirq.XX, cirq.YY, cirq.ZZ] |
116 |
| - for two_qubit_gate, coefficient in zip(two_qubit_gates, kak.interaction_coefficients): |
117 |
| - yield (two_qubit_gate ** (-coefficient * 2 / np.pi))(*operation.qubits) |
118 |
| - |
119 |
| - for qubit, mat in zip(operation.qubits, kak.single_qubit_operations_after): |
120 |
| - for gate in cirq.single_qubit_matrix_to_gates(mat, self.atol): |
121 |
| - yield gate(qubit) |
| 106 | + q0, q1 = operation.qubits |
| 107 | + naive = cirq.two_qubit_matrix_to_operations(q0, q1, mat, allow_partial_czs=False) |
| 108 | + temp = cirq.map_operations_and_unroll( |
| 109 | + cirq.Circuit(naive), |
| 110 | + lambda op, _: [cirq.H(op.qubits[1]), cirq.CNOT(*op.qubits), cirq.H(op.qubits[1])] |
| 111 | + if type(op.gate) == cirq.CZPowGate |
| 112 | + else op, |
| 113 | + ) |
| 114 | + cirq.merge_single_qubit_gates_into_phased_x_z(temp) |
| 115 | + # A final pass breaks up PhasedXPow into Rz, Rx. |
| 116 | + yield cirq.map_operations_and_unroll( |
| 117 | + temp, |
| 118 | + lambda op, _: cirq.decompose_once(op) if type(op.gate) == cirq.PhasedXPowGate else op, |
| 119 | + ).all_operations() |
0 commit comments