24
24
25
25
import numpy as np
26
26
27
- from cirq import ops , linalg , protocols
27
+ from cirq import circuits , ops , linalg , protocols
28
28
from cirq .transformers .analytical_decompositions import single_qubit_decompositions
29
+ from cirq .transformers .merge_single_qubit_gates import merge_single_qubit_gates_to_phxz
29
30
30
31
if TYPE_CHECKING :
31
32
import cirq
@@ -40,6 +41,7 @@ def two_qubit_matrix_to_sqrt_iswap_operations(
40
41
use_sqrt_iswap_inv : bool = False ,
41
42
atol : float = 1e-8 ,
42
43
check_preconditions : bool = True ,
44
+ clean_operations : bool = False ,
43
45
) -> Sequence ['cirq.Operation' ]:
44
46
"""Decomposes a two-qubit operation into ZPow/XPow/YPow/sqrt-iSWAP gates.
45
47
@@ -69,6 +71,8 @@ def two_qubit_matrix_to_sqrt_iswap_operations(
69
71
construction.
70
72
check_preconditions: If set, verifies that the input corresponds to a
71
73
4x4 unitary before decomposing.
74
+ clean_operations: Merges runs of single qubit gates to a single `cirq.PhasedXZGate` in
75
+ the resulting operations list.
72
76
73
77
Returns:
74
78
A list of operations implementing the matrix including at most three
@@ -92,7 +96,11 @@ def two_qubit_matrix_to_sqrt_iswap_operations(
92
96
operations = _kak_decomposition_to_sqrt_iswap_operations (
93
97
q0 , q1 , kak , required_sqrt_iswap_count , use_sqrt_iswap_inv , atol = atol
94
98
)
95
- return operations
99
+ return (
100
+ [* merge_single_qubit_gates_to_phxz (circuits .Circuit (operations )).all_operations ()]
101
+ if clean_operations
102
+ else operations
103
+ )
96
104
97
105
98
106
def _kak_decomposition_to_sqrt_iswap_operations (
0 commit comments