389 lines
15 KiB
Plaintext
389 lines
15 KiB
Plaintext
---
|
||
title: ScalarOp
|
||
description: API reference for qiskit.quantum_info.ScalarOp
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.quantum_info.ScalarOp
|
||
---
|
||
|
||
<span id="qiskit-quantum-info-scalarop" />
|
||
|
||
# qiskit.quantum\_info.ScalarOp
|
||
|
||
<Class id="qiskit.quantum_info.ScalarOp" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.16/qiskit/quantum_info/operators/scalar_op.py" signature="ScalarOp(dims, coeff=1)" modifiers="class">
|
||
Scalar identity operator class.
|
||
|
||
This is a symbolic representation of an scalar identity operator on multiple subsystems. It may be used to initialize a symbolic scalar multiplication of an identity and then be implicitly converted to other kinds of operator subclasses by using the [`compose()`](#qiskit.quantum_info.ScalarOp.compose "qiskit.quantum_info.ScalarOp.compose"), [`dot()`](#qiskit.quantum_info.ScalarOp.dot "qiskit.quantum_info.ScalarOp.dot"), [`tensor()`](#qiskit.quantum_info.ScalarOp.tensor "qiskit.quantum_info.ScalarOp.tensor"), [`expand()`](#qiskit.quantum_info.ScalarOp.expand "qiskit.quantum_info.ScalarOp.expand") methods.
|
||
|
||
Initialize an operator object.
|
||
|
||
**Parameters**
|
||
|
||
* **dims** (*int or tuple*) – subsystem dimensions.
|
||
* **coeff** (*Number*) – scalar coefficient for the identity operator (Default: 1).
|
||
|
||
**Raises**
|
||
|
||
**QiskitError** – If the optional coefficient is invalid.
|
||
|
||
### \_\_init\_\_
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.__init__" signature="__init__(dims, coeff=1)">
|
||
Initialize an operator object.
|
||
|
||
**Parameters**
|
||
|
||
* **dims** (*int or tuple*) – subsystem dimensions.
|
||
* **coeff** (*Number*) – scalar coefficient for the identity operator (Default: 1).
|
||
|
||
**Raises**
|
||
|
||
**QiskitError** – If the optional coefficient is invalid.
|
||
</Function>
|
||
|
||
## Methods
|
||
|
||
| | |
|
||
| ----------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
||
| [`__init__`](#qiskit.quantum_info.ScalarOp.__init__ "qiskit.quantum_info.ScalarOp.__init__")(dims\[, coeff]) | Initialize an operator object. |
|
||
| [`add`](#qiskit.quantum_info.ScalarOp.add "qiskit.quantum_info.ScalarOp.add")(other) | Return the linear operator self + other. |
|
||
| [`adjoint`](#qiskit.quantum_info.ScalarOp.adjoint "qiskit.quantum_info.ScalarOp.adjoint")() | Return the adjoint of the operator. |
|
||
| [`compose`](#qiskit.quantum_info.ScalarOp.compose "qiskit.quantum_info.ScalarOp.compose")(other\[, qargs, front]) | Return the composed operator. |
|
||
| [`conjugate`](#qiskit.quantum_info.ScalarOp.conjugate "qiskit.quantum_info.ScalarOp.conjugate")() | Return the conjugate of the operator. |
|
||
| [`copy`](#qiskit.quantum_info.ScalarOp.copy "qiskit.quantum_info.ScalarOp.copy")() | Make a deep copy of current operator. |
|
||
| [`dot`](#qiskit.quantum_info.ScalarOp.dot "qiskit.quantum_info.ScalarOp.dot")(other\[, qargs]) | Return the right multiplied operator self \* other. |
|
||
| [`expand`](#qiskit.quantum_info.ScalarOp.expand "qiskit.quantum_info.ScalarOp.expand")(other) | Return the tensor product operator other ⊗ self. |
|
||
| [`input_dims`](#qiskit.quantum_info.ScalarOp.input_dims "qiskit.quantum_info.ScalarOp.input_dims")(\[qargs]) | Return tuple of input dimension for specified subsystems. |
|
||
| [`is_unitary`](#qiskit.quantum_info.ScalarOp.is_unitary "qiskit.quantum_info.ScalarOp.is_unitary")(\[atol, rtol]) | Return True if operator is a unitary matrix. |
|
||
| [`multiply`](#qiskit.quantum_info.ScalarOp.multiply "qiskit.quantum_info.ScalarOp.multiply")(other) | Return the linear operator other \* self. |
|
||
| [`output_dims`](#qiskit.quantum_info.ScalarOp.output_dims "qiskit.quantum_info.ScalarOp.output_dims")(\[qargs]) | Return tuple of output dimension for specified subsystems. |
|
||
| [`power`](#qiskit.quantum_info.ScalarOp.power "qiskit.quantum_info.ScalarOp.power")(n) | Return the power of the ScalarOp. |
|
||
| [`reshape`](#qiskit.quantum_info.ScalarOp.reshape "qiskit.quantum_info.ScalarOp.reshape")(\[input\_dims, output\_dims]) | Return a shallow copy with reshaped input and output subsystem dimensions. |
|
||
| [`set_atol`](#qiskit.quantum_info.ScalarOp.set_atol "qiskit.quantum_info.ScalarOp.set_atol")(value) | Set the class default absolute tolerance parameter for float comparisons. |
|
||
| [`set_rtol`](#qiskit.quantum_info.ScalarOp.set_rtol "qiskit.quantum_info.ScalarOp.set_rtol")(value) | Set the class default relative tolerance parameter for float comparisons. |
|
||
| [`subtract`](#qiskit.quantum_info.ScalarOp.subtract "qiskit.quantum_info.ScalarOp.subtract")(other) | Return the linear operator self - other. |
|
||
| [`tensor`](#qiskit.quantum_info.ScalarOp.tensor "qiskit.quantum_info.ScalarOp.tensor")(other) | Return the tensor product operator self ⊗ other. |
|
||
| [`to_matrix`](#qiskit.quantum_info.ScalarOp.to_matrix "qiskit.quantum_info.ScalarOp.to_matrix")() | Convert to a Numpy matrix. |
|
||
| [`to_operator`](#qiskit.quantum_info.ScalarOp.to_operator "qiskit.quantum_info.ScalarOp.to_operator")() | Convert to an Operator object. |
|
||
| [`transpose`](#qiskit.quantum_info.ScalarOp.transpose "qiskit.quantum_info.ScalarOp.transpose")() | Return the transpose of the operator. |
|
||
|
||
## Attributes
|
||
|
||
| | |
|
||
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
|
||
| [`atol`](#qiskit.quantum_info.ScalarOp.atol "qiskit.quantum_info.ScalarOp.atol") | The default absolute tolerance parameter for float comparisons. |
|
||
| [`coeff`](#qiskit.quantum_info.ScalarOp.coeff "qiskit.quantum_info.ScalarOp.coeff") | Return the coefficient |
|
||
| [`dim`](#qiskit.quantum_info.ScalarOp.dim "qiskit.quantum_info.ScalarOp.dim") | Return tuple (input\_shape, output\_shape). |
|
||
| [`num_qubits`](#qiskit.quantum_info.ScalarOp.num_qubits "qiskit.quantum_info.ScalarOp.num_qubits") | Return the number of qubits if a N-qubit operator or None otherwise. |
|
||
| [`qargs`](#qiskit.quantum_info.ScalarOp.qargs "qiskit.quantum_info.ScalarOp.qargs") | Return the qargs for the operator. |
|
||
| [`rtol`](#qiskit.quantum_info.ScalarOp.rtol "qiskit.quantum_info.ScalarOp.rtol") | The relative tolerance parameter for float comparisons. |
|
||
|
||
### add
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.add" signature="add(other)">
|
||
Return the linear operator self + other.
|
||
|
||
DEPRECATED: use `operator + other` instead.
|
||
|
||
**Parameters**
|
||
|
||
**other** (*BaseOperator*) – an operator object.
|
||
|
||
**Returns**
|
||
|
||
the operator self + other.
|
||
|
||
**Return type**
|
||
|
||
BaseOperator
|
||
</Function>
|
||
|
||
### adjoint
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.adjoint" signature="adjoint()">
|
||
Return the adjoint of the operator.
|
||
</Function>
|
||
|
||
### atol
|
||
|
||
<Attribute id="qiskit.quantum_info.ScalarOp.atol">
|
||
The default absolute tolerance parameter for float comparisons.
|
||
</Attribute>
|
||
|
||
### coeff
|
||
|
||
<Attribute id="qiskit.quantum_info.ScalarOp.coeff">
|
||
Return the coefficient
|
||
</Attribute>
|
||
|
||
### compose
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.compose" signature="compose(other, qargs=None, front=False)">
|
||
Return the composed operator.
|
||
|
||
**Parameters**
|
||
|
||
* **other** (*BaseOperator*) – an operator object.
|
||
* **qargs** (*list or None*) – a list of subsystem positions to apply other on. If None apply on all subsystems \[default: None].
|
||
* **front** (*bool*) – If True compose using right operator multiplication, instead of left multiplication \[default: False].
|
||
|
||
**Returns**
|
||
|
||
The operator self @ other.
|
||
|
||
**Return type**
|
||
|
||
BaseOperator
|
||
|
||
**Raises**
|
||
|
||
**QiskitError** – if other has incompatible dimensions for specified subsystems.
|
||
|
||
**Additional Information:**
|
||
|
||
Composition (`@`) is defined as left matrix multiplication for matrix operators. That is that `A @ B` is equal to `B * A`. Setting `front=True` returns right matrix multiplication `A * B` and is equivalent to the [`dot()`](#qiskit.quantum_info.ScalarOp.dot "qiskit.quantum_info.ScalarOp.dot") method.
|
||
</Function>
|
||
|
||
### conjugate
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.conjugate" signature="conjugate()">
|
||
Return the conjugate of the operator.
|
||
</Function>
|
||
|
||
### copy
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.copy" signature="copy()">
|
||
Make a deep copy of current operator.
|
||
</Function>
|
||
|
||
### dim
|
||
|
||
<Attribute id="qiskit.quantum_info.ScalarOp.dim">
|
||
Return tuple (input\_shape, output\_shape).
|
||
</Attribute>
|
||
|
||
### dot
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.dot" signature="dot(other, qargs=None)">
|
||
Return the right multiplied operator self \* other.
|
||
|
||
**Parameters**
|
||
|
||
* **other** (*BaseOperator*) – an operator object.
|
||
* **qargs** (*list or None*) – a list of subsystem positions to apply other on. If None apply on all subsystems \[default: None].
|
||
|
||
**Returns**
|
||
|
||
The operator self \* other.
|
||
|
||
**Return type**
|
||
|
||
BaseOperator
|
||
|
||
**Raises**
|
||
|
||
**QiskitError** – if other cannot be converted to an operator, or has incompatible dimensions for specified subsystems.
|
||
</Function>
|
||
|
||
### expand
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.expand" signature="expand(other)">
|
||
Return the tensor product operator other ⊗ self.
|
||
|
||
**Parameters**
|
||
|
||
**other** (*BaseOperator*) – an operator object.
|
||
|
||
**Returns**
|
||
|
||
if other is an ScalarOp. BaseOperator: if other is not an ScalarOp.
|
||
|
||
**Return type**
|
||
|
||
[ScalarOp](#qiskit.quantum_info.ScalarOp "qiskit.quantum_info.ScalarOp")
|
||
</Function>
|
||
|
||
### input\_dims
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.input_dims" signature="input_dims(qargs=None)">
|
||
Return tuple of input dimension for specified subsystems.
|
||
</Function>
|
||
|
||
### is\_unitary
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.is_unitary" signature="is_unitary(atol=None, rtol=None)">
|
||
Return True if operator is a unitary matrix.
|
||
</Function>
|
||
|
||
### multiply
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.multiply" signature="multiply(other)">
|
||
Return the linear operator other \* self.
|
||
|
||
DEPRECATED: use `other * operator` instead.
|
||
|
||
**Parameters**
|
||
|
||
**other** (*complex*) – a complex number.
|
||
|
||
**Returns**
|
||
|
||
the linear operator other \* self.
|
||
|
||
**Return type**
|
||
|
||
BaseOperator
|
||
|
||
**Raises**
|
||
|
||
**NotImplementedError** – if subclass does not support multiplication.
|
||
</Function>
|
||
|
||
### num\_qubits
|
||
|
||
<Attribute id="qiskit.quantum_info.ScalarOp.num_qubits">
|
||
Return the number of qubits if a N-qubit operator or None otherwise.
|
||
</Attribute>
|
||
|
||
### output\_dims
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.output_dims" signature="output_dims(qargs=None)">
|
||
Return tuple of output dimension for specified subsystems.
|
||
</Function>
|
||
|
||
### power
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.power" signature="power(n)">
|
||
Return the power of the ScalarOp.
|
||
|
||
**Parameters**
|
||
|
||
**n** (*Number*) – the exponent for the scalar op.
|
||
|
||
**Returns**
|
||
|
||
the `coeff ** n` ScalarOp.
|
||
|
||
**Return type**
|
||
|
||
[ScalarOp](#qiskit.quantum_info.ScalarOp "qiskit.quantum_info.ScalarOp")
|
||
|
||
**Raises**
|
||
|
||
**QiskitError** – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.
|
||
</Function>
|
||
|
||
### qargs
|
||
|
||
<Attribute id="qiskit.quantum_info.ScalarOp.qargs">
|
||
Return the qargs for the operator.
|
||
</Attribute>
|
||
|
||
### reshape
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.reshape" signature="reshape(input_dims=None, output_dims=None)">
|
||
Return a shallow copy with reshaped input and output subsystem dimensions.
|
||
|
||
**Arg:**
|
||
|
||
**input\_dims (None or tuple): new subsystem input dimensions.**
|
||
|
||
If None the original input dims will be preserved \[Default: None].
|
||
|
||
**output\_dims (None or tuple): new subsystem output dimensions.**
|
||
|
||
If None the original output dims will be preserved \[Default: None].
|
||
|
||
**Returns**
|
||
|
||
returns self with reshaped input and output dimensions.
|
||
|
||
**Return type**
|
||
|
||
BaseOperator
|
||
|
||
**Raises**
|
||
|
||
**QiskitError** – if combined size of all subsystem input dimension or subsystem output dimensions is not constant.
|
||
</Function>
|
||
|
||
### rtol
|
||
|
||
<Attribute id="qiskit.quantum_info.ScalarOp.rtol">
|
||
The relative tolerance parameter for float comparisons.
|
||
</Attribute>
|
||
|
||
### set\_atol
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.set_atol" signature="set_atol(value)" modifiers="classmethod">
|
||
Set the class default absolute tolerance parameter for float comparisons.
|
||
|
||
DEPRECATED: use operator.atol = value instead
|
||
</Function>
|
||
|
||
### set\_rtol
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.set_rtol" signature="set_rtol(value)" modifiers="classmethod">
|
||
Set the class default relative tolerance parameter for float comparisons.
|
||
|
||
DEPRECATED: use operator.rtol = value instead
|
||
</Function>
|
||
|
||
### subtract
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.subtract" signature="subtract(other)">
|
||
Return the linear operator self - other.
|
||
|
||
DEPRECATED: use `operator - other` instead.
|
||
|
||
**Parameters**
|
||
|
||
**other** (*BaseOperator*) – an operator object.
|
||
|
||
**Returns**
|
||
|
||
the operator self - other.
|
||
|
||
**Return type**
|
||
|
||
BaseOperator
|
||
</Function>
|
||
|
||
### tensor
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.tensor" signature="tensor(other)">
|
||
Return the tensor product operator self ⊗ other.
|
||
|
||
**Parameters**
|
||
|
||
**other** (*BaseOperator*) – an operator object.
|
||
|
||
**Returns**
|
||
|
||
if other is an ScalarOp. BaseOperator: if other is not an ScalarOp.
|
||
|
||
**Return type**
|
||
|
||
[ScalarOp](#qiskit.quantum_info.ScalarOp "qiskit.quantum_info.ScalarOp")
|
||
</Function>
|
||
|
||
### to\_matrix
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.to_matrix" signature="to_matrix()">
|
||
Convert to a Numpy matrix.
|
||
</Function>
|
||
|
||
### to\_operator
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.to_operator" signature="to_operator()">
|
||
Convert to an Operator object.
|
||
</Function>
|
||
|
||
### transpose
|
||
|
||
<Function id="qiskit.quantum_info.ScalarOp.transpose" signature="transpose()">
|
||
Return the transpose of the operator.
|
||
</Function>
|
||
</Class>
|
||
|