# qml.grouping.pauli_group¶

pauli_group(n_qubits, wire_map=None)[source]

Generate the $$n$$-qubit Pauli group.

This function enables the construction of the $$n$$-qubit Pauli group with no storage involved. The $$n$$-qubit Pauli group has size $$4^n$$, thus it may not be desirable to construct it in full and store.

The order of iteration is based on the binary symplectic representation of the Pauli group as $$2n$$-bit strings. Ordering is done by converting the integers $$0$$ to $$2^{2n}$$ to binary strings, and converting those strings to Pauli operators using the binary_to_pauli() method.

Parameters
• n_qubits (int) – The number of qubits for which to create the group.

• 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. If no wire map is provided, wires will be labeled by integers between 0 and n_qubits.

Returns

The next Pauli word in the group.

Return type

Operation

Example

The pauli_group generator can be used to loop over the Pauli group as follows. (Note: in the example below, we display only the first 5 elements for brevity.)

>>> from pennylane.grouping import pauli_group
>>> n_qubits = 3
>>> for p in pauli_group(n_qubits):
...     print(p)
...
Identity(wires=[0])
PauliZ(wires=[2])
PauliZ(wires=[1])
PauliZ(wires=[1]) @ PauliZ(wires=[2])
PauliZ(wires=[0])


The full Pauli group can then be obtained like so:

>>> full_pg = list(pauli_group(n_qubits))


The group can also be created using a custom wire map; if no map is specified, a default map of label $$i$$ to wire i as in the example above will be created. (Note: in the example below, we display only the first 5 elements for brevity.)

>>> wire_map = {'a' : 0, 'b' : 1, 'c' : 2}
>>> for p in pauli_group(n_qubits, wire_map=wire_map):
...     print(p)
...
Identity(wires=['a'])
PauliZ(wires=['c'])
PauliZ(wires=['b'])
PauliZ(wires=['b']) @ PauliZ(wires=['c'])
PauliZ(wires=['a'])


Using PennyLane

Development

API