Skip to main contentIBM Quantum Documentation
You are viewing the API reference for an old version of Qiskit SDK. Switch to latest version

SparsePauliOp

SparsePauliOp(data, coeffs=None)

GitHub(opens in a new tab)

Sparse N-qubit operator in a Pauli basis representation.

This is a sparse representation of an N-qubit matrix Operator in terms of N-qubit PauliTable and complex coefficients.

It can be used for performing operator arithmetic for hundred of qubits if the number of non-zero Pauli basis terms is sufficiently small.

The Pauli basis components are stored as a PauliTable object and can be accessed using the table attribute. The coefficients are stored as a complex Numpy array vector and can be accessed using the coeffs attribute.

Initialize an operator object.

Parameters

  • data (PauliTable) – Pauli table of terms.
  • coeffs (np.ndarray) – complex coefficients for Pauli terms.

Raises

QiskitError – If the input data or coeffs are invalid.


Attributes

atol

The default absolute tolerance parameter for float comparisons.

coeffs

Return the Pauli coefficients.

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.

size

The number of Pauli of Pauli terms in the operator.

table

Return the the PauliTable.


Methods

__call__

SparsePauliOp.__call__(qargs)

Return a clone with qargs set

__getitem__

SparsePauliOp.__getitem__(key)

Return a view of the SparsePauliOp.

__len__

SparsePauliOp.__len__()

Return the size.

__mul__

SparsePauliOp.__mul__(other)

add

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

SparsePauliOp.adjoint()

Return the adjoint of the operator.

compose

SparsePauliOp.compose(other, qargs=None, front=False)

Return the composition channel self∘other.

Parameters

  • other (SparsePauliOp) – an operator object.
  • qargs (list or None) – a list of subsystem positions to compose other on.
  • front (bool or None) – If False compose in standard order other(self(input)) otherwise compose in reverse order self(other(input)) [default: False]

Returns

The composed operator.

Return type

SparsePauliOp

Raises

  • QiskitError – if other cannot be converted to an Operator or has
  • incompatible dimensions.

conjugate

SparsePauliOp.conjugate()

Return the conjugate of the operator.

copy

SparsePauliOp.copy()

Make a deep copy of current operator.

dot

SparsePauliOp.dot(other, qargs=None)

Return the composition channel self∘other.

Parameters

  • other (SparsePauliOp) – an operator object.
  • qargs (list or None) – a list of subsystem positions to compose other on.

Returns

The composed operator.

Return type

SparsePauliOp

Raises

  • QiskitError – if other cannot be converted to an Operator or has
  • incompatible dimensions.

expand

SparsePauliOp.expand(other)

Return the tensor product operator other ⊗ self.

Parameters

other (SparsePauliOp) – an operator object.

Returns

the tensor product operator other ⊗ self.

Return type

SparsePauliOp

Raises

QiskitError – if other cannot be converted to a SparsePauliOp operator.

from_list

static SparsePauliOp.from_list(obj)

Construct from a list [(pauli_str, coeffs)]

from_operator

static SparsePauliOp.from_operator(obj, atol=None, rtol=None)

Construct from an Operator objector.

Note that the cost of this contruction is exponential as it involves taking inner products with every element of the N-qubit Pauli basis.

Parameters

  • obj (Operator) – an N-qubit operator.
  • atol (float) – Optional. Absolute tolerance for checking if coefficients are zero (Default: 1e-8).
  • rtol (float) – Optinoal. relative tolerance for checking if coefficients are zero (Default: 1e-5).

Returns

the SparsePauliOp representation of the operator.

Return type

SparsePauliOp

Raises

QiskitError – if the input operator is not an N-qubit operator.

input_dims

SparsePauliOp.input_dims(qargs=None)

Return tuple of input dimension for specified subsystems.

is_unitary

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

Return True if operator is a unitary matrix.

Parameters

  • atol (float) – Optional. Absolute tolerance for checking if coefficients are zero (Default: 1e-8).
  • rtol (float) – Optinoal. relative tolerance for checking if coefficients are zero (Default: 1e-5).

Returns

True if the operator is unitary, False otherwise.

Return type

bool

label_iter

SparsePauliOp.label_iter()

Return a label representation iterator.

This is a lazy iterator that converts each term in the SparsePauliOp into a tuple (label, coeff). To convert the entire table to labels use the to_labels() method.

Returns

label iterator object for the PauliTable.

Return type

LabelIterator

matrix_iter

SparsePauliOp.matrix_iter(sparse=False)

Return a matrix representation iterator.

This is a lazy iterator that converts each term in the SparsePauliOp into a matrix as it is used. To convert to a single matrix use the to_matrix() method.

Parameters

sparse (bool) – optionally return sparse CSR matrices if True, otherwise return Numpy array matrices (Default: False)

Returns

matrix iterator object for the PauliTable.

Return type

MatrixIterator

multiply

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

SparsePauliOp.output_dims(qargs=None)

Return tuple of output dimension for specified subsystems.

power

SparsePauliOp.power(n)

Return the compose of a operator with itself n times.

Parameters

n (int) – the number of times to compose with self (n>0).

Returns

the n-times composed operator.

Return type

BaseOperator

Raises

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

reshape

SparsePauliOp.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 SparsePauliOp.set_atol(value)

Set the class default absolute tolerance parameter for float comparisons.

set_rtol

classmethod SparsePauliOp.set_rtol(value)

Set the class default relative tolerance parameter for float comparisons.

simplify

SparsePauliOp.simplify(atol=None, rtol=None)

Simplify PauliTable by combining duplicaties and removing zeros.

Parameters

  • atol (float) – Optional. Absolute tolerance for checking if coefficients are zero (Default: 1e-8).
  • rtol (float) – Optinoal. relative tolerance for checking if coefficients are zero (Default: 1e-5).

Returns

the simplified SparsePauliOp operator.

Return type

SparsePauliOp

subtract

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

SparsePauliOp.tensor(other)

Return the tensor product operator self ⊗ other.

Parameters

other (SparsePauliOp) – a operator subclass object.

Returns

the tensor product operator self ⊗ other.

Return type

SparsePauliOp

Raises

QiskitError – if other cannot be converted to a SparsePauliOp operator.

to_list

SparsePauliOp.to_list(array=False)

Convert to a list Pauli string labels and coefficients.

For operators with a lot of terms converting using the array=True kwarg will be more efficient since it allocates memory for the full Numpy array of labels in advance.

Parameters

array (bool) – return a Numpy array if True, otherwise return a list (Default: False).

Returns

List of pairs (label, coeff) for rows of the PauliTable.

Return type

list or array

to_matrix

SparsePauliOp.to_matrix(sparse=False)

Convert to a dense or sparse matrix.

Parameters

sparse (bool) – if True return a sparse CSR matrix, otherwise return dense Numpy array (Default: False).

Returns

A dense matrix if sparse=False. csr_matrix: A sparse matrix in CSR format if sparse=True.

Return type

array

to_operator

SparsePauliOp.to_operator()

Convert to a matrix Operator object

transpose

SparsePauliOp.transpose()

Return the transpose of the operator.

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