pprop.pauli.op module¶
This module defines PauliOp, which represents a Pauli word as a pair
of bitmasks encoding X, Y, Z, and I operators across an arbitrary number of qubits.
Bitmask convention¶
Each qubit k is represented by bit k (i.e. 1 << k) in two integers:
|
|
Operator |
|---|---|---|
0 |
0 |
I |
1 |
0 |
X |
0 |
1 |
Z |
1 |
1 |
Y |
- class pprop.pauli.op.PauliOp(x=0, z=0)[source]¶
Bases:
objectA Pauli word represented as two integer bitmasks.
Using bitmasks instead of lists or dicts allows
PauliOpobjects to be hashed cheaply and compared in O(1), which is important because Pauli propagation creates a very large number of them.__slots__is used to minimise per-instance memory overhead.The encoding maps each qubit
kto bitkin two integersxandzaccording to the table below:xzOperator
0
0
I
1
0
X
0
1
Z
1
1
Y
- Parameters:
x (int, optional) – Bitmask encoding the qubits that carry an X or Y factor. Defaults to 0 (all identity).
z (int, optional) – Bitmask encoding the qubits that carry a Z or Y factor. Defaults to 0 (all identity).
Examples
>>> PauliOp(0b101, 0b110) Y0 Z1 X2
>>> PauliOp(0b1001) X0 X3
>>> PauliOp() I
- copy()[source]¶
Return a shallow copy of this
PauliOp.- Returns:
A new instance with identical
xandzbitmasks.- Return type:
- classmethod from_qml(qml_op)[source]¶
Construct a
PauliOpfrom a PennyLane operator.Accepts either a single-qubit PennyLane operator or an iterable of them (e.g. the result of iterating over a tensor product).
- Parameters:
qml_op (pennylane.operation.Operator or Iterable) – A PennyLane X, Y, Z, or Identity operator, or an iterable thereof.
- Returns:
Bitmask representation of the input operator.
- Return type:
Notes
Identity operators are skipped; their bits remain 0, which is the correct encoding for I.
- qubits()[source]¶
Return the set of qubits where this word acts non-trivially (not as I).
- Returns:
Qubit indices where
self[k] != "I".- Return type:
set[int]
- set(qubit, op)[source]¶
Set the Pauli operator on a specific qubit in-place.
Updates the
xandzbitmasks at bit positionqubitto reflect the requested operator according to the bitmask convention.- Parameters:
qubit (int) – Zero-based qubit index to update.
op (str) – Target operator; one of
"I","X","Y", or"Z".
- Raises:
ValueError – If
opis not one of the four valid Pauli operators.- Return type:
None
- to_qml(indices)[source]¶
Convert this
PauliOpto a PennyLane operator on a subset of qubits.Only the qubits listed in
indicesare included; qubits acting as identity are skipped. If all qubits are identity anIdentityon wire 0 is returned as a fallback.- Parameters:
indices (list[int]) – Qubit indices to include in the operator.
- Returns:
Tensor product of single-qubit Pauli operators over
indices.- Return type:
pennylane.operation.Operator
- weight()[source]¶
Return the Pauli weight, i.e. the number of non-identity single-qubit factors.
Computed as the popcount of
x | z: a qubit is non-identity if and only if at least one of itsxorzbits is set.- Returns:
Number of qubits where the operator is X, Y, or Z.
- Return type:
int
- x¶
- z¶
- zerobracket()[source]¶
Return
Trueif this Pauli word has zero expectation in all but the Z/I basis.A Pauli word \(P\) satisfies \(\langle 0 | P | 0 \rangle \neq 0\) if and only if every single-qubit factor is either \(Z\) or \(I\). This is equivalent to checking that no X bit is set (
x == 0).- Return type:
bool