qiskit.circuit.library.UnitaryGate(data, label=None, check_input=True)
Class quantum gates specified by a unitary matrix.
We can create a unitary gate from a unitary matrix then add it to a quantum circuit. The matrix can also be directly applied to the quantum circuit, see
from qiskit import QuantumCircuit from qiskit.circuit.library import UnitaryGate matrix = [[0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 0], [0, 1, 0, 0]] gate = UnitaryGate(matrix) circuit = QuantumCircuit(2) circuit.append(gate, [0, 1])
Create a gate from a numeric unitary matrix.
- data (numpy.ndarray (opens in a new tab) |Gate | BaseOperator) – Unitary operator.
- label (str (opens in a new tab) | None) – Unitary name for backend [Default: None].
- check_input (bool (opens in a new tab)) – If set to
Falsethis asserts the input is known to be unitary and the checking to validate this will be skipped. This should only ever be used if you know the input is unitary, setting this to
Falseand passing in a non-unitary matrix will result unexpected behavior and errors.
ValueError (opens in a new tab) – If input data is not an N-qubit unitary operator.
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
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.
return instruction params.
Get the time unit of duration.
Return the adjoint of the unitary.
Return the conjugate of the unitary.
control(num_ctrl_qubits=1, label=None, ctrl_state=None)
Return controlled version of gate.
- num_ctrl_qubits (int (opens in a new tab)) – Number of controls to add to gate (default is 1).
- label (int (opens in a new tab) | None) – Optional gate label.
- ctrl_state (int (opens in a new tab) |str (opens in a new tab) | None) – The control state in decimal or as a bit string (e.g.
2**num_ctrl_qubits - 1.
Controlled version of gate.
Return the adjoint of the unitary.
Return the transpose of the unitary.
Unitary gate parameter has to be an ndarray.