qiskit-documentation/docs/api/qiskit/0.43/qiskit.extensions.SingleQub...

370 lines
11 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: SingleQubitUnitary
description: API reference for qiskit.extensions.SingleQubitUnitary
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.extensions.SingleQubitUnitary
---
# SingleQubitUnitary
<Class id="qiskit.extensions.SingleQubitUnitary" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.24/qiskit/extensions/quantum_initializer/squ.py" signature="SingleQubitUnitary(unitary_matrix, mode='ZYZ', up_to_diagonal=False)" modifiers="class">
Bases: [`Gate`](qiskit.circuit.Gate "qiskit.circuit.gate.Gate")
u = 2\*2 unitary (given as a (complex) numpy.ndarray)
mode - determines the used decomposition by providing the rotation axes
**up\_to\_diagonal - the single-qubit unitary is decomposed up to a diagonal matrix,**
i.e. a unitary u is implemented such that there exists a 2\*2 diagonal gate d with u = d.dot(u).
Create a new single qubit gate based on the unitary `u`.
## Methods
<span id="qiskit-extensions-singlequbitunitary-add-decomposition" />
### add\_decomposition
<Function id="qiskit.extensions.SingleQubitUnitary.add_decomposition" signature="SingleQubitUnitary.add_decomposition(decomposition)">
Add a decomposition of the instruction to the SessionEquivalenceLibrary.
</Function>
<span id="qiskit-extensions-singlequbitunitary-assemble" />
### assemble
<Function id="qiskit.extensions.SingleQubitUnitary.assemble" signature="SingleQubitUnitary.assemble()">
Assemble a QasmQobjInstruction
</Function>
<span id="qiskit-extensions-singlequbitunitary-broadcast-arguments" />
### broadcast\_arguments
<Function id="qiskit.extensions.SingleQubitUnitary.broadcast_arguments" signature="SingleQubitUnitary.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.
**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.
**Return type**
Iterable\[tuple\[list, list]]
</Function>
<span id="qiskit-extensions-singlequbitunitary-c-if" />
### c\_if
<Function id="qiskit.extensions.SingleQubitUnitary.c_if" signature="SingleQubitUnitary.c_if(classical, val)">
Set a classical equality condition on this instruction between the register or cbit `classical` and value `val`.
<Admonition title="Note" type="note">
This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.
</Admonition>
</Function>
<span id="qiskit-extensions-singlequbitunitary-control" />
### control
<Function id="qiskit.extensions.SingleQubitUnitary.control" signature="SingleQubitUnitary.control(num_ctrl_qubits=1, label=None, ctrl_state=None)">
Return controlled version of gate. See [`ControlledGate`](qiskit.circuit.ControlledGate "qiskit.circuit.ControlledGate") for usage.
**Parameters**
* **num\_ctrl\_qubits** (*int*) number of controls to add to gate (default=1)
* **label** (*str | None*) optional gate label
* **ctrl\_state** (*int | str | None*) The control state in decimal or as a bitstring (e.g. 111). If None, use 2\*\*num\_ctrl\_qubits-1.
**Returns**
Controlled version of gate. This default algorithm uses num\_ctrl\_qubits-1 ancillae qubits so returns a gate of size num\_qubits + 2\*num\_ctrl\_qubits - 1.
**Return type**
[qiskit.circuit.ControlledGate](qiskit.circuit.ControlledGate "qiskit.circuit.ControlledGate")
**Raises**
**QiskitError** unrecognized mode or invalid ctrl\_state
</Function>
<span id="qiskit-extensions-singlequbitunitary-copy" />
### copy
<Function id="qiskit.extensions.SingleQubitUnitary.copy" signature="SingleQubitUnitary.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-singlequbitunitary-inverse" />
### inverse
<Function id="qiskit.extensions.SingleQubitUnitary.inverse" signature="SingleQubitUnitary.inverse()">
Return the inverse.
Note that the resulting gate has an empty `params` property.
</Function>
<span id="qiskit-extensions-singlequbitunitary-is-parameterized" />
### is\_parameterized
<Function id="qiskit.extensions.SingleQubitUnitary.is_parameterized" signature="SingleQubitUnitary.is_parameterized()">
Return True .IFF. instruction is parameterized else False
</Function>
<span id="qiskit-extensions-singlequbitunitary-power" />
### power
<Function id="qiskit.extensions.SingleQubitUnitary.power" signature="SingleQubitUnitary.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-singlequbitunitary-qasm" />
### qasm
<Function id="qiskit.extensions.SingleQubitUnitary.qasm" signature="SingleQubitUnitary.qasm()">
Return a default OpenQASM string for the instruction.
Derived instructions may override this to print in a different format (e.g. measure q\[0] -> c\[0];).
</Function>
<span id="qiskit-extensions-singlequbitunitary-repeat" />
### repeat
<Function id="qiskit.extensions.SingleQubitUnitary.repeat" signature="SingleQubitUnitary.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-singlequbitunitary-reverse-ops" />
### reverse\_ops
<Function id="qiskit.extensions.SingleQubitUnitary.reverse_ops" signature="SingleQubitUnitary.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-singlequbitunitary-soft-compare" />
### soft\_compare
<Function id="qiskit.extensions.SingleQubitUnitary.soft_compare" signature="SingleQubitUnitary.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-singlequbitunitary-to-matrix" />
### to\_matrix
<Function id="qiskit.extensions.SingleQubitUnitary.to_matrix" signature="SingleQubitUnitary.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-singlequbitunitary-validate-parameter" />
### validate\_parameter
<Function id="qiskit.extensions.SingleQubitUnitary.validate_parameter" signature="SingleQubitUnitary.validate_parameter(parameter)">
Single-qubit unitary gate parameter has to be an ndarray.
</Function>
## Attributes
### condition\_bits
<Attribute id="qiskit.extensions.SingleQubitUnitary.condition_bits">
Get Clbits in condition.
</Attribute>
### decompositions
<Attribute id="qiskit.extensions.SingleQubitUnitary.decompositions">
Get the decompositions of the instruction from the SessionEquivalenceLibrary.
</Attribute>
### definition
<Attribute id="qiskit.extensions.SingleQubitUnitary.definition">
Return definition in terms of other basic gates.
</Attribute>
### diag
<Attribute id="qiskit.extensions.SingleQubitUnitary.diag">
Returns the diagonal gate D up to which the single-qubit unitary u is implemented.
I.e. u=D.u, where u is the unitary implemented by the found circuit.
</Attribute>
### duration
<Attribute id="qiskit.extensions.SingleQubitUnitary.duration">
Get the duration.
</Attribute>
### label
<Attribute id="qiskit.extensions.SingleQubitUnitary.label">
Return instruction label
</Attribute>
### name
<Attribute id="qiskit.extensions.SingleQubitUnitary.name">
Return the name.
</Attribute>
### num\_clbits
<Attribute id="qiskit.extensions.SingleQubitUnitary.num_clbits">
Return the number of clbits.
</Attribute>
### num\_qubits
<Attribute id="qiskit.extensions.SingleQubitUnitary.num_qubits">
Return the number of qubits.
</Attribute>
### params
<Attribute id="qiskit.extensions.SingleQubitUnitary.params">
return instruction params.
</Attribute>
### unit
<Attribute id="qiskit.extensions.SingleQubitUnitary.unit">
Get the time unit of duration.
</Attribute>
</Class>