382 lines
10 KiB
Plaintext
382 lines
10 KiB
Plaintext
---
|
||
title: UnitaryGate (v0.31)
|
||
description: API reference for qiskit.extensions.UnitaryGate in qiskit v0.31
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.extensions.UnitaryGate
|
||
---
|
||
|
||
# UnitaryGate
|
||
|
||
<Class id="qiskit.extensions.UnitaryGate" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.18/qiskit/extensions/unitary.py" signature="UnitaryGate(data, label=None)" modifiers="class">
|
||
Bases: `qiskit.circuit.gate.Gate`
|
||
|
||
Class for representing unitary gates
|
||
|
||
Create a gate from a numeric unitary matrix.
|
||
|
||
**Parameters**
|
||
|
||
* **data** (*matrix or* [*Operator*](qiskit.quantum_info.Operator "qiskit.quantum_info.Operator")) – unitary operator.
|
||
* **label** (*str*) – unitary name for backend \[Default: None].
|
||
|
||
**Raises**
|
||
|
||
**ExtensionError** – if input data is not an N-qubit unitary operator.
|
||
|
||
## Methods
|
||
|
||
<span id="qiskit-extensions-unitarygate-add-decomposition" />
|
||
|
||
### add\_decomposition
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.add_decomposition" signature="UnitaryGate.add_decomposition(decomposition)">
|
||
Add a decomposition of the instruction to the SessionEquivalenceLibrary.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-adjoint" />
|
||
|
||
### adjoint
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.adjoint" signature="UnitaryGate.adjoint()">
|
||
Return the adjoint of the unitary.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-assemble" />
|
||
|
||
### assemble
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.assemble" signature="UnitaryGate.assemble()">
|
||
Assemble a QasmQobjInstruction
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-broadcast-arguments" />
|
||
|
||
### broadcast\_arguments
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.broadcast_arguments" signature="UnitaryGate.broadcast_arguments(qargs, cargs)">
|
||
Validation and handling of the arguments and its relationship.
|
||
|
||
For example, `cx([q[0],q[1]], q[2])` means `cx(q[0], q[2]); cx(q[1], q[2])`. This method yields the arguments in the right grouping. In the given example:
|
||
|
||
```python
|
||
in: [[q[0],q[1]], q[2]],[]
|
||
outs: [q[0], q[2]], []
|
||
[q[1], q[2]], []
|
||
```
|
||
|
||
The general broadcasting rules are:
|
||
|
||
> * If len(qargs) == 1:
|
||
>
|
||
> ```python
|
||
> [q[0], q[1]] -> [q[0]],[q[1]]
|
||
> ```
|
||
>
|
||
> * If len(qargs) == 2:
|
||
>
|
||
> ```python
|
||
> [[q[0], q[1]], [r[0], r[1]]] -> [q[0], r[0]], [q[1], r[1]]
|
||
> [[q[0]], [r[0], r[1]]] -> [q[0], r[0]], [q[0], r[1]]
|
||
> [[q[0], q[1]], [r[0]]] -> [q[0], r[0]], [q[1], r[0]]
|
||
> ```
|
||
>
|
||
> * If len(qargs) >= 3:
|
||
>
|
||
> ```python
|
||
> [q[0], q[1]], [r[0], r[1]], ...] -> [q[0], r[0], ...], [q[1], r[1], ...]
|
||
> ```
|
||
|
||
**Parameters**
|
||
|
||
* **qargs** (`List`) – List of quantum bit arguments.
|
||
* **cargs** (`List`) – List of classical bit arguments.
|
||
|
||
**Return type**
|
||
|
||
`Tuple`\[`List`, `List`]
|
||
|
||
**Returns**
|
||
|
||
A tuple with single arguments.
|
||
|
||
**Raises**
|
||
|
||
**CircuitError** – If the input is not valid. For example, the number of arguments does not match the gate expectation.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-c-if" />
|
||
|
||
### c\_if
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.c_if" signature="UnitaryGate.c_if(classical, val)">
|
||
Add classical condition on register or cbit classical and value val.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-conjugate" />
|
||
|
||
### conjugate
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.conjugate" signature="UnitaryGate.conjugate()">
|
||
Return the conjugate of the unitary.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-control" />
|
||
|
||
### control
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.control" signature="UnitaryGate.control(num_ctrl_qubits=1, label=None, ctrl_state=None)">
|
||
Return controlled version of gate
|
||
|
||
**Parameters**
|
||
|
||
* **num\_ctrl\_qubits** (*int*) – number of controls to add to gate (default=1)
|
||
* **label** (*str*) – optional gate label
|
||
* **ctrl\_state** (*int or str or None*) – The control state in decimal or as a bit string (e.g. ‘1011’). If None, use 2\*\*num\_ctrl\_qubits-1.
|
||
|
||
**Returns**
|
||
|
||
controlled version of gate.
|
||
|
||
**Return type**
|
||
|
||
[UnitaryGate](qiskit.extensions.UnitaryGate "qiskit.extensions.UnitaryGate")
|
||
|
||
**Raises**
|
||
|
||
* **QiskitError** – Invalid ctrl\_state.
|
||
* **ExtensionError** – Non-unitary controlled unitary.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-copy" />
|
||
|
||
### copy
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.copy" signature="UnitaryGate.copy(name=None)">
|
||
Copy of the instruction.
|
||
|
||
**Parameters**
|
||
|
||
**name** (*str*) – name to be given to the copied circuit, if None then the name stays the same.
|
||
|
||
**Returns**
|
||
|
||
**a copy of the current instruction, with the name**
|
||
|
||
updated if it was provided
|
||
|
||
**Return type**
|
||
|
||
[qiskit.circuit.Instruction](qiskit.circuit.Instruction "qiskit.circuit.Instruction")
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-inverse" />
|
||
|
||
### inverse
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.inverse" signature="UnitaryGate.inverse()">
|
||
Return the adjoint of the unitary.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-is-parameterized" />
|
||
|
||
### is\_parameterized
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.is_parameterized" signature="UnitaryGate.is_parameterized()">
|
||
Return True .IFF. instruction is parameterized else False
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-mirror" />
|
||
|
||
### mirror
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.mirror" signature="UnitaryGate.mirror()">
|
||
DEPRECATED: use instruction.reverse\_ops().
|
||
|
||
**Returns**
|
||
|
||
**a new instruction with sub-instructions**
|
||
|
||
reversed.
|
||
|
||
**Return type**
|
||
|
||
[qiskit.circuit.Instruction](qiskit.circuit.Instruction "qiskit.circuit.Instruction")
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-power" />
|
||
|
||
### power
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.power" signature="UnitaryGate.power(exponent)">
|
||
Creates a unitary gate as gate^exponent.
|
||
|
||
**Parameters**
|
||
|
||
**exponent** (*float*) – Gate^exponent
|
||
|
||
**Returns**
|
||
|
||
To which to\_matrix is self.to\_matrix^exponent.
|
||
|
||
**Return type**
|
||
|
||
[qiskit.extensions.UnitaryGate](qiskit.extensions.UnitaryGate "qiskit.extensions.UnitaryGate")
|
||
|
||
**Raises**
|
||
|
||
**CircuitError** – If Gate is not unitary
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-qasm" />
|
||
|
||
### qasm
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.qasm" signature="UnitaryGate.qasm()">
|
||
The qasm for a custom unitary gate This is achieved by adding a custom gate that corresponds to the definition of this gate. It gives the gate a random name if one hasn’t been given to it.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-repeat" />
|
||
|
||
### repeat
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.repeat" signature="UnitaryGate.repeat(n)">
|
||
Creates an instruction with gate repeated n amount of times.
|
||
|
||
**Parameters**
|
||
|
||
**n** (*int*) – Number of times to repeat the instruction
|
||
|
||
**Returns**
|
||
|
||
Containing the definition.
|
||
|
||
**Return type**
|
||
|
||
[qiskit.circuit.Instruction](qiskit.circuit.Instruction "qiskit.circuit.Instruction")
|
||
|
||
**Raises**
|
||
|
||
**CircuitError** – If n \< 1.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-reverse-ops" />
|
||
|
||
### reverse\_ops
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.reverse_ops" signature="UnitaryGate.reverse_ops()">
|
||
For a composite instruction, reverse the order of sub-instructions.
|
||
|
||
This is done by recursively reversing all sub-instructions. It does not invert any gate.
|
||
|
||
**Returns**
|
||
|
||
**a new instruction with**
|
||
|
||
sub-instructions reversed.
|
||
|
||
**Return type**
|
||
|
||
[qiskit.circuit.Instruction](qiskit.circuit.Instruction "qiskit.circuit.Instruction")
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-soft-compare" />
|
||
|
||
### soft\_compare
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.soft_compare" signature="UnitaryGate.soft_compare(other)">
|
||
Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.
|
||
|
||
**Parameters**
|
||
|
||
**other** (*instruction*) – other instruction.
|
||
|
||
**Returns**
|
||
|
||
are self and other equal up to parameter expressions.
|
||
|
||
**Return type**
|
||
|
||
bool
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-to-matrix" />
|
||
|
||
### to\_matrix
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.to_matrix" signature="UnitaryGate.to_matrix()">
|
||
Return a Numpy.array for the gate unitary matrix.
|
||
|
||
**Returns**
|
||
|
||
if the Gate subclass has a matrix definition.
|
||
|
||
**Return type**
|
||
|
||
np.ndarray
|
||
|
||
**Raises**
|
||
|
||
**CircuitError** – If a Gate subclass does not implement this method an exception will be raised when this base class method is called.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-transpose" />
|
||
|
||
### transpose
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.transpose" signature="UnitaryGate.transpose()">
|
||
Return the transpose of the unitary.
|
||
</Function>
|
||
|
||
<span id="qiskit-extensions-unitarygate-validate-parameter" />
|
||
|
||
### validate\_parameter
|
||
|
||
<Function id="qiskit.extensions.UnitaryGate.validate_parameter" signature="UnitaryGate.validate_parameter(parameter)">
|
||
Unitary gate parameter has to be an ndarray.
|
||
</Function>
|
||
|
||
## Attributes
|
||
|
||
### decompositions
|
||
|
||
<Attribute id="qiskit.extensions.UnitaryGate.decompositions">
|
||
Get the decompositions of the instruction from the SessionEquivalenceLibrary.
|
||
</Attribute>
|
||
|
||
### definition
|
||
|
||
<Attribute id="qiskit.extensions.UnitaryGate.definition">
|
||
Return definition in terms of other basic gates.
|
||
</Attribute>
|
||
|
||
### duration
|
||
|
||
<Attribute id="qiskit.extensions.UnitaryGate.duration">
|
||
Get the duration.
|
||
</Attribute>
|
||
|
||
### label
|
||
|
||
<Attribute id="qiskit.extensions.UnitaryGate.label">
|
||
Return instruction label
|
||
|
||
**Return type**
|
||
|
||
`str`
|
||
</Attribute>
|
||
|
||
### params
|
||
|
||
<Attribute id="qiskit.extensions.UnitaryGate.params">
|
||
return instruction params.
|
||
</Attribute>
|
||
|
||
### unit
|
||
|
||
<Attribute id="qiskit.extensions.UnitaryGate.unit">
|
||
Get the time unit of duration.
|
||
</Attribute>
|
||
</Class>
|
||
|