Documentation Index
Fetch the complete documentation index at: https://prod-mint.classiq.io/llms.txt
Use this file to discover all available pages before exploring further.
View on GitHub
Open this notebook in GitHub to run it yourself
Overview
Classical shadow tomography [1], introduced by Huang, Kueng, and Preskill (2020), is a measurement protocol for predicting many properties of an unknown quantum state from a small number of measurements. Rather than reconstructing the full density matrix, it builds a compact classical estimator, the classical shadow, that supports efficient prediction of a large set of observables. The algorithm treats the following problem:Complexity: The sample cost, which is the number of required measurements (or copies of ), scales as . This scaling is logarithmic in the number of target observables, . Here is the shadow norm which depends on both the specific method used to construct the classical shadow and the observables of interest, . When Pauli measurements are utilized to build the classical shadow it scales as , for -local Pauli observables, while, when the algorithm involves random-Clifford measurements, the classical shadow scales as the Hilbert-Schmidt norm . In comparison, the naive approach of measuring each time a different observable, would require (using Hoeffding inequality) measurements.
- Input: Access to copies of an unknown -qubit state , and a target set of observables .
- Output: Estimates for every , to additive error , with a probability of at least .
Keywords: Quantum state tomography, Randomized measurements, Shadow norm, Median-of-means estimator.
Introduction
Predicting properties of unknown quantum states is an essential task in quantum computing. By conducting many measurements in different bases on copies of the state a method called Quantum State Tomography [1] fully reconstructs the quantum state. Naturally, such complete characterization requires a number of state copies which scales exponentially, with the number of qubits and quadratically with the error, . As a result, this procedure is unfeasible for a system of more than a few qubits. Nevertheless, for many applications a complete characterization of the state, or equivalently, evaluation of the expectation value of an exponential number of observables is unnecessary. When restricting to observables, one can characterize only a part of the Hilbert space and achieve better complexity. Aaronson introduced shadow tomography [2] which constructs a compact classical representation of the quantum state, coined as classical shadow. The shadow allows predicting observables simultaneously without completely reconstructing the state. This could be done using copies of the state. However, this approach still requires a lot of quantum memory to store the copies and long circuits to make the predictions. Based on this idea Huang, et al. introduced classical shadow tomography [3], a procedure that required only copies of the state and independent of the dimension of the system to approximate the classical shadow. The copies could also be stored efficiently in classical memory. Meaning that one can estimate exponentially many observables using only logarithmically many measurements in the number of observables. These can be used to estimate fidelity, the entanglement entropy, or find entanglement witnesses. The procedure consists of two steps:- Data acquisition - constructing snapshots of the quantum state, and construction of a classical representation of the quantum state, i.e, the classical shadow.
- Prediction
- Given observables , estimate their expectation values .

Procedure
Data Acquisition
One step of the data acquisition procedure consists of the following:- Select a random unitary, , transformation from a predefined, tomographically complete ensemble.
- Apply the transformation to the quantum state of interest:
- Measure the transformed quantum state in the computational basis and obtain a bit string of measurements .
- Store the of the state by classically performing the reverse operation and storing (efficiently) it in classical memory.
Prediction
Although the observables can be predicted using an empirical mean, the authors use a median-of-means approach in order to mitigate outliers:- Divide the shadow into equally sized parts, and take the mean of each one to construct estimators of
- Then, for each observable (for to ), take the median of the means, where is the estimation of the observable:
- Random Pauli measurements: each qubit is rotated by an independently sampled single-qubit Clifford gate, .
- The -qubit Clifford group .
Building a Classical Shadow with Classiq
In this example, we will construct a classical shadow of the bell state, utilizing the random Pauli and random Clifford measurement channels. We begin by describing the random Pauli measurement channel in the first section and continue by analyzing the Clifford measurement channel. For each measurement channel, we first introduce the quantum functions required to implement the quantum part of the shadow protocol. Then we present the classical processing functions, which construct the classical shadow. Utilizing the shadows, the full state is constructed and compared to the ground truth. Generally, state construction even with the classical shadow is inefficient, nevertheless, the construction demonstrates the strength of the method. Following, we utilize the classical shadow representation to estimate the expectation value of , and finally, we evaluate the error bound, lower bounding the number of measurements (sample complexity) required to achieve an accurate estimation with high probability. The Pauli measurement channel (with samples) produced a closer state reconstruction, but did not achieve an accurate estimation of the expectation value of . In contrast, the Clifford measurement channel (with only samples) achieved machine precision for the expectation value estimation, but produced a state with larger distance from the target Bell state (this result is not coincidental but stems from the fact that the Bell state is a stabilizer state and is one of its stabilizers).Classical Shadow with Pauli Measurement Channel
We begin by preparing the Bell state and then rotating each qubit so that it corresponds to a randomly chosen Pauli measurement basis. The tomographically complete set corresponds to measurements in the , , bases respectively. A unitary ensemble of tensor products of single-qubit Clifford circuits is easy to implement on NISQ hardware, performs well when estimating local observables, but scales poorly (see discussion above). Rather than baking each random basis choice into a fresh circuit at synthesis time, which forces one synthesis per snapshot and dominates the wall-clock time, we express the per-qubit rotation as and pass as classical execution-time parameters. The program is then synthesized once and executed in a singleExecutionSession.batch_sample call that submits all snapshots together.
The mapping from basis index to angles is:
| basis | gate (up to global phase) | ||
|---|---|---|---|
BASIS_ANGLES numpy array.
calculate_shadow_pauli() synthesizes the parametric program once, samples the random measurement bases, and submits all snapshots in a single sample call.
The snapshots contain the measurement results (bits) and unitary operations are stored as basis identifiers, in ids list.
Output:
Output:
- Full Tomography: reconstruct the state completely (not just certain pieces of information) as an instructive example.
- Estimating Observables: estimating the expectation values of observables by reconstructing only parts of the state.
State Reconstruction
The two functions below perform a full state reconstruction, given enough snapshots. To reconstruct the state, we take the measurement results insnapshots and apply the inverse of the operations stored in ids. It turns out that since each of our possible unitaries is a tensor product of randomly selected single-qubit Clifford gates, we can apply inverse of the channel Eq. (4)
In snapshot_reconstruction_pauli() below, we apply this equation to get the density matrix of the reconstructed state. reconstruction_pauli() averages these density matrices to get an accurate estimation of the initial state .
Output:
Output:
num_snapshots to see for yourself.
The execution time scales linearly with the number of snapshots.
Although completely reconstructing a state using the classical shadow procedure is an instructive example, the procedure doesn’t offer much advantage when doing so.
Classical shadow shine when estimating many observables.
Estimating Observables
In this example, we will assume that our observables are only made up of Pauli operators. That is, , where is the number of qubits. Recall that to estimate an observable, we compute the median of observable estimators. Each estimator is the product of the observable and the mean of the estimated states in the median-of-means division (Eq. (2)). For each of , we must compute the estimated states from the snapshots in the shadow. For this, we will apply Eq. (4) When the basis matches the observable, e.g. , and we measured in the basis (applied in the circuit), the trace evaluates to when and when . If , the trace evaluates to . Otherwise, the trace evaluates to , making the product .Output:
error_bound_pauli() function below implements this equation for the case of an ensemble consisting of Pauli basis measurements: it computes the per-term locality and uses the shadow-norm bound above.
For other ensembles the shadow norm has a different form (e.g. the Hilbert-Schmidt bound for the random-Clifford ensemble).
Output:
div=2 chunks of 200 shots each, the standard error is .
Classical shadow with random Clifford measurements
We now repeat the protocol with the second ensemble described in the introduction: the full -qubit Clifford group . Instead of applying an independent single-qubit Clifford on each qubit, we sample a single uniformly-random element and apply it globally to the bell state, then measure in the computational basis. As discussed earlier, the average measurement channel is the depolarizing channel , and the inverse-channel snapshot reads This Clifford track is independent of the Pauli-shadow workflow above. Two practical changes from the Pauli protocol:- We sample the random Clifford classically as a depth- sequence of the generator set (applied to randomly chosen qubits).
H, S, and CX qfuncs.
- We record only the sampled gate sequence per snapshot in
clifford_sequences— a list of(label, q1, q2)tuples.
sequence_to_unitary.
Note: As mentioned in the beginning, in contrast to the present implementation, there is no need to create the unitary matrices, corresponding to the random Clifford circuits, explicitly (see sequence_to_unitary).
The unitary operations can be calculated efficiently () employing the stabilizer formalism [5].
Output:
Output:
Output:
Output:
Reconstruction with the Clifford shadow
The inverse-channel snapshot for the Clifford ensemble is given by: Here, is a unitary which generally does not factorize to single qubit gates. So we build in the full -dimensional Hilbert space, and perform the inverse channel. Averaging across the snapshots than reconstructs .Output:
Estimation of Observables
For the random -qubit Clifford measurement channel the inverse channel does not factorize across qubits, and the per-snapshot estimator reads Substituting into gives so each snapshot’s contribution is a single diagonal entry of the rotated observable. As before, we average within each median-of-means chunk and take the median across the chunks (Eqs. (1)–(2)).Output:
Error bound — Clifford ensemble
The sample-complexity bound (Eq. (5)) holds with the Clifford-ensemble shadow norm. Using the upper bound from the introduction, we obtain a sufficient sample count Unlike the Pauli ensemble, this does not scale with the locality of the observable, only with the Hilbert–Schmidt norm of its traceless part, so global observables (e.g. fidelities) are tractable.Output: