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 .
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
 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. (opens in a new tab)
Create a new linear function.
- LinearFunction (linear (list (opens in a new tab)[list (opens in a new tab)] or ndarray[bool (opens in a new tab)] 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.
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).
Get the base class of this instruction. This is guaranteed to be in the inheritance tree of
The “base class” of an instruction is the lowest class in its inheritance tree that the object should be considered entirely compatible with for _all_ circuit applications. This typically means that the subclass is defined purely to offer some sort of programmer convenience over the base class, and the base class is the “true” class for a behavioural perspective. In particular, you should not override
base_class if you are defining a custom version of an instruction that will be implemented differently by hardware, such as an alternative measurement strategy, or a version of a parametrised gate with a particular set of parameters for the purposes of distinguishing it in a
Target from the full parametrised gate.
This is often exactly equivalent to
type(obj), except in the case of singleton instances of standard-library instructions. These singleton instances are special subclasses of their base class, and this property will return that base. For example:
>>> isinstance(XGate(), XGate) True >>> type(XGate()) is XGate False >>> XGate().base_class is XGate True
In general, you should not rely on the precise class of an instruction; within a given circuit, it is expected that
Instruction.name should be a more suitable discriminator in most situations.
The classical condition on the instruction.
Get Clbits in condition.
Get the decompositions of the instruction from the SessionEquivalenceLibrary.
Return definition in terms of other basic gates.
Get the duration.
Return instruction label
Returns the n x n matrix representing this linear function.
Is this instance is a mutable unique instance or not.
If this attribute is
False the gate instance is a shared singleton and is not mutable.
Return the name.
Return the number of clbits.
Return the number of qubits.
Returns the original circuit used to construct this linear function (including None, when the linear function is not constructed from a circuit).
return instruction params.
Get the time unit of duration.
Extend linear function to a linear function over nq qubits, with identities on other subsystems.
- num_qubits (int (opens in a new tab)) – number of qubits of the extended function.
- positions (list (opens in a new tab)[int (opens in a new tab)]) – describes the positions of original qubits in the extended function’s qubits.
extended linear function.
Return string representation of the linear function viewed as a linear transformation.
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 string representation of the linear function viewed as a matrix with 0/1 entries.
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.
Synthesizes the linear function into a quantum circuit.
A circuit implementing the evolution.