Quantum States¶
MicroQuantum represents quantum states two ways: pure StateVector
and mixed DensityMatrix.
StateVector¶
A 2**n complex amplitude vector, normalized to unit norm. Big-endian
ordering means amplitude index 1 corresponds to the bitstring ...001.
import numpy as np
from microquantum import StateVector
sv = StateVector(2) # |00>
sv.amplitudes[3] = 1.0 / 2**0.5 # |11> component
sv = sv.normalize() # |psi> = (|00> + |11>)/sqrt(2)
print(sv.dim) # 4
print(sv.num_qubits) # 2
print(sv.is_normalized) # True
print(sv) # (~0.816)|00> + (~0.577)|11>
Properties and operations¶
amplitudes— the raw complex array (direct access for read/write).normalize()— renormalize in place (returnsselffor chaining).inner_product(other)/fidelity(other)— overlap and fidelity.copy()— deep copy.
Measurement distributions come from sample_state() and the
States layer (see below).
DensityMatrix¶
Density matrices describe mixed states and underpin noisy simulation.
from microquantum import DensityMatrix
dm = DensityMatrix.from_statevector(sv)
print(dm.trace) # 1.0 (property)
print(dm.is_pure) # True for |psi><psi|, False for mixed
print(dm.matrix.shape) # (4, 4)
DensityMatrix also applies unitaries (apply_unitary), Kraus noise
(apply_kraus), forms partial traces, and computes observables
(expectation).
Analysis¶
The States page shows StateAnalysis,
which inspects normalization, probabilities, the most probable basis state and
— for density matrices — trace and purity in a backend-independent way. It
accepts raw StateVector / DensityMatrix
objects or backend results carrying them.
Tensor products¶
For composing systems the SDK provides tensor() (Kronecker
product) and expand_operator(); both operate on the
big-endian convention consistently.