File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -75,19 +75,21 @@ def _has_unitary_(self):
75
75
return True
76
76
77
77
def _decompose_ (self , qubits : Sequence ['cirq.Qid' ]) -> 'cirq.OP_TREE' :
78
- # List is need otherwise permutation[j] = -1 fails to assign to a tuple
79
- permutation = list (deepcopy (self .permutation ))
78
+ permutation = [p for p in self .permutation ]
80
79
81
80
for i in range (len (permutation )):
81
+
82
82
if permutation [i ] == - 1 :
83
83
continue
84
84
cycle = [i ]
85
85
while permutation [cycle [- 1 ]] != i :
86
86
cycle .append (permutation [cycle [- 1 ]])
87
+
87
88
for j in cycle :
88
89
permutation [j ] = - 1
89
- cycle .reverse ()
90
- # yield len(cycle) - 1 swap operations
90
+
91
+ for idx in cycle [1 :]:
92
+ yield swap_gates .SWAP (qubits [cycle [0 ]], qubits [idx ])
91
93
92
94
def _apply_unitary_ (self , args : 'cirq.ApplyUnitaryArgs' ):
93
95
# Compute the permutation index list.
You can’t perform that action at this time.
0 commit comments