149 lines
3.5 KiB
Plaintext
149 lines
3.5 KiB
Plaintext
---
|
||
title: SwapGate
|
||
description: API reference for qiskit.circuit.library.SwapGate
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.circuit.library.SwapGate
|
||
---
|
||
|
||
# SwapGate
|
||
|
||
<Class id="qiskit.circuit.library.SwapGate" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.22/qiskit/circuit/library/standard_gates/swap.py" signature="SwapGate(label=None)" modifiers="class">
|
||
Bases: [`qiskit.circuit.gate.Gate`](qiskit.circuit.Gate "qiskit.circuit.gate.Gate")
|
||
|
||
The SWAP gate.
|
||
|
||
This is a symmetric and Clifford gate.
|
||
|
||
Can be applied to a [`QuantumCircuit`](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") with the [`swap()`](qiskit.circuit.QuantumCircuit#swap "qiskit.circuit.QuantumCircuit.swap") method.
|
||
|
||
**Circuit symbol:**
|
||
|
||
```python
|
||
q_0: ─X─
|
||
│
|
||
q_1: ─X─
|
||
```
|
||
|
||
**Matrix Representation:**
|
||
|
||
$$
|
||
\begin{split}SWAP =
|
||
\begin{pmatrix}
|
||
1 & 0 & 0 & 0 \\
|
||
0 & 0 & 1 & 0 \\
|
||
0 & 1 & 0 & 0 \\
|
||
0 & 0 & 0 & 1
|
||
\end{pmatrix}\end{split}
|
||
$$
|
||
|
||
The gate is equivalent to a state swap and is a classical logic gate.
|
||
|
||
$$
|
||
|a, b\rangle \rightarrow |b, a\rangle
|
||
$$
|
||
|
||
Create new SWAP gate.
|
||
|
||
## Methods Defined Here
|
||
|
||
### control
|
||
|
||
<Function id="qiskit.circuit.library.SwapGate.control" signature="SwapGate.control(num_ctrl_qubits=1, label=None, ctrl_state=None)">
|
||
Return a (multi-)controlled-SWAP gate.
|
||
|
||
One control returns a CSWAP (Fredkin) gate.
|
||
|
||
**Parameters**
|
||
|
||
* **num\_ctrl\_qubits** (*int*) – number of control qubits.
|
||
* **label** (*str or None*) – An optional label for the gate \[Default: None]
|
||
* **ctrl\_state** (*int or str or None*) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.
|
||
|
||
**Returns**
|
||
|
||
controlled version of this gate.
|
||
|
||
**Return type**
|
||
|
||
[ControlledGate](qiskit.circuit.ControlledGate "qiskit.circuit.ControlledGate")
|
||
</Function>
|
||
|
||
### inverse
|
||
|
||
<Function id="qiskit.circuit.library.SwapGate.inverse" signature="SwapGate.inverse()">
|
||
Return inverse Swap gate (itself).
|
||
</Function>
|
||
|
||
## Attributes
|
||
|
||
### condition\_bits
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.condition_bits">
|
||
Get Clbits in condition.
|
||
|
||
**Return type**
|
||
|
||
`List`\[[`Clbit`](qiskit.circuit.Clbit "qiskit.circuit.classicalregister.Clbit")]
|
||
</Attribute>
|
||
|
||
### decompositions
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.decompositions">
|
||
Get the decompositions of the instruction from the SessionEquivalenceLibrary.
|
||
</Attribute>
|
||
|
||
### definition
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.definition">
|
||
Return definition in terms of other basic gates.
|
||
</Attribute>
|
||
|
||
### duration
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.duration">
|
||
Get the duration.
|
||
</Attribute>
|
||
|
||
### label
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.label">
|
||
Return instruction label
|
||
|
||
**Return type**
|
||
|
||
`str`
|
||
</Attribute>
|
||
|
||
### name
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.name">
|
||
Return the name.
|
||
</Attribute>
|
||
|
||
### num\_clbits
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.num_clbits">
|
||
Return the number of clbits.
|
||
</Attribute>
|
||
|
||
### num\_qubits
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.num_qubits">
|
||
Return the number of qubits.
|
||
</Attribute>
|
||
|
||
### params
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.params">
|
||
return instruction params.
|
||
</Attribute>
|
||
|
||
### unit
|
||
|
||
<Attribute id="qiskit.circuit.library.SwapGate.unit">
|
||
Get the time unit of duration.
|
||
</Attribute>
|
||
</Class>
|
||
|