Measurement¶
Prepare a state, choose a Pauli observable, and sample its measurement circuit.
Use the library estimators to calculate expectation values and standard errors.
Direct Pauli measurements¶
make_direct_measure_pauli_simpleconstructs basis changes and full-register measurement for a Pauli string, including products such as \(X_0Z_1\).estimate_pauli_observable_expectation_from_bitstringsconverts the measured bitstrings into the relevant parity and combines weighted terms.See the direct measurement notebook for a complete circuit.
Hadamard-test measurements¶
make_hadamard_test_paulimeasures a Pauli expectation through an ancilla.estimate_expectation_from_binary_sampleshandles its binary readout.For a sum of terms, use
estimate_pauli_observable_expectation_from_binary_sampleswith a separate sample collection for each term.See the Hadamard-test notebook.
Expectation values and uncertainty¶
For a binary Pauli measurement, False represents \(+1\) and True represents
\(-1\). The estimator returns the sample mean and its estimated standard error:
from guppyalgos.primitives.measurement import estimate_expectation_from_binary_samples
estimate = estimate_expectation_from_binary_samples({False: 750, True: 250})
print(f"Expectation: {estimate.expectation:.3f}")
print(f"Standard error: {estimate.standard_error:.3f}")
Expectation: 0.500
Standard error: 0.027
For a real observable \(H=\sum_j c_jP_j\), the observable estimators combine independently sampled terms:
Sample each term in its corresponding basis; computational-basis shots alone do not estimate arbitrary X or Y observables.
This uncertainty calculation assumes independent term samples. Grouped measurements require covariance terms.
The Trotter demo uses these routines to plot measured dynamics with error bars.
See all measurement notebooks.