Skip to content

Commit 2b0d564

Browse files
PR suggestions applied
1 parent 9ac6870 commit 2b0d564

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cirq-core/cirq/ops/permutation_gate.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,21 @@ def _has_unitary_(self):
7575
return True
7676

7777
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]
8079

8180
for i in range(len(permutation)):
81+
8282
if permutation[i] == -1:
8383
continue
8484
cycle = [i]
8585
while permutation[cycle[-1]] != i:
8686
cycle.append(permutation[cycle[-1]])
87+
8788
for j in cycle:
8889
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])
9193

9294
def _apply_unitary_(self, args: 'cirq.ApplyUnitaryArgs'):
9395
# Compute the permutation index list.

0 commit comments

Comments
 (0)