This quantum state tomography tutorial shows how to reconstruct a qubit's density matrix from measurement results, check whether the reconstruction is physically valid, and compare it with a target state using fidelity and trace distance. The workflow is designed for simulators and hardware, with repeatable shot estimates and practical guidance on linear inversion, maximum-likelihood estimation, and classical shadows.
Overview
Quantum state tomography is the process of estimating an unknown quantum state from repeated measurements. Unlike a classical bit, a qubit may be in a superposition, and a single measurement reveals only one outcome from one measurement basis. Tomography therefore repeats state preparation and measures the qubit in several complementary bases.
For a single qubit, the state is represented by a density matrix:
rho = 1/2 (I + rx X + ry Y + rz Z)
Here, rx, ry, and rz are expectation values of the Pauli X, Y, and Z operators. They form the Bloch vector. If the vector has length one, the state is pure; if its length is less than one, the state is mixed. A valid density matrix must also be Hermitian, have trace one, and have no negative eigenvalues.
Tomography is useful for validating state-preparation circuits, comparing a simulator with hardware, checking calibration changes, and measuring how closely an experimental state matches a target. It is not a free diagnostic: the number of required measurement settings and shots grows quickly with the number of qubits.
How to estimate
1. Select an informationally complete set of measurements
For one qubit, measure in the computational Z basis and in bases corresponding to X and Y. A convenient circuit implementation rotates the desired basis into Z immediately before measurement:
- Z measurement: measure directly.
- X measurement: apply a Hadamard gate, then measure Z.
- Y measurement: apply an S-dagger gate followed by a Hadamard gate, then measure Z.
With outcomes encoded as +1 and -1, estimate each expectation value from the counts. For example, if an X-basis experiment produces N_plus plus outcomes and N_minus minus outcomes:
rx = (N_plus - N_minus) / (N_plus + N_minus)
Repeat this calculation for ry and rz, then construct the density matrix. Keep the measurement-basis convention explicit in your code; differences in qubit ordering, bit-string ordering, and the sign convention for Y are common sources of incorrect reconstructions.
2. Reconstruct the density matrix
Linear inversion is the simplest method:
rho_linear = 0.5 * (I + rx*X + ry*Y + rz*Z)
It is fast and transparent, but finite-shot fluctuations can produce a matrix with a small negative eigenvalue. That does not necessarily mean the experiment created an invalid physical state; it usually means that the unconstrained estimate is outside the physical state space because of statistical noise.
Maximum-likelihood estimation addresses this problem by finding the physical density matrix whose predicted measurement probabilities best explain the observed counts. The optimization must enforce Hermiticity, unit trace, and positive semidefiniteness. A common parameterization is rho = T T† / Tr(T T†), where T is a complex triangular matrix. This guarantees a physical result while adding optimization cost and model choices.
3. Validate the reconstruction
Run these checks before interpreting the result:
- Check that
rhois square and Hermitian within numerical tolerance. - Check that
Tr(rho)is approximately one. - Calculate the eigenvalues and verify that they are nonnegative, allowing for small floating-point error.
- Compare predicted measurement probabilities with the observed frequencies.
- Repeat the reconstruction with independent shot batches when uncertainty matters.
For a reconstructed state rho and target state sigma, two useful comparison metrics are:
- Trace distance:
D(rho,sigma) = 1/2 ||rho - sigma||_1. It is zero for identical states and indicates distinguishability. - State fidelity: a common convention is
F(rho,sigma) = [Tr(sqrt(sqrt(rho) sigma sqrt(rho)))]^2. It is one for identical states. Some libraries report the unsquared root fidelity, so record the convention with every result.
Inputs and assumptions
A repeatable tomography calculation should record more than the final matrix. Save the prepared circuit, measurement rotations, qubit and bit ordering, shot count for each basis, simulator or hardware backend, noise model if used, software package versions, and the reconstruction method.
Shot noise sets a practical precision limit. For a Pauli expectation estimated from N shots, a simple standard-error estimate is:
standard_error = sqrt((1 - expectation**2) / N)
Using the conservative worst case, the standard error is no larger than approximately 1/sqrt(N). This is a planning estimate, not a confidence interval for the complete density matrix. If you want an expectation-value standard error near 0.01 in the worst case, the rough starting point is 10,000 shots for that basis. Increase the budget if you need reliable eigenvalues, small infidelities, or comparisons between nearly identical states.
For multiple qubits, full Pauli tomography requires many observables. Measuring every local X, Y, and Z combination involves up to 3^n basis settings for n qubits, while a complete Pauli-operator description contains 4^n - 1 nonidentity terms. The exact workload depends on the measurement design and whether observables can be grouped into compatible settings. Read the related guide on Pauli grouping for quantum measurements when the goal is expectation estimation rather than a complete density matrix.
| Method | Strength | Limitation | Best use |
|---|---|---|---|
| Linear inversion | Simple, fast, and easy to audit | Can produce nonphysical matrices | Initial analysis and simulator checks |
| Maximum likelihood | Returns a physical density matrix | Requires an optimizer and can be slower | Hardware results and reported states |
| Classical shadows | Can estimate many properties from randomized measurements | Estimator variance depends on the observable and target task; it is not always the best full-matrix method | Property estimation and larger systems |
Worked examples
Single-qubit |+⟩ state
Prepare |+⟩ by applying H to |0⟩. Ideally, X measurements always return the +1 eigenvalue, while Y and Z outcomes are balanced. With finite shots, suppose the measured expectation values are:
rx = 0.98
ry = 0.03
rz = -0.02
The linear reconstruction is approximately:
rho = [[0.49, 0.49 - 0.015i],
[0.49 + 0.015i, 0.51]]
The Bloch-vector length is close to one, so this result is consistent with a nearly pure state. Before reporting it, calculate the eigenvalues. If one is slightly negative, compare the linear estimate with a maximum-likelihood reconstruction rather than silently clipping the eigenvalue.
Comparing a hardware result with a target
Suppose the target is the ideal |+⟩ state and the hardware reconstruction is rho_hw. Compute fidelity and trace distance against the target density matrix. Then repeat the experiment with the same shot budget on a noise-aware simulator. This separates three effects: sampling variation, the modeled noise, and hardware-specific behavior.
For a fair comparison, use identical basis rotations, shot allocation, qubit mapping where relevant, and post-processing. Report uncertainty by rerunning independent batches or by resampling counts. A single fidelity value without its shot budget and reconstruction method is difficult to interpret.
Framework implementation notes
In Qiskit, Cirq, PennyLane, or another SDK, the durable workflow is more important than a particular tomography helper API: create one circuit per measurement basis, execute each circuit with a recorded shot count, convert counts into expectation values, reconstruct the matrix, and validate it. Estimator and tomography interfaces can change between package releases, so pin versions for experiments and verify whether an API returns expectation values, quasi-probabilities, or raw counts. Use the same discipline when moving from a simulator to a cloud device; measurement mitigation and provider-specific result formats can change the numerical interpretation.
When to recalculate
Recalculate the tomography whenever the prepared circuit, device, measurement calibration, shot budget, noise model, or software stack changes. A useful maintenance cycle is to rerun a small reference state such as |0⟩, |1⟩, or |+⟩ before a larger experiment. This catches basis-rotation errors and qubit-ordering mistakes early.
Update the workflow after major SDK releases or backend changes, and record the tested package versions beside saved results. Revisit shot allocation when the decision threshold changes: distinguishing a visibly mixed state requires less precision than demonstrating a small improvement in fidelity. For multi-qubit work, reconsider full tomography when the system grows; classical shadows, targeted Pauli measurements, or reduced-state tomography may answer the scientific question with fewer settings.
For a practical checklist, prepare the state, measure X/Y/Z or the selected multi-qubit basis set, save raw counts, estimate observables, reconstruct with linear inversion, apply a physical estimator when needed, check eigenvalues and trace, calculate fidelity and trace distance, and repeat under the comparison condition. Keeping those inputs fixed makes each new tomography run comparable rather than merely producing another isolated density matrix.