# LinearFunction#

class qiskit.circuit.library.LinearFunction(linear, validate_input=False)[source]#

Bases: 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

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.

Create a new linear function.

Parameters:
• LinearFunction (linear (list[list] or ndarray[bool] or QuantumCircuit or) β or PermutationGate or Clifford): data from which a linear function can be constructed. It can be either a nxn matrix (describing the linear transformation), a permutation (which is a special case of a linear function), another linear function, a clifford (when it corresponds to a linear function), or a quantum circuit composed of linear gates (CX and SWAP) and other objects described above, including nested subcircuits.

• validate_input β 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 the input matrix is not square or not invertible, or the input quantum circuit contains non-linear objects (for example, a Hadamard gate, or a Clifford that does not correspond to a linear function).

Attributes

condition_bits#

Get Clbits in condition.

decompositions#

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

definition#

Return definition in terms of other basic gates.

duration#

Get the duration.

label#

Return instruction label

linear#

Returns the n x n matrix representing this linear function.

name#

Return the name.

num_clbits#

Return the number of clbits.

num_qubits#

Return the number of qubits.

original_circuit#

Returns the original circuit used to construct this linear function (including None, when the linear function is not constructed from a circuit).

params#

return instruction params.

unit#

Get the time unit of duration.

Methods

extend_with_identity(num_qubits, positions)[source]#

Extend linear function to a linear function over nq qubits, with identities on other subsystems.

Parameters:
• num_qubits (int) β number of qubits of the extended function.

• positions (list[int]) β describes the positions of original qubits in the extended functionβs qubits.

Returns:

extended linear function.

Return type:

LinearFunction

function_str()[source]#

Return string representation of the linear function viewed as a linear transformation.

is_permutation()[source]#

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

mat_str()[source]#

Return string representation of the linear function viewed as a matrix with 0/1 entries.

permutation_pattern()[source]#

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.

synthesize()[source]#

Synthesizes the linear function into a quantum circuit.

Returns:

A circuit implementing the evolution.

Return type:

QuantumCircuit

validate_parameter(parameter)[source]#

Parameter validation