QDrift¶
- class QDrift(keep_fraction=None, keep_top_n=None, sampling_budget=None, sampling_strategy='uniform', seed=None, n_hamiltonians_per_iteration=10, _cache=<factory>)[source]¶
Bases:
TrotterizationStrategyQDriftTrotterization strategy.Attributes Summary
Fraction of terms to keep deterministically by coefficient magnitude (largest first).
Number of top terms to keep deterministically by coefficient magnitude.
Number of Hamiltonian samples per cost evaluation; losses are averaged over them.
Number of terms to sample from the remaining Hamiltonian per cost evaluation.
How to sample terms —
"uniform"(equal probability) or"weighted"(by coefficient magnitude).Random seed for reproducible sampling.
True if the strategy retains state across
process_hamiltoniancalls.Methods Summary
process_hamiltonian(hamiltonian)Apply the
QDriftrandomized channel to a Hamiltonian.Attributes Documentation
- keep_fraction: float | None = None¶
Fraction of terms to keep deterministically by coefficient magnitude (largest first). Must be in (0, 1]. If None, all terms go to the sampling pool. Mutually exclusive with keep_top_n.
- keep_top_n: int | None = None¶
Number of top terms to keep deterministically by coefficient magnitude. Must be >= 1. If None, all terms go to the sampling pool. Mutually exclusive with keep_fraction.
- last_sampled_spo: SparsePauliOp | None = None¶
- n_hamiltonians_per_iteration: int = 10¶
Number of Hamiltonian samples per cost evaluation; losses are averaged over them.
- sampling_budget: int | None = None¶
Number of terms to sample from the remaining Hamiltonian per cost evaluation. If None, only kept terms are applied (equivalent to
ExactTrotterization).
- sampling_strategy: Literal['uniform', 'weighted'] = 'uniform'¶
How to sample terms —
"uniform"(equal probability) or"weighted"(by coefficient magnitude).
- seed: int | None = None¶
Random seed for reproducible sampling. If None, sampling is non-deterministic.
- stateful¶
Methods Documentation
- process_hamiltonian(hamiltonian)[source]¶
Apply the
QDriftrandomized channel to a Hamiltonian.Implements the
QDriftprotocol (Campbell 2019): for H = Σ c_i P_i, randomly sample L terms and rescale their coefficients so that E[H_sampled] = H.- Return type:
- Rescaling rules (L = sampling_budget, λ = Σ|c_i|, N = #terms):
Weighted: term_i → (λ / (L · |c_i|)) · c_i · P_i
Uniform: term_i → (N / L) · c_i · P_i