# Qshift Adaptive Sampling

> qSHIFT adaptive sampling protocol for higher-order quantum simulation. Implements L-independent gate complexity with O(t^(1+r)) error scaling through adaptive distribution updates. Use when: performing quantum Hamiltonian simulation, designing quantum algorithms requiring high-precision time evolution, implementing qDRIFT-style randomized product formulas, or optimizing circuit depth for NISQ devices. Triggers on: qshift, adaptive sampling quantum, quantum simulation protocol, higher-order Trotter, qdrift improvement, Hamiltonian simulation.

- Skill: `hiyenwong/qshift-adaptive-sampling` (Agent Skill)
- Install (CLI): `npx get-skill add hiyenwong/qshift-adaptive-sampling`
- Raw SKILL.md: https://api.skillmd.com/api/skills/hiyenwong/qshift-adaptive-sampling/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: hiyenwong (https://skillmd.com/u/hiyenwong)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/hiyenwong/qshift-adaptive-sampling

---


# qSHIFT Adaptive Sampling Protocol

qSHIFT (Quantum Stochastic Hamiltonian Iterative Factorization Technique) is an adaptive sampling protocol for quantum simulation that overcomes the trade-off between circuit depth and accuracy faced by standard methods.

## Core Methodology

### Problem Statement

Standard quantum simulation methods face a fundamental trade-off:
- **Trotterization**: Gate complexity scales with number of Hamiltonian terms L
- **qDRIFT**: Sampling-based but restricted to O(t²) error scaling

### qSHIFT Solution

By adaptively updating sampling distributions, qSHIFT achieves:
- **L-independent gate complexity** (same as qDRIFT)
- **O(t^(1+r)) error scaling** for adjustable parameter r
- **Classical subroutine**: Solves L^r linear equations per sampling round

### Key Insight

The protocol maintains a running estimate of the effective Hamiltonian error and updates the sampling distribution to compensate for accumulated error from previous steps. This is analogous to iterative refinement in numerical linear algebra.

## Algorithm Steps

### Step 1: Hamiltonian Decomposition

Decompose Hamiltonian H = Σⱼ hⱼ Hⱼ where:
- Hⱼ are unitary operators (typically Pauli strings)
- hⱼ are real coefficients
- L = number of terms

### Step 2: Initial Distribution

Set initial sampling distribution:
```
p₀(j) = |hⱼ| / Σₖ |hₖ|
```

### Step 3: Adaptive Sampling Loop

For each time segment τ = t/N:

1. **Sample term**: Draw j ~ pₘ (current distribution)
2. **Apply gate**: Uⱼ = exp(-iτ·sign(hⱼ)·Hⱼ / pₘ(j))
3. **Compute error estimate**: εₘ = accumulated Trotter error
4. **Update distribution**: pₘ₊₁(j) ∝ pₘ(j) + α·|εₘ(j)|^r

Where:
- N = number of time segments
- r = order parameter (typically 1 or 2)
- α = adaptation rate

### Step 4: Distribution Update Rule

The distribution update solves a system of L^r linear equations:
```
A·x = b
```
where A encodes commutator relationships between Hamiltonian terms and b represents the target error distribution.

## Error Analysis

### Error Scaling

Total error after N steps:
```
ε_total = O(t^(1+r) / N^r)
```

Compared to qDRIFT:
```
ε_qdrift = O(t² / N)
```

For r=1: qSHIFT matches qDRIFT gate count with O(t²) error
For r=2: qSHIFT achieves O(t³) error with same gate complexity

### Gate Complexity

Number of gates: O(t²λ² / ε) where λ = Σⱼ|hⱼ|

This is **L-independent**, unlike Trotter methods which scale as O(L·t/ε).

## Implementation Patterns

### NISQ-Compatible Implementation

For near-term devices:
1. Use r=1 for minimal classical overhead
2. Limit distribution updates to dominant terms (top-k by |hⱼ|)
3. Combine with physical error mitigation techniques

### High-Precision Implementation

For fault-tolerant devices:
1. Use r=2 or higher for improved scaling
2. Full distribution update each step
3. Can serve as foundation for qSWIFT or Krylov diagonalization

### Classical Preprocessing

The L^r linear system can be precomputed:
```python
import numpy as np

def build_comm_matrix(terms):
    """Build commutator matrix for distribution update."""
    L = len(terms)
    A = np.zeros((L, L))
    for i in range(L):
        for j in range(L):
            A[i, j] = norm_commutator(terms[i], terms[j])
    return A

def update_distribution(p_prev, error_estimate, alpha, r):
    """Compute updated sampling distribution."""
    correction = alpha * np.abs(error_estimate) ** r
    p_new = p_prev + correction
    return p_new / np.sum(p_new)
```

## Comparison with Baselines

| Method | Gate Complexity | Error Scaling | L-Dependent |
|--------|----------------|--------------|-------------|
| Trotter | O(L·t/ε) | O(t^(k+1)) | Yes |
| qDRIFT | O(t²λ²/ε) | O(t²) | No |
| qSHIFT | O(t²λ²/ε) | O(t^(1+r)) | No |
| qSWIFT | O(tλ/ε) | O(t^(k+1)) | Yes (weak) |

## Applications

1. **Quantum chemistry**: Molecular Hamiltonian simulation
2. **Condensed matter**: Lattice model time evolution
3. **Quantum dynamics**: Open system simulation
4. **Quantum algorithms**: Subroutine for phase estimation, HHL

## Best Practices

1. **Choose r appropriately**: Higher r gives better scaling but more classical overhead
2. **Precompute commutators**: The commutator structure is Hamiltonian-dependent but time-independent
3. **Truncate small terms**: Terms with |hⱼ| below threshold can be dropped with bounded error
4. **Combine with error mitigation**: Reduced circuit depth enables better physical error mitigation
5. **Monitor distribution convergence**: The adaptive distribution should converge to a stable form

## References

- arXiv:2604.26263 — qSHIFT: An Adaptive Sampling Protocol for Higher-Order Quantum Simulation
- Campbell, E. (2019). Random Compiler for Fast Hamiltonian Simulation (qDRIFT)
- Low, G. H., & Wiebe, N. (2019). Hamiltonian Simulation in the Sparse Query Model (qSWIFT)

