mimiqcircuits.operations.gates.standard.cswap¶
Controlled-SWAP (Fredkin) gate.
Classes
|
Three qubit Controlled-SWAP (Fredkin) gate. |
- class GateCSWAP(num_controls=None, operation=None, *args, **kwargs)[source]¶
Bases:
ControlThree qubit Controlled-SWAP (Fredkin) gate.
By convention, the first qubit is the control and the last two are the targets. The targets are swapped when the control is \(|1\rangle\).
Matrix Representation
\[\begin{split}\operatorname{CSWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]Examples
>>> from mimiqcircuits import * >>> GateCSWAP(), GateCSWAP().num_controls, GateCSWAP().num_targets, GateCSWAP().num_qubits (CSWAP, 1, 2, 3) >>> GateCSWAP().matrix() [1.0, 0, 0, 0, 0, 0, 0, 0] [0, 1.0, 0, 0, 0, 0, 0, 0] [0, 0, 1.0, 0, 0, 0, 0, 0] [0, 0, 0, 1.0, 0, 0, 0, 0] [0, 0, 0, 0, 1.0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 1.0, 0] [0, 0, 0, 0, 0, 1.0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 1.0] >>> c = Circuit().push(GateCSWAP(), 0, 1, 2) >>> c 3-qubit circuit with 1 instruction: └── CSWAP @ q[0], q[1:2] >>> GateCSWAP().power(2), GateCSWAP().inverse() (C(⨷ ² ID), CSWAP) >>> GateCSWAP().decompose() 3-qubit circuit with 3 instructions: ├── CX @ q[2], q[1] ├── C₂X @ q[0:1], q[2] └── CX @ q[2], q[1]