Pauli
A single Pauli term: Pauli letters placed on specific qubits.
The placement is local -- the string names only the qubits the term acts on, so a term fits an
operator of any width and the total num_qubits lives on PauliOperator, not here.
Terms are canonicalized on construction: identity (I) letters are dropped and the
remaining (qubit, letter) pairs are sorted by qubit, so Pauli("XY", (1, 0)) and
Pauli("YX", (0, 1)) compare equal and hash alike, making the term usable as a dict key.
Attributes
attribute__slots__= ('qubits', 'string')attributequbits= tuple(q for q, _ in pairs)The (sorted, distinct) qubit indices the letters act on.
attributestring= ''.join(p for _, p in pairs)The non-identity Pauli letters, ordered to match qubits.
Functions
func__init__(self, string, qubits=None) -> NoneInitialize the Pauli term.
paramselfparamstringstrPauli letters (each one of I, X, Y, Z).
paramqubitsint | Sequence[int] | None= NoneQubit index or indices the letters act on; defaults to range(len(string)).
Returns
Nonefunc__eq__(self, other) -> boolTwo Pauli terms are equal when their letters and qubits match (post-canonicalization).
paramselfparamotherobjectReturns
boolfunc__hash__(self) -> intHash on the canonical (string, qubits) so equal terms share a bucket.
paramselfReturns
intfunc__repr__(self) -> strReturn a string representation such as Pauli('ZZ', (0, 1)).
paramselfReturns
str