Skip to main contentIBM Quantum Documentation

UnitaryGate

qiskit.circuit.library.UnitaryGate(data, label=None, check_input=True) GitHub(opens in a new tab)

Bases: Gate

Class quantum gates specified by a unitary matrix.

Example

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 QuantumCircuit.unitary().

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.

Parameters

  • 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 False this 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 False and passing in a non-unitary matrix will result unexpected behavior and errors.

Raises

ValueError(opens in a new tab) – If input data is not an N-qubit unitary operator.


Attributes

base_class

Get the base class of this instruction. This is guaranteed to be in the inheritance tree of self.

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.

condition

The classical condition on the instruction.

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

mutable

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.

name

Return the name.

num_clbits

Return the number of clbits.

num_qubits

Return the number of qubits.

params

return instruction params.

unit

Get the time unit of duration.


Methods

adjoint

adjoint()

Return the adjoint of the unitary.

conjugate

conjugate()

Return the conjugate of the unitary.

control

control(num_ctrl_qubits=1, label=None, ctrl_state=None, annotated=False)

Return controlled version of gate.

Parameters

Returns

Controlled version of gate.

Return type

ControlledGate | AnnotatedOperation

inverse

inverse(annotated=False)

Return the adjoint of the unitary.

transpose

transpose()

Return the transpose of the unitary.

validate_parameter

validate_parameter(parameter)

Unitary gate parameter has to be an ndarray.

Was this page helpful?