qml.pauli.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.
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.
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 (Union[Observable, Prod, SProd, Sum]) – 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 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.X('a') @ qml.Y('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]])