QPCA quantum principal component analysis¶
oracq.algorithms.qml.qpca
QPCA quantum principal component analysis: density matrix exponentiation (the LMR protocol) plus phase estimation.
Implements the core primitive of Lloyd–Mohseni–Rebentrost 2014 (“Quantum
principal component analysis”, Nature Physics 10, 631). Density matrix
exponentiation exploits the eigenvalue structure of the SWAP operator:
perform a partial swap e^{-iΔt·SWAP} between one copy of ρ and the
system, and after discarding the copy the effective channel on the system is
the first-order approximation of e^{-iρΔt} (error O(Δt²)); chaining
copies copies gives total time t = copies·Δt. QPCA runs phase estimation on
that unitary and reads out the spectrum of ρ.
Input model: copies of ρ are provided by a state preparation oracle (SP/QRAM bindable at three layers); mixed states are adapted via density.PurificationAccess.as_state_preparation (environment qubits stay out of the swap, which has the same effect as taking the partial trace). Multiple copies mean multiple invocations of the preparation oracle — the resource precondition of QPCA — recorded into the attributes together with the QRAM assumption.
- oracq.algorithms.qml.qpca.density_matrix_exponentiation(preparation, *, time, copies, swap_width=None, name=None)[source]¶
LMR density matrix exponentiation: approximate
e^{-iρ·time}on the system using copies copies of ρ.- Parameters:
preparation – State preparation of a ρ copy (a StatePreparation, possibly a purification adapter).
time – Total evolution time t; each step is Δt = t/copies.
copies – Number of copies; the first-order error O(t·Δt) decreases linearly with it.
swap_width – Prefix bit width participating in the swap, defaulting to the preparation’s entire target (purification scenarios should use ρ’s system width, leaving the environment qubits in the copy out of the swap).
name – Overrides the automatically generated module name.
- Returns:
Registers system (swap_width bits) and copies (copies × prep.width bits). The system’s input state is prepared by the caller; the copy registers are filled from all zeros by the preparation oracle.
- Return type:
- oracq.algorithms.qml.qpca.qpca(preparation, *, precision, step_time, system=None, swap_width=None, name=None)[source]¶
QPCA principal component analysis: run phase estimation on
e^{-iρ·step_time}and read out the spectrum of ρ.- Parameters:
preparation – State preparation of a ρ copy;
2**precision − 1copies are consumed in total.precision – Number of phase register bits, in 1..6 (the copy count grows exponentially).
step_time – Single-step evolution time Δt; it must satisfy λ·Δt ≪ 2π to avoid readout aliasing.
system – Optional state preparation of the system input (default
|0>); different eigenstate inputs correspond to different eigenvalue peaks in the readout.swap_width – Prefix bit width participating in the swap, same semantics as density_matrix_exponentiation.
name – Overrides the automatically generated module name.
- Returns:
Registers system, copies, and phase. After reading out phase, decode the eigenvalue with eigenvalue_from_phase.
- Return type:
- oracq.algorithms.qml.qpca.eigenvalue_from_phase(value, precision, step_time)[source]¶
Decode the phase readout of qpca into an eigenvalue estimate of ρ.
The eigenphase of the unitary step
e^{-iρΔt}isφ = -λΔt/(2π) (mod 1); this function decodes on the λ ∈ [0, π/Δt) branch, and aliasing occurs when λ·Δt leaves that range (the caller’s responsibility).- Parameters:
value – phase register readout, an integer in 0..2^precision−1.
precision – Number of phase register bits, in 1..63.
step_time – Duration Δt of a partial swap step, a positive real.
- Returns:
Eigenvalue estimate λ of the density matrix.
- Return type:
float