qdk_chemistry.algorithms.hamiltonian_unitary_builder.time_evolution.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.hamiltonian_unitary_builder.time_evolution.qdrift.QDrift(*, time=0.0, num_samples=100, target_accuracy=0.0, error_bound='campbell', weight_threshold=1e-12, seed=-1, merge_duplicate_terms=True, commutation_type='general', power=1, power_strategy='repeat')[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:
  • time (float)

  • num_samples (int)

  • target_accuracy (float)

  • error_bound (str)

  • weight_threshold (float)

  • seed (int)

  • merge_duplicate_terms (bool)

  • commutation_type (str)

  • power (int)

  • power_strategy (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("hamiltonian_unitary_builder", "qdrift", num_samples=500, seed=42, time=1.0)
>>> # Use it to build a unitary representation for a Hamiltonian
>>> unitary_rep = qdrift.run(qubit_hamiltonian)

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__(*, time=0.0, num_samples=100, target_accuracy=0.0, error_bound='campbell', weight_threshold=1e-12, seed=-1, merge_duplicate_terms=True, commutation_type='general', power=1, power_strategy='repeat')[source]

Initialize qDRIFT builder with specified settings.

Parameters:
  • time (float) – The evolution time. Defaults to 0.0.

  • num_samples (int) – Number of random samples N. Acts as a manual floor when target_accuracy is also provided (the larger value wins). More samples increase accuracy but also increase circuit depth. Error scales as O(λ²t²/N). Defaults to 100.

  • target_accuracy (float) – Target accuracy ε for automatic sample-count computation using the Campbell (2019) bound N >= ceil(2 λ² / ε). Use 0.0 (default) to disable and rely solely on num_samples. When both are provided, the larger of the two values is used.

  • error_bound (str) – Strategy for computing the qDRIFT error bound. Currently only "campbell" is supported. Defaults to "campbell".

  • weight_threshold (float) – Threshold for filtering small coefficients when computing λ and when sampling. Defaults to 1e-12.

  • 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.

  • power (int) – The power to raise the unitary to. Defaults to 1.

  • power_strategy (str) – Strategy for U^power: "rescale" scales time, "repeat" repeats the circuit. Defaults to "repeat".

name()[source]

Return the name of the unitary builder.

Return type:

str

type_name()[source]

Return hamiltonian_unitary_builder as the algorithm type name.

Return type:

str

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

Bases: TimeEvolutionSettings

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.