---
title: UnitaryGate (v1.0)
description: API reference for qiskit.circuit.library.UnitaryGate in qiskit v1.0
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/1.0/qiskit.circuit.library.UnitaryGate
---

# UnitaryGate

*class* `qiskit.circuit.library.UnitaryGate(data, label=None, check_input=True)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/circuit/library/generalized_gates/unitary.py#L43-L208)

Bases: [`Gate`](/docs/api/qiskit/1.0/qiskit.circuit.Gate "qiskit.circuit.gate.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()`](/docs/api/qiskit/1.0/qiskit.circuit.QuantumCircuit#unitary "qiskit.circuit.QuantumCircuit.unitary").

```python
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*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)  *|*[*Gate*](/docs/api/qiskit/1.0/qiskit.circuit.Gate "qiskit.circuit.Gate") *| BaseOperator*) – Unitary operator.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Unitary name for backend \[Default: `None`].
- **check\_input** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – 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**](https://docs.python.org/3/library/exceptions.html#ValueError) – 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`](#qiskit.circuit.library.UnitaryGate.base_class "qiskit.circuit.library.UnitaryGate.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`](/docs/api/qiskit/1.0/qiskit.transpiler.Target "qiskit.transpiler.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:

```python
>>> 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()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/circuit/library/generalized_gates/unitary.py#L130-L132)

Return the adjoint of the unitary.

### conjugate

`conjugate()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/circuit/library/generalized_gates/unitary.py#L126-L128)

Return the conjugate of the unitary.

### control

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

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/circuit/library/generalized_gates/unitary.py#L156-L194)

Return controlled version of gate.

**Parameters**

- **num\_ctrl\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int)) – Number of controls to add to gate (default is 1).
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Optional gate label.
- **ctrl\_state** ([*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The control state in decimal or as a bit string (e.g. `"1011"`). If `None`, use `2**num_ctrl_qubits - 1`.
- **annotated** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – indicates whether the controlled gate can be implemented as an annotated gate.

**Returns**

Controlled version of gate.

**Return type**

[ControlledGate](/docs/api/qiskit/1.0/qiskit.circuit.ControlledGate "qiskit.circuit.ControlledGate") | [AnnotatedOperation](/docs/api/qiskit/1.0/qiskit.circuit.AnnotatedOperation "qiskit.circuit.AnnotatedOperation")

### inverse

`inverse(annotated=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/circuit/library/generalized_gates/unitary.py#L122-L124)

Return the adjoint of the unitary.

### transpose

`transpose()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/circuit/library/generalized_gates/unitary.py#L134-L136)

Return the transpose of the unitary.

### validate\_parameter

`validate_parameter(parameter)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/1.0/qiskit/circuit/library/generalized_gates/unitary.py#L203-L208)

Unitary gate parameter has to be an ndarray.
