qml.pauli.pauli_word_to_string

pauli_word_to_string(pauli_word, wire_map=None)[source]

Convert a Pauli word to a string.

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 Pauli operator.

  • A Sum instance with only one term.

Given a Pauli in observable form, convert it into string of characters from ['I', 'X', 'Y', 'Z']. This representation is required for functions such as PauliRot.

Warning

This method ignores any potential coefficient multiplying the Pauli word:

>>> qml.pauli.pauli_word_to_string(3 * qml.X(0) @ qml.Y(1))
'XY'

Warning

This method assumes all Pauli operators are acting on different wires, ignoring any extra operators:

>>> qml.pauli.pauli_word_to_string(qml.X(0) @ qml.Y(0) @ qml.Y(0))
'X'
Parameters:
  • pauli_word (Operator) – an observable, either a single-qubit observable representing a Pauli group element, or a tensor product of single-qubit observables.

  • wire_map (dict[Union[str, int], int]) – dictionary containing all wire labels used in the Pauli word as keys, and unique integer labels as their values

Returns:

The string representation of the observable in terms of 'I', 'X', 'Y', and/or 'Z'.

Return type:

str

Raises:

TypeError – if the input observable is not a proper Pauli word.

Example

>>> wire_map = {'a' : 0, 'b' : 1, 'c' : 2}
>>> pauli_word = qml.X('a') @ qml.Y('c')
>>> pauli_word_to_string(pauli_word, wire_map=wire_map)
'XIY'