Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK Go to the latest version
Important

IBM Quantum Platform is moving and this version will be sunset on July 1. To get started on the new platform, read the migration guide.

ScalarOp

class ScalarOp(dims, coeff=1)

GitHub

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.


Attributes

atol

The 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

The relative tolerance parameter for float comparisons.


Methods

__call__

ScalarOp.__call__(qargs)

Return a clone with qargs set

__mul__

ScalarOp.__mul__(other)

add

ScalarOp.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

adjoint

ScalarOp.adjoint()

Return the adjoint of the operator.

compose

ScalarOp.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() method.

conjugate

ScalarOp.conjugate()

Return the conjugate of the operator.

copy

ScalarOp.copy()

Make a deep copy of current operator.

dot

ScalarOp.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.

expand

ScalarOp.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

input_dims

ScalarOp.input_dims(qargs=None)

Return tuple of input dimension for specified subsystems.

is_unitary

ScalarOp.is_unitary(atol=None, rtol=None)

Return True if operator is a unitary matrix.

multiply

ScalarOp.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.

output_dims

ScalarOp.output_dims(qargs=None)

Return tuple of output dimension for specified subsystems.

power

ScalarOp.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

Raises

QiskitError – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.

reshape

ScalarOp.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.

set_atol

classmethod ScalarOp.set_atol(value)

Set the class default absolute tolerance parameter for float comparisons.

set_rtol

classmethod ScalarOp.set_rtol(value)

Set the class default relative tolerance parameter for float comparisons.

subtract

ScalarOp.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

tensor

ScalarOp.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

to_matrix

ScalarOp.to_matrix()

Convert to a Numpy matrix.

to_operator

ScalarOp.to_operator()

Convert to an Operator object.

transpose

ScalarOp.transpose()

Return the transpose of the operator.

Was this page helpful?
Report a bug or request content on GitHub.