Skip to content

Density-matrix circuit simulation propagates the ensemble state exactly within a finite noise model, up to floating-point error. It removes trajectory sampling variance from expectation values at the cost of 4n4^n complex entries for nn qubits. It is particularly useful as a small-system reference for testing approximate simulators.

Helpful background. Density-matrix storage supplies representation checks; quantum channels defines Kraus maps.

With nn binary ket indices and nn bra indices, store

ρi0⋯in−1;j0⋯jn−1.\rho_{i_0\cdots i_{n-1};j_0\cdots j_{n-1}}.

A gate UU on a chosen kk-qubit target set contracts UU into the ket axes and U∗U^* into the corresponding bra axes. For one target,

ρ…i…;…j…′=∑abUiaρ…a…;…b…Ujb∗.\rho'_{\ldots i\ldots;\ldots j\ldots} =\sum_{ab}U_{ia}\rho_{\ldots a\ldots;\ldots b\ldots}U^*_{jb}.

Apply the two contractions sequentially. This avoids constructing a 2n2^n square full-register gate or a 4n4^n square superoperator. For fixed local gate size the work is proportional to the density-array size, with constants set by target dimension.

For several targets, keep their ordered tuple explicit. Permute ket axes so that those targets precede the untouched axes, and apply the matching permutation to bra axes. Reshape to ρar;bs\rho_{ar;bs} with target dimension dt=2kd_t=2^k and remainder dimension dr=2n−kd_r=2^{n-k}. Then

ρir;js′=∑abUiaρar;bsUjb∗.\rho'_{ir;js}=\sum_{ab}U_{ia}\rho_{ar;bs}U^*_{jb}.

Undo both permutations after the contractions. A gate whose local basis is ordered by targets (2,0)(2,0) generally changes meaning if that tuple is sorted to (0,2)(0,2) without also transforming the gate. Test an asymmetric complex gate on nonadjacent targets, since real gates or symmetric states can hide conjugation and ordering errors. The two dense contractions cost O(dt 4n)O(d_t\,4^n) operations for a fixed gate; applying rKr_K Kraus operators costs O(rKdt 4n)O(r_Kd_t\,4^n).

A channel sums the same contractions over its local Kraus operators. Use separate input and accumulation buffers: overwriting the input after the first Kraus term changes later terms and can still produce a normalized-looking result.

Prepare ∣Φ+⟩=(∣00⟩+∣11⟩)/2|\Phi^+\rangle=(|00\rangle+|11\rangle)/\sqrt2 and damp the second qubit with probability pp. The output is

ρ′=12(1001−p000000p01−p001−p).\rho'=\frac12 \begin{pmatrix} 1&0&0&\sqrt{1-p}\\ 0&0&0&0\\ 0&0&p&0\\ \sqrt{1-p}&0&0&1-p \end{pmatrix}.

In ordering (00,01,10,11)(00,01,10,11) the decay event sends ∣11⟩|11\rangle to ∣10⟩|10\rangle. This distinguishes which qubit was targeted; damping the first qubit puts the population in ∣01⟩|01\rangle instead.

The exact measurement probabilities are (1/2,0,p/2,(1−p)/2)(1/2,0,p/2,(1-p)/2), and Bell-state fidelity is (2−p+21−p)/4(2-p+2\sqrt{1-p})/4. At p=1p=1 the result is a mixture of ∣00⟩|00\rangle and ∣10⟩|10\rangle, not a pure reset of the entire register.

For outcome mm with measurement operator MmM_m, the unnormalized branch is ρ~m=MmρMm†\tilde\rho_m=M_m\rho M_m^\dagger, with probability pm=Tr⁡ρ~mp_m=\operatorname{Tr}\tilde\rho_m. If the outcome is ignored, sum the branches. If later gates depend on mm, keep the classical branch label until branches can validly be merged.

A density matrix with all branches averaged together is insufficient for arbitrary outcome-dependent control. Two branches can have the same quantum state yet different future classical instructions. Branch weights should sum to one; never normalize a branch with zero probability.

One exact representation retains unnormalized blocks ρCQ=∑m∣m⟩⟨m∣⊗ρ~m\rho_{\rm CQ}=\sum_m|m\rangle\langle m|\otimes\tilde\rho_m. If the next operation is the unitary UmU_m selected by the classical outcome, the final quantum state is

ρout=∑mUmρ~mUm†.\rho_{\rm out}=\sum_m U_m\tilde\rho_m U_m^\dagger.

For example, measure ∣+⟩|+\rangle in the ZZ basis, then apply XX only after outcome 1. The two blocks are ∣0⟩⟨0∣/2|0\rangle\langle0|/2 and ∣1⟩⟨1∣/2|1\rangle\langle1|/2, and the controlled continuation produces ∣0⟩⟨0∣|0\rangle\langle0|. Averaging first gives I/2I/2; no outcome-independent unitary acting on that average can reproduce the result. Store branch traces as weights, or store normalized states with separate weights, but do not count the probability twice.

Sampling outcomes introduces shot noise even when state propagation is deterministic. Exact probabilities and finite-shot histograms are different outputs; use measurement sampling for the latter.

Complex double storage is 16 4n16\,4^n bytes: n=15n=15 already needs 16 GiB for one state array. Kraus buffers and contraction copies can multiply peak memory. Plan memory from actual workspace requirements.

Test local contractions against full Kronecker matrices for two or three qubits, including nonadjacent targets and complex gates. Check each channel’s Choi matrix separately and state diagnostics after circuit segments. Compare a noiseless run to the projector from a statevector simulator.

Do not truncate tiny off-diagonal entries without an observable-error study. Their collective contribution can matter, and entrywise sparsification is not a positivity-preserving operation.

Why can all terminal computational-basis shots be sampled from one evolved density matrix, but mid-circuit adaptive measurements may require repeated branching?

Solution

Terminal shots are independent categorical draws from the unchanged diagonal distribution. A mid-circuit outcome changes the conditional state and can select subsequent gates, so each branch has a different continuation. Exact branch enumeration or correctly sampled conditional trajectories is required.

  • QuTiP developers, “Basic Operations on Quantum Objects”, QuTiP documentation — tensor dimensions and operator representations.
  • Watrous, J., The Theory of Quantum Information, Cambridge University Press (2018), author’s text — channels, instruments, and classical outcomes.