English
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

UnitaryGate

class UnitaryGate(data, label=None)[source]

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

from qiskit import QuantumCircuit
from qiskit.extensions 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 (matrix or Operator) – unitary operator.

  • label (str) – unitary name for backend [Default: None].

Raises

ExtensionError – if input data is not an N-qubit unitary operator.

Methods

add_decomposition

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

adjoint

Return the adjoint of the unitary.

assemble

Assemble a QasmQobjInstruction

broadcast_arguments

Validation and handling of the arguments and its relationship.

c_if

Set a classical equality condition on this instruction between the register or cbit classical and value val.

conjugate

Return the conjugate of the unitary.

control

Return controlled version of gate

copy

Copy of the instruction.

inverse

Return the adjoint of the unitary.

is_parameterized

Return True .IFF.

power

Creates a unitary gate as gate^exponent.

qasm

The qasm for a custom unitary gate This is achieved by adding a custom gate that corresponds to the definition of this gate.

repeat

Creates an instruction with gate repeated n amount of times.

reverse_ops

For a composite instruction, reverse the order of sub-instructions.

soft_compare

Soft comparison between gates.

to_matrix

Return a Numpy.array for the gate unitary matrix.

transpose

Return the transpose of the unitary.

validate_parameter

Unitary gate parameter has to be an ndarray.

Attributes

condition_bits

Get Clbits in condition.

Return type

List[Clbit]

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

Return type

str

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.