ρ is a generalization of the state vector that can represent both pure states and mixed states. It is essential for:
- Describing statistical mixtures of quantum states (when preparation is uncertain)
- Modeling open quantum systems where a qubit interacts with an environment
- Computing the state of a subsystem of a larger entangled system
|ψ⟩ is ρ = |ψ⟩⟨ψ|. A mixed state is a probabilistic combination of pure states: ρ = Σᵢ pᵢ |ψᵢ⟩⟨ψᵢ|.
The github.com/itsubaki/q/quantum/density package provides DensityMatrix along with a library of standard quantum noise channels.
Creating a density matrix
From a pure state
Usedensity.From(qb) to construct a density matrix from a single *qubit.Qubit. This is equivalent to density.FromStates with a single state of probability 1.
From a mixed state
Usedensity.FromStates([]density.WeightedState{...}) to construct a density matrix from a statistical ensemble. Each WeightedState holds a probability and a *qubit.Qubit. Probabilities must sum to 1.
Checking purity
The purity of a density matrix isTr(ρ²):
- Pure state:
Tr(ρ²) = 1 - Mixed state:
Tr(ρ²) < 1 - Maximally mixed (d-dimensional):
Tr(ρ²) = 1/d
Applying noise channels
Noise channels are mapsρ → E(ρ) defined by Kraus operators {Kᵢ} satisfying Σᵢ Kᵢ†Kᵢ = I. The DensityMatrix methods apply channels in-place style, returning a new DensityMatrix.
Bit flip
With probabilityp, the qubit is flipped by X. With probability 1-p, it is left unchanged.
Phase flip
With probabilityp, the qubit’s phase is flipped by Z. This dephases superposition states.
Depolarizing
The depolarizing channel applies X, Y, or Z each with probabilityp/3, and leaves the qubit unchanged with probability 1-p. It is the most common noise model in quantum computing.
Amplitude damping
Models energy loss — a qubit in|1⟩ spontaneously decays to |0⟩ with probability γ. This is the primary model for qubit relaxation (T1 decay).
Kraus operators:
Phase damping
Models pure dephasing — loss of quantum coherence without energy exchange. The off-diagonal elements ofρ decay while the diagonal (populations) remain unchanged.
Kraus operators:
Chaining channels
Channels can be chained because each returns a new*DensityMatrix:
Partial trace for subsystem analysis
The partial trace removes (traces out) one or more qubits from a multi-qubit density matrix, yielding the reduced density matrix of the remaining qubits. For an entangled system, tracing out a qubit generally produces a mixed state — the subsystem has lost information about the traced-out qubit.purity = 1). But when you trace out either qubit, the remaining subsystem is maximally mixed (purity = 0.5). This is a direct signature of entanglement — neither qubit has a definite state on its own.
PartialTrace(qb ...int) is the lower-level method; TraceOut is an alias with the same signature.
What is a Kraus operator?
What is a Kraus operator?
A Kraus operator The completeness relation
Kᵢ is a matrix that describes one possible outcome of a quantum process on an open system. The complete set {Kᵢ} defines the channel E:Σᵢ Kᵢ†Kᵢ = I ensures that probability is preserved (the trace of ρ remains 1).Every physically allowed quantum operation (including noise, measurement, and unitary evolution) can be written in this Kraus operator-sum form. Unitary evolution is the special case where there is only one Kraus operator and it is unitary: E(ρ) = UρU†.In the density package, Kraus operators are constructed inside each ChannelFunc and applied via DensityMatrix.ApplyKraus. You can define a custom channel using density.NewChannel(kraus ...) and apply it with DensityMatrix.ApplyChannel.Reference: Nielsen & Chuang, Quantum Computation and Quantum Information, Chapter 8.