|
13 | 13 |
|
14 | 14 | from cirq import ops, linalg, circuits, devices |
15 | 15 | from cirq.optimizers import merge_single_qubit_gates, drop_empty_moments |
| 16 | +from cirq._compat import deprecated |
16 | 17 |
|
17 | 18 | if TYPE_CHECKING: |
18 | 19 | import cirq |
19 | 20 |
|
20 | 21 |
|
| 22 | +@deprecated(deadline='v0.10', |
| 23 | + fix='Use cirq.decompose_two_qubit_interaction_into_four_fsim_gates.' |
| 24 | + ) |
21 | 25 | def decompose_two_qubit_interaction_into_four_fsim_gates_via_b( |
22 | 26 | interaction: Union['cirq.Operation', 'cirq.Gate', np.ndarray, Any], |
23 | 27 | *, |
24 | 28 | fsim_gate: Union['cirq.FSimGate', 'cirq.ISwapPowGate'], |
25 | 29 | qubits: Sequence['cirq.Qid'] = None) -> 'cirq.Circuit': |
| 30 | + circuit = decompose_two_qubit_interaction_into_four_fsim_gates( |
| 31 | + interaction, fsim_gate=fsim_gate, qubits=qubits) |
| 32 | + merge_single_qubit_gates.MergeSingleQubitGates().optimize_circuit(circuit) |
| 33 | + drop_empty_moments.DropEmptyMoments().optimize_circuit(circuit) |
| 34 | + return circuit |
| 35 | + |
| 36 | + |
| 37 | +def decompose_two_qubit_interaction_into_four_fsim_gates( |
| 38 | + interaction: Union['cirq.Operation', 'cirq.Gate', np.ndarray, Any], |
| 39 | + *, |
| 40 | + fsim_gate: Union['cirq.FSimGate', 'cirq.ISwapPowGate'], |
| 41 | + qubits: Sequence['cirq.Qid'] = None) -> 'cirq.Circuit': |
26 | 42 | """Decomposes operations into an FSimGate near theta=pi/2, phi=0. |
27 | 43 |
|
28 | 44 | This decomposition is guaranteed to use exactly four of the given FSim |
@@ -72,19 +88,18 @@ def decompose_two_qubit_interaction_into_four_fsim_gates_via_b( |
72 | 88 |
|
73 | 89 | b_decomposition = _decompose_b_gate_into_two_fsims(fsim_gate=mapped_gate, |
74 | 90 | qubits=qubits) |
75 | | - result = [] |
| 91 | + b_decomposition = [ |
| 92 | + fsim_gate(*op.qubits) if op.gate == mapped_gate else op |
| 93 | + for op in b_decomposition |
| 94 | + ] |
| 95 | + |
| 96 | + result = circuits.Circuit() |
76 | 97 | for op in result_using_b_gates: |
77 | 98 | if isinstance(op.gate, _BGate): |
78 | | - result.extend(b_decomposition) |
| 99 | + result.append(b_decomposition) |
79 | 100 | else: |
80 | 101 | result.append(op) |
81 | | - |
82 | | - circuit = circuits.Circuit( |
83 | | - fsim_gate(*op.qubits) if op.gate == mapped_gate else op |
84 | | - for op in result) |
85 | | - merge_single_qubit_gates.MergeSingleQubitGates().optimize_circuit(circuit) |
86 | | - drop_empty_moments.DropEmptyMoments().optimize_circuit(circuit) |
87 | | - return circuit |
| 102 | + return result |
88 | 103 |
|
89 | 104 |
|
90 | 105 | def _sticky_0_to_1(v: float, *, atol: float) -> Optional[float]: |
|
0 commit comments