178 lines
5.3 KiB
Plaintext
178 lines
5.3 KiB
Plaintext
---
|
||
title: LinearFunction
|
||
description: API reference for qiskit.circuit.library.LinearFunction
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.circuit.library.LinearFunction
|
||
---
|
||
|
||
# LinearFunction
|
||
|
||
<Class id="qiskit.circuit.library.LinearFunction" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.20/qiskit/circuit/library/generalized_gates/linear_function.py" signature="LinearFunction(linear, validate_input=False)" modifiers="class">
|
||
Bases: `qiskit.circuit.gate.Gate`
|
||
|
||
A linear reversible circuit on n qubits.
|
||
|
||
Internally, a linear function acting on n qubits is represented as a n x n matrix of 0s and 1s in numpy array format.
|
||
|
||
A linear function can be synthesized into CX and SWAP gates using the Patel–Markov–Hayes algorithm, as implemented in `cnot_synth()` based on reference \[1].
|
||
|
||
For efficiency, the internal n x n matrix is stored in the format expected by cnot\_synth, which is the big-endian (and not the little-endian) bit-ordering convention.
|
||
|
||
**Example:** the circuit
|
||
|
||
```python
|
||
q_0: ──■──
|
||
┌─┴─┐
|
||
q_1: ┤ X ├
|
||
└───┘
|
||
q_2: ─────
|
||
```
|
||
|
||
is represented by a 3x3 linear matrix
|
||
|
||
$$
|
||
\begin{split}\begin{pmatrix}
|
||
1 & 0 & 0 \\
|
||
1 & 1 & 0 \\
|
||
0 & 0 & 1
|
||
\end{pmatrix}\end{split}
|
||
$$
|
||
|
||
**References:**
|
||
|
||
\[1] Ketan N. Patel, Igor L. Markov, and John P. Hayes, Optimal synthesis of linear reversible circuits, Quantum Inf. Comput. 8(3) (2008). [Online at umich.edu.](https://web.eecs.umich.edu/~imarkov/pubs/jour/qic08-cnot.pdf)
|
||
|
||
Create a new linear function.
|
||
|
||
**Parameters**
|
||
|
||
* **linear** (*list\[list] or ndarray\[bool] or* [*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")) – either an n x n matrix, describing the linear function, or a quantum circuit composed of linear gates only (currently supported gates are CX and SWAP).
|
||
* **validate\_input** (`Optional`\[`bool`]) – if True, performs more expensive input validation checks, such as checking that a given n x n matrix is invertible.
|
||
|
||
**Raises**
|
||
|
||
**CircuitError** – if the input is invalid: either a matrix is non \{square, invertible}, or a quantum circuit contains non-linear gates.
|
||
|
||
## Methods Defined Here
|
||
|
||
### is\_permutation
|
||
|
||
<Function id="qiskit.circuit.library.LinearFunction.is_permutation" signature="LinearFunction.is_permutation()">
|
||
Returns whether this linear function is a permutation, that is whether every row and every column of the n x n matrix has exactly one 1.
|
||
|
||
**Return type**
|
||
|
||
`bool`
|
||
</Function>
|
||
|
||
### permutation\_pattern
|
||
|
||
<Function id="qiskit.circuit.library.LinearFunction.permutation_pattern" signature="LinearFunction.permutation_pattern()">
|
||
This method first checks if a linear function is a permutation and raises a qiskit.circuit.exceptions.CircuitError if not. In the case that this linear function is a permutation, returns the permutation pattern.
|
||
</Function>
|
||
|
||
### synthesize
|
||
|
||
<Function id="qiskit.circuit.library.LinearFunction.synthesize" signature="LinearFunction.synthesize()">
|
||
Synthesizes the linear function into a quantum circuit.
|
||
|
||
**Returns**
|
||
|
||
A circuit implementing the evolution.
|
||
|
||
**Return type**
|
||
|
||
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
|
||
</Function>
|
||
|
||
### validate\_parameter
|
||
|
||
<Function id="qiskit.circuit.library.LinearFunction.validate_parameter" signature="LinearFunction.validate_parameter(parameter)">
|
||
Parameter validation
|
||
</Function>
|
||
|
||
## Attributes
|
||
|
||
### condition\_bits
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.condition_bits">
|
||
Get Clbits in condition.
|
||
|
||
**Return type**
|
||
|
||
`List`\[`Clbit`]
|
||
</Attribute>
|
||
|
||
### decompositions
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.decompositions">
|
||
Get the decompositions of the instruction from the SessionEquivalenceLibrary.
|
||
</Attribute>
|
||
|
||
### definition
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.definition">
|
||
Return definition in terms of other basic gates.
|
||
</Attribute>
|
||
|
||
### duration
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.duration">
|
||
Get the duration.
|
||
</Attribute>
|
||
|
||
### label
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.label">
|
||
Return instruction label
|
||
|
||
**Return type**
|
||
|
||
`str`
|
||
</Attribute>
|
||
|
||
### linear
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.linear">
|
||
Returns the n x n matrix representing this linear function
|
||
</Attribute>
|
||
|
||
### name
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.name">
|
||
Return the name.
|
||
</Attribute>
|
||
|
||
### num\_clbits
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.num_clbits">
|
||
Return the number of clbits.
|
||
</Attribute>
|
||
|
||
### num\_qubits
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.num_qubits">
|
||
Return the number of qubits.
|
||
</Attribute>
|
||
|
||
### original\_circuit
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.original_circuit">
|
||
Returns the original circuit used to construct this linear function (including None, when the linear function is not constructed from a circuit).
|
||
</Attribute>
|
||
|
||
### params
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.params">
|
||
return instruction params.
|
||
</Attribute>
|
||
|
||
### unit
|
||
|
||
<Attribute id="qiskit.circuit.library.LinearFunction.unit">
|
||
Get the time unit of duration.
|
||
</Attribute>
|
||
</Class>
|
||
|