qml.grouping.pauli_word_to_matrix

pauli_word_to_matrix(pauli_word, wire_map=None)[source]

Convert a Pauli word from a tensor to its matrix representation.

The matrix representation of a Pauli word has dimension \(2^n \times 2^n\), where \(n\) is the number of qubits provided in wire_map. For wires that the Pauli word does not act on, identities must be inserted into the tensor product at the correct positions.

Parameters
  • pauli_word (Observable) – an observable, either a Tensor instance or single-qubit observable representing a Pauli group element.

  • 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 matrix representation of the multi-qubit Pauli over the specified wire map.

Return type

array[complex]

Raises

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

Example

>>> wire_map = {'a' : 0, 'b' : 1}
>>> pauli_word = qml.PauliX('a') @ qml.PauliY('b')
>>> pauli_word_to_matrix(pauli_word, wire_map=wire_map)
array([[0.+0.j, 0.-0.j, 0.+0.j, 0.-1.j],
       [0.+0.j, 0.+0.j, 0.+1.j, 0.+0.j],
       [0.+0.j, 0.-1.j, 0.+0.j, 0.-0.j],
       [0.+1.j, 0.+0.j, 0.+0.j, 0.+0.j]])