Tamil
மொழிகள்
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

SparsePauliOp

class SparsePauliOp(data, coeffs=None, *, ignore_pauli_phase=False, copy=True)[source]

Bases: LinearOp

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 PauliList 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 PauliList object and can be accessed using the paulis attribute. The coefficients are stored as a complex Numpy array vector and can be accessed using the coeffs attribute.

Data type of coefficients

The default dtype of the internal coeffs Numpy array is complex128. Users can configure this by passing np.ndarray with a different dtype. For example, a parameterized SparsePauliOp can be made as follows:

>>> import numpy as np
>>> from qiskit.circuit import ParameterVector
>>> from qiskit.quantum_info import SparsePauliOp

>>> SparsePauliOp(["II", "XZ"], np.array(ParameterVector("a", 2)))
SparsePauliOp(['II', 'XZ'],
      coeffs=[ParameterExpression(1.0*a[0]), ParameterExpression(1.0*a[1])])

Note

Parameterized SparsePauliOp does not support the following methods:

  • to_matrix(sparse=True) since scipy.sparse cannot have objects as elements.

  • to_operator() since Operator does not support objects.

  • sort, argsort since ParameterExpression does not support comparison.

  • equiv since ParameterExpression cannot be converted into complex.

  • chop since ParameterExpression does not support absolute value.

Initialize an operator object.

Parameters
  • data (PauliList or SparsePauliOp or Pauli or list or str) -- Pauli list of terms. A list of Pauli strings or a Pauli string is also allowed.

  • coeffs (np.ndarray) --

    complex coefficients for Pauli terms.

    Note

    If data is a SparsePauliOp and coeffs is not None, the value of the SparsePauliOp.coeffs will be ignored, and only the passed keyword argument coeffs will be used.

  • ignore_pauli_phase (bool) -- if true, any phase component of a given PauliList will be assumed to be zero. This is more efficient in cases where a PauliList has been constructed purely for this object, and it is already known that the phases in the ZX-convention are zero. It only makes sense to pass this option when giving PauliList data. (Default: False)

  • copy (bool) -- copy the input data if True, otherwise assign it directly, if possible. (Default: True)

Raises

QiskitError -- If the input data or coeffs are invalid.

Methods

adjoint

Return the adjoint of the Operator.

argsort

Return indices for sorting the rows of the table.

assign_parameters

Bind the free Parameters in the coefficients to provided values.

chop

Set real and imaginary parts of the coefficients to 0 if < tol in magnitude.

compose

Return the operator composition with another SparsePauliOp.

conjugate

Return the conjugate of the SparsePauliOp.

copy

Make a deep copy of current operator.

dot

Return the right multiplied operator self * other.

equiv

Check if two SparsePauliOp operators are equivalent.

expand

Return the reverse-order tensor product with another SparsePauliOp.

from_list

Construct from a list of Pauli strings and coefficients.

from_operator

Construct from an Operator objector.

from_sparse_list

Construct from a list of local Pauli strings and coefficients.

group_commuting

Partition a SparsePauliOp into sets of commuting Pauli strings.

input_dims

Return tuple of input dimension for specified subsystems.

is_unitary

Return True if operator is a unitary matrix.

label_iter

Return a label representation iterator.

matrix_iter

Return a matrix representation iterator.

output_dims

Return tuple of output dimension for specified subsystems.

power

Return the compose of a operator with itself n times.

reshape

Return a shallow copy with reshaped input and output subsystem dimensions.

simplify

Simplify PauliList by combining duplicates and removing zeros.

sort

Sort the rows of the table.

sum

Sum of SparsePauliOps.

tensor

Return the tensor product with another SparsePauliOp.

to_list

Convert to a list Pauli string labels and coefficients.

to_matrix

Convert to a dense or sparse matrix.

to_operator

Convert to a matrix Operator object

transpose

Return the transpose of the SparsePauliOp.

Attributes

atol = 1e-08
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.

parameters

Return the free Parameters in the coefficients.

paulis

Return the the PauliList.

qargs

Return the qargs for the operator.

rtol = 1e-05
settings

Return settings.

size

The number of Pauli of Pauli terms in the operator.