qiskit.quantum_info.SparsePauliOp¶
-
class
SparsePauliOp
(data, coeffs=None)[소스]¶ Sparse N-qubit operator in a Pauli basis representation.
This is a sparse representation of an N-qubit matrix
Operator
in terms of N-qubitPauliTable
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 thetable
attribute. The coefficients are stored as a complex Numpy array vector and can be accessed using thecoeffs
attribute.Initialize an operator object.
- 매개변수
data (PauliTable) – Pauli table of terms.
coeffs (np.ndarray) – complex coefficients for Pauli terms.
- 예외
QiskitError – If the input data or coeffs are invalid.
-
__init__
(data, coeffs=None)[소스]¶ Initialize an operator object.
- 매개변수
data (PauliTable) – Pauli table of terms.
coeffs (np.ndarray) – complex coefficients for Pauli terms.
- 예외
QiskitError – If the input data or coeffs are invalid.
Methods
__init__
(data[, coeffs])Initialize an operator object.
add
(other)Return the linear operator self + other.
adjoint
()Return the adjoint of the operator.
compose
(other[, qargs, front])Return the composition channel self∘other.
Return the conjugate of the operator.
copy
()Make a deep copy of current operator.
dot
(other[, qargs])Return the composition channel self∘other.
expand
(other)Return the tensor product operator other ⊗ self.
from_list
(obj)Construct from a list [(pauli_str, coeffs)]
from_operator
(obj[, atol, rtol])Construct from an Operator objector.
input_dims
([qargs])Return tuple of input dimension for specified subsystems.
is_unitary
([atol, rtol])Return True if operator is a unitary matrix.
Return a label representation iterator.
matrix_iter
([sparse])Return a matrix representation iterator.
multiply
(other)Return the linear operator other * self.
output_dims
([qargs])Return tuple of output dimension for specified subsystems.
power
(n)Return the compose of a operator with itself n times.
reshape
([input_dims, output_dims])Return a shallow copy with reshaped input and output subsystem dimensions.
set_atol
(value)Set the class default absolute tolerance parameter for float comparisons.
set_rtol
(value)Set the class default relative tolerance parameter for float comparisons.
simplify
([atol, rtol])Simplify PauliTable by combining duplicaties and removing zeros.
subtract
(other)Return the linear operator self - other.
tensor
(other)Return the tensor product operator self ⊗ other.
to_list
([array])Convert to a list Pauli string labels and coefficients.
to_matrix
([sparse])Convert to a dense or sparse matrix.
Convert to a matrix Operator object
Return the transpose of the operator.
Attributes
The default absolute tolerance parameter for float comparisons.
Return the Pauli coefficients.
Return tuple (input_shape, output_shape).
Return the number of qubits if a N-qubit operator or None otherwise.
Return the qargs for the operator.
The relative tolerance parameter for float comparisons.
The number of Pauli of Pauli terms in the operator.
Return the the PauliTable.
-
add
(other)¶ Return the linear operator self + other.
DEPRECATED: use
operator + other
instead.- 매개변수
other (BaseOperator) – an operator object.
- 반환값
the operator self + other.
- 반환 형식
BaseOperator
-
property
atol
¶ The default absolute tolerance parameter for float comparisons.
-
property
coeffs
¶ Return the Pauli coefficients.
-
compose
(other, qargs=None, front=False)[소스]¶ Return the composition channel self∘other.
- 매개변수
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]
- 반환값
The composed operator.
- 반환 형식
- 예외
QiskitError – if other cannot be converted to an Operator or has
incompatible dimensions. –
-
copy
()¶ Make a deep copy of current operator.
-
property
dim
¶ Return tuple (input_shape, output_shape).
-
dot
(other, qargs=None)[소스]¶ Return the composition channel self∘other.
- 매개변수
other (SparsePauliOp) – an operator object.
qargs (list or None) – a list of subsystem positions to compose other on.
- 반환값
The composed operator.
- 반환 형식
- 예외
QiskitError – if other cannot be converted to an Operator or has
incompatible dimensions. –
-
expand
(other)[소스]¶ Return the tensor product operator other ⊗ self.
- 매개변수
other (SparsePauliOp) – an operator object.
- 반환값
the tensor product operator other ⊗ self.
- 반환 형식
- 예외
QiskitError – if other cannot be converted to a SparsePauliOp operator.
-
static
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.
- 매개변수
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).
- 반환값
the SparsePauliOp representation of the operator.
- 반환 형식
- 예외
QiskitError – if the input operator is not an N-qubit operator.
-
input_dims
(qargs=None)¶ Return tuple of input dimension for specified subsystems.
-
is_unitary
(atol=None, rtol=None)[소스]¶ Return True if operator is a unitary matrix.
- 매개변수
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).
- 반환값
True if the operator is unitary, False otherwise.
- 반환 형식
bool
-
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.- 반환값
label iterator object for the PauliTable.
- 반환 형식
LabelIterator
-
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.- 매개변수
sparse (bool) – optionally return sparse CSR matrices if True, otherwise return Numpy array matrices (Default: False)
- 반환값
matrix iterator object for the PauliTable.
- 반환 형식
MatrixIterator
-
multiply
(other)¶ Return the linear operator other * self.
DEPRECATED: use
other * operator
instead.- 매개변수
other (complex) – a complex number.
- 반환값
the linear operator other * self.
- 반환 형식
BaseOperator
- 예외
NotImplementedError – if subclass does not support multiplication.
-
property
num_qubits
¶ Return the number of qubits if a N-qubit operator or None otherwise.
-
output_dims
(qargs=None)¶ Return tuple of output dimension for specified subsystems.
-
power
(n)¶ Return the compose of a operator with itself n times.
- 매개변수
n (int) – the number of times to compose with self (n>0).
- 반환값
the n-times composed operator.
- 반환 형식
BaseOperator
- 예외
QiskitError – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.
-
property
qargs
¶ Return the qargs for the operator.
-
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 self with reshaped input and output dimensions.
- 반환 형식
BaseOperator
- 예외
QiskitError – if combined size of all subsystem input dimension or subsystem output dimensions is not constant.
-
property
rtol
¶ The relative tolerance parameter for float comparisons.
-
classmethod
set_atol
(value)¶ Set the class default absolute tolerance parameter for float comparisons.
DEPRECATED: use operator.atol = value instead
-
classmethod
set_rtol
(value)¶ Set the class default relative tolerance parameter for float comparisons.
DEPRECATED: use operator.rtol = value instead
-
simplify
(atol=None, rtol=None)[소스]¶ Simplify PauliTable by combining duplicaties and removing zeros.
- 매개변수
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).
- 반환값
the simplified SparsePauliOp operator.
- 반환 형식
-
property
size
¶ The number of Pauli of Pauli terms in the operator.
-
subtract
(other)¶ Return the linear operator self - other.
DEPRECATED: use
operator - other
instead.- 매개변수
other (BaseOperator) – an operator object.
- 반환값
the operator self - other.
- 반환 형식
BaseOperator
-
property
table
¶ Return the the PauliTable.
-
tensor
(other)[소스]¶ Return the tensor product operator self ⊗ other.
- 매개변수
other (SparsePauliOp) – a operator subclass object.
- 반환값
the tensor product operator self ⊗ other.
- 반환 형식
- 예외
QiskitError – if other cannot be converted to a SparsePauliOp operator.
-
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.- 매개변수
array (bool) – return a Numpy array if True, otherwise return a list (Default: False).
- 반환값
List of pairs (label, coeff) for rows of the PauliTable.
- 반환 형식
list or array