Bases: Decomposer
Predefined decomposition of SWAP gate to 3 CNOT gates.
---x--- ----•---[X]---•----
| → | | |
---x--- ---[X]---•---[X]---
Note:
This decomposition preserves the global phase of the SWAP gate.
Source code in opensquirrel/passes/decomposer/swap2cnot_decomposer.py
| class SWAP2CNOTDecomposer(Decomposer):
"""Predefined decomposition of SWAP gate to 3 CNOT gates.
---x--- ----•---[X]---•----
| → | | |
---x--- ---[X]---•---[X]---
Note:
This decomposition preserves the global phase of the SWAP gate.
"""
def decompose(self, gate: Gate) -> list[Gate]:
if gate.name != "SWAP":
return [gate]
qubit0, qubit1 = gate.get_qubit_operands()
return [
CNOT(qubit0, qubit1),
CNOT(qubit1, qubit0),
CNOT(qubit0, qubit1),
]
|