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: TrotterizationStrategy

QDrift Trotterization strategy.

Attributes Summary

keep_fraction

Fraction of terms to keep deterministically by coefficient magnitude (largest first).

keep_top_n

Number of top terms to keep deterministically by coefficient magnitude.

last_sampled_spo

n_hamiltonians_per_iteration

Number of Hamiltonian samples per cost evaluation; losses are averaged over them.

sampling_budget

Number of terms to sample from the remaining Hamiltonian per cost evaluation.

sampling_strategy

How to sample terms — "uniform" (equal probability) or "weighted" (by coefficient magnitude).

seed

Random seed for reproducible sampling.

stateful

True if the strategy retains state across process_hamiltonian calls.

Methods Summary

process_hamiltonian(hamiltonian)

Apply the QDrift randomized 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 QDrift randomized channel to a Hamiltonian.

Implements the QDrift protocol (Campbell 2019): for H = Σ c_i P_i, randomly sample L terms and rescale their coefficients so that E[H_sampled] = H.

Return type:

SparsePauliOp

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