Pauli
class qiskit.quantum_info.Pauli(data=None, x=None, *, z=None, label=None)
Bases: BasePauli
N-qubit Pauli operator.
This class represents an operator from the full -qubit Pauli group
where and are single-qubit Pauli matrices:
Initialization
A Pauli object can be initialized in several ways:
Pauli(obj)
where
obj
is a Pauli string,Pauli
orScalarOp
operator, or a Pauli gate orQuantumCircuit
containing only Pauli gates.
Pauli((z, x, phase))
where
z
andx
are booleannumpy.ndarrays
andphase
is an integer in[0, 1, 2, 3]
.
Pauli((z, x))
equivalent to
Pauli((z, x, 0))
with trivial phase.
String representation
An -qubit Pauli may be represented by a string consisting of characters from ['I', 'X', 'Y', 'Z']
, and optionally phase coefficient in . For example: XYZ
or '-iZIZ'
.
In the string representation qubit-0 corresponds to the right-most Pauli character, and qubit- to the left-most Pauli character. For example 'XYZ'
represents with 'Z'
on qubit-0, 'Y'
on qubit-1, and 'X'
on qubit-3.
The string representation can be converted to a Pauli
using the class initialization (Pauli('-iXYZ')
). A Pauli
object can be converted back to the string representation using the to_label()
method or str(pauli)
.
Using str
to convert a Pauli
to a string will truncate the returned string for large numbers of qubits while to_label()
will return the full string with no truncation. The default truncation length is 50 characters. The default value can be changed by setting the class __truncate__ attribute to an integer value. If set to 0
no truncation will be performed.
Array Representation
The internal data structure of an -qubit Pauli is two length- boolean vectors , , and an integer defining the Pauli operator
The and arrays
where z[k] = P.z[k]
, x[k] = P.x[k]
respectively.
The and arrays can be accessed and updated using the z
and x
properties respectively. The phase integer can be accessed and updated using the phase
property.
Matrix Operator Representation
Pauli’s can be converted to Operator
using the to_operator()
method, or to a dense or sparse complex matrix using the to_matrix()
method.
Data Access
The individual qubit Paulis can be accessed and updated using the []
operator which accepts integer, lists, or slices for selecting subsets of Paulis. Note that selecting subsets of Pauli’s will discard the phase of the current Pauli.
For example
p = Pauli('-iXYZ')
print('P[0] =', repr(P[0]))
print('P[1] =', repr(P[1]))
print('P[2] =', repr(P[2]))
print('P[:] =', repr(P[:]))
print('P[::-1] =, repr(P[::-1]))
Initialize the Pauli.
When using the symplectic array input data both z and x arguments must be provided, however the first (z) argument can be used alone for string label, Pauli operator, or ScalarOp input data.
Parameters
data (str ortuple orPauli orScalarOp) – input data for Pauli. If input is a tuple it must be of the form (z, x)
or (z, x, phase)`` where z
and x
are boolean Numpy arrays, and phase is an integer from Z_4. If input is a string, it must be a concatenation of a phase and a Pauli string (e.g. ‘XYZ’, ‘-iZIZ’) where a phase string is a combination of at most three characters from [‘+’, ‘-’, ‘’], [‘1’, ‘’], and [‘i’, ‘j’, ‘’] in this order, e.g. ‘’, ‘-1j’ while a Pauli string is 1 or more characters of ‘I’, ‘X’, ‘Y’ or ‘Z’, e.g. ‘Z’, ‘XIYY’.
Raises
QiskitError – if input array is invalid shape.
Attributes
dim
Return tuple (input_shape, output_shape).
name
Unique string identifier for operation type.
num_clbits
Number of classical bits.
num_qubits
Return the number of qubits if a N-qubit operator or None otherwise.
phase
Return the group phase exponent for the Pauli.
qargs
Return the qargs for the operator.
settings
Return settings.
x
The x vector for the Pauli.
z
The z vector for the Pauli.
Methods
adjoint
adjoint()
Return the adjoint of the Operator.
anticommutes
anticommutes(other, qargs=None)
Return True if other Pauli anticommutes with self.
Parameters
- other (Pauli) – another Pauli operator.
- qargs (list) – qubits to apply dot product on (default: None).
Returns
True if Pauli’s anticommute, False if they commute.
Return type
commutes
commutes(other, qargs=None)
Return True if the Pauli commutes with other.
Parameters
- other (Pauli orPauliList) – another Pauli operator.
- qargs (list) – qubits to apply dot product on (default: None).
Returns
True if Pauli’s commute, False if they anti-commute.
Return type
compose
compose(other, qargs=None, front=False, inplace=False)
Return the operator composition with another Pauli.
Parameters
- other (Pauli) – a Pauli object.
- qargs (list or None) – Optional, qubits to apply dot product on (default: None).
- front (bool) – If True compose using right operator multiplication, instead of left multiplication [default: False].
- inplace (bool) – If True update in-place (default: False).
Returns
The composed Pauli.
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 each Pauli in the list.
copy
copy()
Make a deep copy of current operator.
delete
delete(qubits)
Return a Pauli with qubits deleted.
Parameters
qubits (int orlist) – qubits to delete from Pauli.
Returns
the resulting Pauli with the specified qubits removed.
Return type
Raises
QiskitError – if ind is out of bounds for the array size or number of qubits.
dot
dot(other, qargs=None, inplace=False)
Return the right multiplied operator self * other.
Parameters
- other (Pauli) – an operator object.
- qargs (list or None) – Optional, qubits to apply dot product on (default: None).
- inplace (bool) – If True update in-place (default: False).
Returns
The operator self * other.
Return type
equiv
equiv(other)
Return True if Pauli’s are equivalent up to group phase.
Parameters
other (Pauli) – an operator object.
Returns
True if the Pauli’s are equivalent up to group phase.
Return type
evolve
evolve(other, qargs=None, frame='h')
Performs either Heisenberg (default) or Schrödinger picture evolution of the Pauli by a Clifford and returns the evolved Pauli.
Schrödinger picture evolution can be chosen by passing parameter frame='s'
. This option yields a faster calculation.
Heisenberg picture evolves the Pauli as .
Schrödinger picture evolves the Pauli as .
Parameters
- other (Pauli orClifford orQuantumCircuit) – The Clifford operator to evolve by.
- qargs (list) – a list of qubits to apply the Clifford to.
- frame (string) –
'h'
for Heisenberg (default) or's'
for - framework. (Schrödinger) –
Returns
the Pauli (Heisenberg picture) or the Pauli (Schrödinger picture).
Return type
Raises
QiskitError – if the Clifford number of qubits and qargs don’t match.
expand
expand(other)
Return the reverse-order tensor product with another Pauli.
Parameters
other (Pauli) – a Pauli object.
Returns
the tensor product , where
is the current Pauli, and is the other Pauli.
Return type
input_dims
input_dims(qargs=None)
Return tuple of input dimension for specified subsystems.
insert
insert(qubits, value)
Insert a Pauli at specific qubit value.
Parameters
Returns
the resulting Pauli with the entries inserted.
Return type
Raises
QiskitError – if the insertion qubits are invalid.
inverse
inverse()
Return the inverse of the Pauli.
output_dims
output_dims(qargs=None)
Return tuple of output dimension for specified subsystems.
power
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
Raises
QiskitError – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.
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.
set_truncation
classmethod set_truncation(val)
Set the max number of Pauli characters to display before truncation/
Parameters
val (int) – the number of characters.
Truncation will be disabled if the truncation value is set to 0.
tensor
tensor(other)
Return the tensor product with another Pauli.
Parameters
other (Pauli) – a Pauli object.
Returns
the tensor product , where
is the current Pauli, and is the other Pauli.
Return type
The tensor product can be obtained using the ^
binary operator. Hence a.tensor(b)
is equivalent to a ^ b
.
to_instruction
to_instruction()
Convert to Pauli circuit instruction.
to_label
to_label()
Convert a Pauli to a string label.
The difference between to_label and __str__()
is that the later will truncate the output for large numbers of qubits.
Returns
the Pauli string label.
Return type
to_matrix
to_matrix(sparse=False)
Convert to a Numpy array or sparse CSR matrix.
Parameters
sparse (bool) – if True return sparse CSR matrices, otherwise return dense Numpy arrays (default: False).
Returns
The Pauli matrix.
Return type
array
transpose
transpose()
Return the transpose of each Pauli in the list.