qml.pauli.pauli_word_prefactor

pauli_word_prefactor(observable)[source]

If the operator provided is a valid Pauli word (i.e a single term which may be a tensor product of pauli operators), then this function extracts the prefactor.

Parameters

observable (Operator) – the operator to be examined

Returns

The scaling/phase coefficient of the Pauli word.

Return type

Union[int, float, complex]

Raises

ValueError – If an operator is provided that is not a valid Pauli word.

Example

>>> pauli_word_prefactor(qml.Identity(0))
1
>>> pauli_word_prefactor(qml.X(0) @ qml.Y(1))
1
>>> pauli_word_prefactor(qml.X(0) @ qml.Y(0))
1j