qiskit.quantum_info.ScalarOp
class ScalarOp(dims=None, coeff=1)
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()
, dot()
, tensor()
, 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__
__init__(dims=None, 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.
Methods
__init__ ([dims, coeff]) | Initialize an operator object. |
adjoint () | Return the adjoint of the Operator. |
compose (other[, qargs, front]) | Return the operator composition with another ScalarOp. |
conjugate () | Return the conjugate of the ScalarOp. |
copy () | Make a deep copy of current operator. |
dot (other[, qargs]) | Return the right multiplied operator self * other. |
expand (other) | Return the reverse-order tensor product with another ScalarOp. |
input_dims ([qargs]) | Return tuple of input dimension for specified subsystems. |
is_unitary ([atol, rtol]) | Return True if operator is a unitary matrix. |
output_dims ([qargs]) | Return tuple of output dimension for specified subsystems. |
power (n) | Return the power of the ScalarOp. |
reshape ([input_dims, output_dims, num_qubits]) | Return a shallow copy with reshaped input and output subsystem dimensions. |
tensor (other) | Return the tensor product with another ScalarOp. |
to_matrix () | Convert to a Numpy matrix. |
to_operator () | Convert to an Operator object. |
transpose () | Return the transpose of the ScalarOp. |
Attributes
atol | Default absolute tolerance parameter for float comparisons. |
coeff | Return the coefficient |
dim | Return tuple (input_shape, output_shape). |
num_qubits | Return the number of qubits if a N-qubit operator or None otherwise. |
qargs | Return the qargs for the operator. |
rtol | Default relative tolerance parameter for float comparisons. |
adjoint
adjoint()
Return the adjoint of the Operator.
atol
Default absolute tolerance parameter for float comparisons.
coeff
Return the coefficient
compose
compose(other, qargs=None, front=False)
Return the operator composition with another ScalarOp.
Parameters
- other (ScalarOp) – a ScalarOp object.
- qargs (list or None) – Optional, 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 composed ScalarOp.
Return type
Raises
QiskitError – if other cannot be converted to an operator, or has incompatible dimensions for specified subsystems.
Composition (&
) by default is defined as left matrix multiplication for matrix operators, while dot()
is defined as right matrix multiplication. That is that A & B == A.compose(B)
is equivalent to B.dot(A)
when A
and B
are of the same type.
Setting the front=True
kwarg changes this to right matrix multiplication and is equivalent to the dot()
method A.dot(B) == A.compose(B, front=True)
.
conjugate
conjugate()
Return the conjugate of the ScalarOp.
copy
copy()
Make a deep copy of current operator.
dim
Return tuple (input_shape, output_shape).
dot
dot(other, qargs=None)
Return the right multiplied operator self * other.
Parameters
- other (Operator) – an operator object.
- qargs (list or None) – Optional, a list of subsystem positions to apply other on. If None apply on all subsystems (default: None).
Returns
The right matrix multiplied Operator.
Return type
expand
expand(other)
Return the reverse-order tensor product with another ScalarOp.
Parameters
other (ScalarOp) – a ScalarOp object.
Returns
the tensor product , where
is the current ScalarOp, and is the other ScalarOp.
Return type
input_dims
input_dims(qargs=None)
Return tuple of input dimension for specified subsystems.
is_unitary
is_unitary(atol=None, rtol=None)
Return True if operator is a unitary matrix.
num_qubits
Return the number of qubits if a N-qubit operator or None otherwise.
output_dims
output_dims(qargs=None)
Return tuple of output dimension for specified subsystems.
power
power(n)
Return the power of the ScalarOp.
Parameters
n (float) – the exponent for the scalar op.
Returns
the coeff ** n
ScalarOp.
Return type
qargs
Return the qargs for the operator.
reshape
reshape(input_dims=None, output_dims=None, num_qubits=None)
Return a shallow copy with reshaped input and output subsystem dimensions.
Parameters
- 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].
- num_qubits (None or int) – reshape to an N-qubit operator [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.
rtol
Default relative tolerance parameter for float comparisons.
tensor
tensor(other)
Return the tensor product with another ScalarOp.
Parameters
other (ScalarOp) – a ScalarOp object.
Returns
the tensor product , where
is the current ScalarOp, and is the other ScalarOp.
Return type
The tensor product can be obtained using the ^
binary operator. Hence a.tensor(b)
is equivalent to a ^ b
.
to_matrix
to_matrix()
Convert to a Numpy matrix.
to_operator
to_operator()
Convert to an Operator object.
transpose
transpose()
Return the transpose of the ScalarOp.