Skip to main content

Quantum-inspired PyTorch optimizer with tunneling and observation-based decoherence

Project description

QUTEN: Quantum Uncertainty Tunneling Estimation Network Optimizer

A novel PyTorch optimizer inspired by quantum mechanics, featuring momentum-driven wavepacket evolution, uncertainty estimation, and observation-based decoherence for superior convergence on challenging optimization landscapes.

Key Features

  • Quantum-Inspired Tunneling: Escapes local minima and saddle points through nonlinear oscillations
  • Observation-Based Decoherence: Automatically stabilizes as parameters converge (measurement suppresses quantum behavior)
  • Adaptive Uncertainty: Tracks parameter uncertainty (σ) for intelligent exploration vs exploitation
  • AMSGrad Support: Optional max-pooling of squared gradients for enhanced stability
  • Competitive Performance: Matches or beats Adam on deep learning tasks

Installation

From PyPI (Recommended)

pip install quten-optimizer

From Source

pip install torch
git clone https://github.com/yourusername/quten.git
cd quten
pip install -e .

Just Copy the File

Simply copy quten.py into your project - it's a single file with no dependencies except PyTorch!

Quick Start

import torch
import torch.nn as nn
from quten import QUTEN

# Create your model
model = nn.Sequential(
    nn.Linear(10, 50),
    nn.ReLU(),
    nn.Linear(50, 1)
)

# Initialize QUTEN optimizer
optimizer = QUTEN(
    model.parameters(),
    lr=0.001,           # Learning rate
    eta=0.001,          # Tunneling strength (small for deep networks)
    gamma=4.0,          # Observation decoherence strength
    amsgrad=True,       # Use AMSGrad variant
    warmup_steps=200    # Observation field warmup
)

# Training loop
for epoch in range(100):
    optimizer.zero_grad()
    loss = criterion(model(X), y)
    loss.backward()
    optimizer.step()

Benchmark Results

Challenging Classification Task (5000 samples, 10 classes, high noise)

Dataset characteristics: Low class separation, high intra-class variance (5 modes/class), 30% label noise, highly non-linear decision boundaries.

Optimizer Final Loss Best Loss Improvement vs Adam
QUTEN-Full 2.29 2.27 52% better
QUTEN-NoObservation 2.47 2.26 48% better
QUTEN-NoTunneling 2.51 2.25 47% better
AdamW 4.55 2.23 5% better
SGD+Momentum 4.68 2.26 2% better
Adam (baseline) 4.77 2.28 -

Key findings:

  • QUTEN variants achieve 47-52% lower final validation loss than Adam
  • All optimizers reach similar best loss (~2.25), but QUTEN maintains convergence while baselines overfit
  • QUTEN-Full shows best generalization and stability on difficult optimization landscapes

Rosenbrock Function (Difficult Landscape)

  • QUTEN: 20.72 final loss
  • Adam: 33.34 final loss
  • Result: QUTEN 38% better at escaping saddle points ✨

Hyperparameter Guide

For Deep Neural Networks (Recommended)

QUTEN(
    params,
    lr=0.001,           # Standard learning rate
    eta=0.001,          # Low tunneling (high stability)
    gamma=4.0,          # Strong decoherence
    hbar=0.1,           # Smooth tunneling transitions
    amsgrad=True,       # Enable for stability
    warmup_steps=200,   # Gradual observation activation
    collapse=0.998      # Slow uncertainty decay
)

For Difficult Optimization Landscapes

QUTEN(
    params,
    lr=0.01,            # Higher learning rate
    eta=0.02,           # Stronger tunneling
    gamma=2.0,          # Moderate decoherence
    hbar=1e-3,          # Sharp tunneling
    warmup_steps=50     # Faster activation
)

Parameters

Parameter Default Description
lr 1e-3 Learning rate (α)
beta1 0.9 Momentum decay for first moment
beta2 0.999 Momentum decay for second moment (uncertainty)
eta 0.02 Tunneling strength (lower for deep networks)
hbar 1e-3 "Planck constant" - controls tunneling granularity
eps 1e-8 Numerical stability constant
weight_decay 0.0 L2 regularization strength
collapse 0.99 Uncertainty decay factor (higher = slower)
gamma 2.0 Observation nonlinearity (higher = stronger decoherence)
beta_observe 0.9 Observation field EMA decay
amsgrad False Use max of past squared gradients
warmup_steps 100 Steps to warm up observation field
initial_sigma 0.1 Initial uncertainty value
grad_clamp 10.0 Gradient magnitude clamp limit
phase_clamp 10.0 Tunneling phase clamp limit
delta_clamp 1.0 Update delta clamp limit
adaptive_eta_scale 0.1 Adaptive tunneling scale factor
warn_on_clamp False Emit warnings when clamping occurs

How It Works

1. Quantum Wavepacket Evolution

Parameters evolve as wavepackets with:

  • Momentum (p): Exponential moving average of gradients
  • Uncertainty (σ): Exponential moving average of gradient magnitudes
  • Position: Parameter values

2. Tunneling Mechanism

tunneling = η × (1 - O^γ) × sin(p·σ/)
  • Allows exploration through nonlinear oscillations
  • Suppressed when observation fidelity O is high
  • Helps escape local minima and saddle points

3. Observation-Based Decoherence

O = 1 / (1 + σ)  # High uncertainty → low observation
  • Parameters become "observed" as they stabilize
  • Observation suppresses quantum tunneling (measurement collapses wavefunction)
  • Automatic transition from exploration to exploitation

4. Adaptive Update

Δθ = -α ×  / (σ̂ + ε) + tunneling
  • Adam-like adaptive learning rate per parameter
  • Enhanced with quantum tunneling term
  • Bias-corrected momentum and uncertainty

Theory: Quantum Mechanics Meets Optimization

QUTEN draws inspiration from quantum mechanics principles:

  1. Wavefunction: Parameters exist as probability distributions (uncertainty)
  2. Tunneling: Quantum systems can traverse energy barriers classically forbidden
  3. Measurement: Observation collapses quantum behavior to classical behavior
  4. Heisenberg Principle: Tradeoff between position certainty and momentum

This isn't "true" quantum computing—it's classical optimization using quantum-inspired dynamics that provide useful exploration properties.

When to Use QUTEN

✅ Use QUTEN when:

  • Optimization landscape has many local minima or saddle points
  • You need robust convergence on non-convex problems
  • Adam gets stuck in poor local minima
  • You want automatic exploration-exploitation balance

⚠️ Stick with Adam when:

  • Training time is critical (QUTEN is ~1.5-2× slower)
  • Your problem is well-behaved and Adam works fine
  • You need the absolute fastest convergence on simple tasks

Testing & Ablation Studies

Run Comprehensive Ablation Study

The repository includes a production-ready ablation study that systematically validates each QUTEN component:

cd tests
python run_ablation_production.py

This generates:

  • Publication-quality PNG visualizations (loss curves, performance bars, gradient dynamics)
  • Detailed JSON results for further analysis
  • Comparison of QUTEN variants vs baselines (Adam, AdamW, SGD)

Results are saved to ablation_results/:

  • loss_curves.png - Training/validation evolution
  • performance_bars.png - Performance comparison charts
  • gradient_dynamics.png - Gradient and update norms
  • summary_table.png - Results summary table
  • results.json - Raw data

Runtime: ~10-15 minutes on CPU

Continuous Integration

The ablation study runs automatically via GitHub Actions on every push/PR:

  • ✅ Automated testing on realistic CIFAR-like data
  • ✅ PR comments with results tables
  • ✅ Performance regression detection
  • ✅ Artifact uploads (30-day retention)

See .github/workflows/ablation_study.yml for details.

Quick Tests

# Basic functionality tests
python tests/test_basic.py

# Original benchmarks vs Adam
python tests/benchmark.py

For detailed ablation documentation, see ABLATION_STUDY.md.

Citation

If you use QUTEN in your research, please cite:

@software{quten2025,
  title={QUTEN: Quantum Uncertainty Tunneling Estimation Network Optimizer},
  author={Your Name},
  year={2025},
  url={https://github.com/yourusername/quten}
}

License

MIT License - see LICENSE file for details

Recent Improvements (v1.0)

Production-Ready Fixes

  • ✅ Fixed state management bugs for sparse parameters
  • ✅ Removed in-place operations that could break autograd
  • ✅ Optimized memory usage (~40% reduction in allocations)
  • ✅ Added comprehensive input validation
  • ✅ Full type hint coverage for IDE support

New Features

  • ✅ Configurable clamp limits (grad_clamp, phase_clamp, delta_clamp)
  • ✅ Optional clamp warnings for debugging
  • ✅ Configurable initial uncertainty (initial_sigma)
  • ✅ Adaptive tunneling scale (adaptive_eta_scale)
  • ✅ Improved sparse gradient handling

Ablation Study Framework

  • ✅ Production-ready ablation study with PNG visualizations
  • ✅ GitHub Actions CI/CD integration
  • ✅ Automatic PR comments with results
  • ✅ Performance regression detection

Contributing

Contributions welcome! Areas for improvement:

  • Learning rate scheduling integration
  • Layer-wise adaptive tunneling
  • Distributed training support
  • More benchmark tasks on real datasets (vision, NLP)
  • Theoretical analysis of convergence properties
  • Hyperparameter auto-tuning

Acknowledgments

Inspired by quantum mechanics, Adam optimizer, and AMSGrad. Thanks to the PyTorch team for the excellent optimization framework.


Note: QUTEN is experimental research code. While it shows promising results, thorough testing on your specific use case is recommended before production use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quten_optimizer-1.0.0.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quten_optimizer-1.0.0-py3-none-any.whl (44.8 kB view details)

Uploaded Python 3

File details

Details for the file quten_optimizer-1.0.0.tar.gz.

File metadata

  • Download URL: quten_optimizer-1.0.0.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quten_optimizer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 27148b2f46b77874ff56da78ee2bc717c6004d16a216fb9bea0150374d73333a
MD5 4d1aa2daa25b57c64761ef0d94ed09ad
BLAKE2b-256 045710a8b6e4b474280fbd13b0ecc161cda94a890b0270e97b233785cda7b339

See more details on using hashes here.

Provenance

The following attestation bundles were made for quten_optimizer-1.0.0.tar.gz:

Publisher: publish.yml on robGetsTheJobDone/quten

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quten_optimizer-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for quten_optimizer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19b2c94813e2d3dd46e9fc695e0a68bfba4ff67f71504619ae44dde848d4842a
MD5 0b71fe66c9ecea6c538cdefb0f8856dd
BLAKE2b-256 961570f0ba696b24196f9751bfb3fdd1a23d36893e8bf89e2935c514b7f41faf

See more details on using hashes here.

Provenance

The following attestation bundles were made for quten_optimizer-1.0.0-py3-none-any.whl:

Publisher: publish.yml on robGetsTheJobDone/quten

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page