qdk_chemistry.algorithms.time_evolution.builder.qdrift module

QDK/Chemistry implementation of the qDRIFT randomized evolution builder.

This module implements the qDRIFT algorithm for Hamiltonian simulation, which provides an alternative to deterministic Trotter decomposition by using randomized sampling.

References

Campbell, E. (2019). Random Compiler for Fast Hamiltonian Simulation. Physical Review Letters, 123(7), 070503. https://arxiv.org/abs/1811.08017 https://doi.org/10.1103/PhysRevLett.123.070503

class qdk_chemistry.algorithms.time_evolution.builder.qdrift.QDrift(num_samples=100, seed=-1, merge_duplicate_terms=True, commutation_type='general')[source]

Bases: TimeEvolutionBuilder

qDRIFT randomized product formula builder.

Implements the qDRIFT algorithm from Campbell (2019), which approximates the time evolution operator \(U(t) = e^{-iHt}\) using randomized sampling of Hamiltonian terms.

Instead of applying all Hamiltonian terms in a fixed sequence (as in Trotter decomposition), qDRIFT randomly samples terms with probability proportional to their coefficient magnitudes. This can achieve better gate complexity for Hamiltonians with many terms.

The algorithm works as follows:

  1. Compute \(\lambda = \sum_j |h_j|\) (1-norm of coefficients)

  2. Build probability distribution \(p_j = |h_j| / \lambda\)

  3. Sample N terms according to this distribution

  4. Each sample contributes \(e^{-i \cdot \text{sign}(h_j) \cdot \lambda t / N \cdot P_j}\)

The approximation error is bounded by \(\epsilon \leq 2\lambda^2 t^2 / N\).

Parameters:
  • num_samples (int)

  • seed (int)

  • merge_duplicate_terms (bool)

  • commutation_type (str)

num_samples

Number of random samples to draw.

seed

Random seed for reproducibility.

merge_duplicate_terms

Whether to fuse identical Pauli terms within consecutive commuting runs.

Examples

>>> from qdk_chemistry.algorithms import create
>>> # Create a qDRIFT builder with 500 samples
>>> qdrift = create("time_evolution_builder", "qdrift", num_samples=500, seed=42)
>>> # Use it to build time evolution for a Hamiltonian
>>> time_evolution = qdrift.run(qubit_hamiltonian, time=1.0)

References

Campbell, E. (2019). Random Compiler for Fast Hamiltonian Simulation. Physical Review Letters, 123(7), 070503. https://arxiv.org/abs/1811.08017 https://doi.org/10.1103/PhysRevLett.123.070503

__init__(num_samples=100, seed=-1, merge_duplicate_terms=True, commutation_type='general')[source]

Initialize qDRIFT builder with specified settings.

Parameters:
  • num_samples (int) – Number of random samples N. More samples increase accuracy but also increase circuit depth. Error scales as O(λ²t²/N). Defaults to 100.

  • seed (int) – Random seed for reproducibility. Use -1 for non-deterministic sampling. Defaults to -1.

  • merge_duplicate_terms (bool) – If True, identical Pauli terms within consecutive mutually-commuting runs are fused to reduce circuit depth. Distinct commuting terms are kept separate. The merging is exact and preserves the Campbell (2019) error bound. Defaults to True.

  • commutation_type (str) – Commutation check used when merging duplicate terms. "qubit_wise" requires every single-qubit pair to commute individually — stricter but always safe. "general" (default) uses standard Pauli commutation (even number of anti-commuting positions), which allows larger merge groups.

name()[source]

Return the name of the time evolution unitary builder.

Return type:

str

type_name()[source]

Return time_evolution_builder as the algorithm type name.

Return type:

str

class qdk_chemistry.algorithms.time_evolution.builder.qdrift.QDriftSettings[source]

Bases: Settings

Settings for qDRIFT randomized decomposition builder.

The qDRIFT algorithm approximates the time evolution operator using randomized sampling of Hamiltonian terms. The error scales as O(λ²t²/N), where λ is the 1-norm of the Hamiltonian coefficients, t is evolution time, and N is the number of samples.

__init__()[source]

Initialize QDriftSettings with default values.

num_samples

Number of random samples N. More samples = higher accuracy. Error scales as O(λ²t²/N).

seed

Random seed for reproducibility. Use -1 for non-deterministic behavior.

merge_duplicate_terms

Whether to fuse identical Pauli terms that appear in consecutive mutually-commuting runs, reducing circuit depth. Only equal operators are combined; distinct commuting terms are kept separate. The merging is exact and preserves the error bound.