qml.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
Tensor
instance containing Pauli operators.A
Prod
instance containing Pauli operators.A
SProd
instance containing a valid Pauli word.A
Hamiltonian
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(qml.Identity(0)) True >>> is_pauli_word(qml.X(0) @ qml.Z(2)) True >>> is_pauli_word(qml.Z(0) @ qml.Hadamard(1)) False >>> is_pauli_word(4 * qml.X(0) @ qml.Z(0)) True