# CSwapGate¶

class CSwapGate(label=None, ctrl_state=None)[source]

Controlled-X gate.

Circuit symbol:

q_0: ─X─
│
q_1: ─X─
│
q_2: ─■─


Matrix representation:

$\begin{split}CSWAP\ q_0, q_1, q_2 = |0 \rangle \langle 0| \otimes I \otimes I + |1 \rangle \langle 1| \otimes SWAP = \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 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 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 & 0 & 1 \\ \end{pmatrix}\end{split}$

Note

In Qiskit’s convention, higher qubit indices are more significant (little endian convention). In many textbooks, controlled gates are presented with the assumption of more significant qubits as control, which in our case would be q_2. Thus a textbook matrix for this gate will be:

q_0: ─■─
│
q_1: ─X─
│
q_2: ─X─

$\begin{split}CSWAP\ q_2, q_1, q_0 = |0 \rangle \langle 0| \otimes I \otimes I + |1 \rangle \langle 1| \otimes SWAP = \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}$

In the computational basis, this gate swaps the states of the two target qubits if the control qubit is in the $$|1\rangle$$ state.

$|0, b, c\rangle \rightarrow |0, b, c\rangle |1, b, c\rangle \rightarrow |1, c, b\rangle$

Create new CSWAP gate.

Attributes

 CSwapGate.ctrl_state Return the control state of the gate as a decimal integer. CSwapGate.decompositions Get the decompositions of the instruction from the SessionEquivalenceLibrary. CSwapGate.definition Return definition in terms of other basic gates. CSwapGate.label Return gate label CSwapGate.params return instruction params.

Methods

 CSwapGate.add_decomposition(decomposition) Add a decomposition of the instruction to the SessionEquivalenceLibrary. Assemble a QasmQobjInstruction CSwapGate.broadcast_arguments(qargs, cargs) Validation and handling of the arguments and its relationship. CSwapGate.c_if(classical, val) Add classical condition on register classical and value val. CSwapGate.control([num_ctrl_qubits, label, …]) Return controlled version of gate. CSwapGate.copy([name]) Copy of the instruction. Return inverse CSwap gate (itself). Return True .IFF. For a composite instruction, reverse the order of sub-gates. CSwapGate.power(exponent) Creates a unitary gate as gate^exponent. Return a default OpenQASM string for the instruction. Creates an instruction with gate repeated n amount of times. Return a numpy.array for the Fredkin (CSWAP) gate.