Observables & Metrics
A PauliString is an metrics helpers read expectations and state fidelities off a simulator. Together they cover the "measure something" half of the library, complementing the gates and channels.
PauliString
A PauliString stores
python
from qliff import PauliString
p = PauliString.parse("-XYZ")Constructors
| Constructor | Description |
|---|---|
PauliString(x, z, phase=0) | from explicit |
PauliString.parse(s) | from a string: "+XYZ", "-Y", "+iXZ", "X_Z" (_ = identity) |
PauliString.identity(n) | the |
PauliString.from_sparse(n, ops, phase=0) | from {qubit: 'X'|'Y'|'Z'}, others identity |
Properties and methods
| Property/Method | Description |
|---|---|
x, z, phase | the 0..3) |
n | number of qubits |
tuple() | (sign, x, z) with sign in {0,1}; raises for non-Hermitian phases |
commutes_with(other) | whether the two Paulis commute |
a * b | Pauli product, tracking the |
python
from qliff import PauliString
x = PauliString.parse("X")
z = PauliString.parse("Z")
(x * z) # -iY
x.commutes_with(z) # False
PauliString.from_sparse(3, {0: "X", 2: "Z"}) # +XIZReading observables
Both live on the Simulator. expectation is a free-function alias for peek. P is a PauliString or a signed string such as "ZZ" or "-X".
| Call | Returns | Description |
|---|---|---|
sim.peek(P) | -1 | 0 | +1 | |
expectation(sim, P) | -1 | 0 | +1 | free-function form of the above |
sim.measure(P, force=None) | (value, random) | measure value in {+1,-1} |
peekreturnsand never collapses. A 0means the state is not an eigenstate ofP.measurecollapses the state, returning the eigenvalue and whether the outcome was a coin flip. It handles multi-qubit stabilizers — the primitive behind syndrome extraction.force=+1/force=-1pins a random outcome, projecting onto a chosen eigenspace.
python
from qliff import Simulator
bell = Simulator(2).H(0).CX(0, 1)
bell.peek("ZZ") # +1
bell.measure("XX") # (1, False)
Simulator(2).measure("XX") # (±1, True)State fidelity
fidelity(a, b) returns the overlap a on a copy of b, so the result is always a power of two.
python
from qliff import Simulator, fidelity
fidelity(Simulator(1), Simulator(1).H(0)) # 0.5
a = Simulator(2).H(0).CX(0, 1)
fidelity(a, a.copy()) # 1.0
fidelity(a, a.copy().Z(0)) # 0.0