qp.pauli.is_pauli_word

is_pauli_word(observable)[source]

Checks if an observable instance consists only of Pauli and Identity Operators.

A Pauli word can be either:

  • A single pauli operator (see PauliX for an example).

  • A Prod instance containing Pauli operators.

  • A SProd instance containing a valid Pauli word.

  • A Sum instance with only one term.

Warning

This function will only confirm that all operators are Pauli or Identity operators, and not whether the observable is mathematically a Pauli word. If an Observable consists of multiple Pauli operators targeting the same wire, the function will return True regardless of any complex coefficients.

Parameters:

observable (Operator) – the operator to be examined

Returns:

true if the input observable is a Pauli word, false otherwise.

Return type:

bool

Example

>>> is_pauli_word(qp.Identity(0))
True
>>> is_pauli_word(qp.X(0) @ qp.Z(2))
True
>>> is_pauli_word(qp.Z(0) @ qp.Hadamard(1))
False
>>> is_pauli_word(4 * qp.X(0) @ qp.Z(0))
True