QOptLib: Quantum-Inspired Optimizers
A framework of quantum-inspired classical optimizers for machine learning.
Installation
pip install qoptlib
# or for development
pip install -e .
Quick Start
NumPy (Core Optimizers)
import numpy as np
from qoptlib import QuantumAdam
params = [np.random.randn(10, 5).astype(np.float32)]
optimizer = QuantumAdam(params, lr=0.001, quantum_strength=0.2)
def get_grads():
return [np.random.randn(10, 5).astype(np.float32) * 0.1]
for _ in range(100):
optimizer.step(get_grads)
PyTorch (via Adapter)
from quantopt.opt import QuantumAdam
from quantopt.adapters import TorchAdapter
import torch
import torch.nn as nn
model = nn.Sequential(
nn.Linear(10, 64),
nn.ReLU(),
nn.Linear(64, 1)
)
adapter = TorchAdapter(model)
optimizer = QuantumAdam(lr=0.001, quantum_strength=0.2)
# Run optimization
best_weights, best_loss = adapter.optimize(
optimizer,
loss_fn=lambda out, tgt: ((out - tgt) ** 2).mean(),
dataset=torch.utils.data.TensorDataset(
torch.randn(100, 10),
torch.randn(100, 1)
),
iterations=50
)
TensorFlow (via Adapter)
from quantopt.quantopt import QuantumAdam
from quantopt.adapters import TensorFlowAdapter
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.Dense(64, activation='relu', input_shape=(10,)),
tf.keras.layers.Dense(1)
])
adapter = TensorFlowAdapter(model)
optimizer = QuantumAdam(lr=0.001, quantum_strength=0.2)
best_weights, best_loss = adapter.optimize(
optimizer,
loss_fn=lambda y_true, y_pred: tf.keras.losses.mse(y_true, y_pred),
dataset=tf.data.Dataset.from_tensor_slices((
tf.random.normal((100, 10)),
tf.random.normal((100, 1))
)).batch(32),
iterations=50
)
Structure
quantopt/
├── quantopt/ # CORE: NumPy implementations
│ ├── __init__.py # Exports: QuantumSGD, QuantumAdam, QuantumRMSprop, QuantumTunneling
│ ├── base.py # BaseOptimizer
│ ├── sgd.py # QuantumSGD
│ ├── adam.py # QuantumAdam
│ ├── rmsprop.py # QuantumRMSprop
│ └── tunneling.py # QuantumTunneling
│
├── adapters/ # Framework bridges
│ ├── __init__.py # Lazy imports
│ ├── torch.py # TorchAdapter
│ └── tensorflow.py # TensorFlowAdapter
│
├── benchmarks/ # Test functions
├── examples/ # Usage examples
└── tests/ # Test suite
Core Optimizers
| Optimizer | Description |
|---|---|
QuantumSGD |
SGD with quantum noise |
QuantumAdam |
Adam with quantum phase |
QuantumRMSprop |
RMSprop with tunneling |
QuantumTunneling |
Escapes local minima |
Parameters
| Parameter | Description | Default |
|---|---|---|
lr |
Learning rate | optimizer-specific |
quantum_strength |
Quantum effect (0-1) | 0.1 |
momentum |
Momentum factor | 0.0 |
weight_decay |
L2 regularization | 0.0 |
Adapters
TorchAdapter
from quantopt.adapters import TorchAdapter
from quantopt.quantopt import QuantumAdam
adapter = TorchAdapter(model)
optimizer = QuantumAdam(lr=0.001)
best_weights, best_loss = adapter.optimize(
optimizer,
loss_fn,
dataset,
iterations=100,
verbose=True
)
TensorFlowAdapter
from quantopt.adapters import TensorFlowAdapter
from quantopt.quantopt import QuantumAdam
adapter = TensorFlowAdapter(model)
optimizer = QuantumAdam(lr=0.001)
best_weights, best_loss = adapter.optimize(
optimizer,
loss_fn,
dataset,
iterations=100
)
API
Core (NumPy)
from quantopt import QuantumAdam
from quantopt.quantopt import QuantumSGD, QuantumRMSprop, QuantumTunneling
# All have:
opt.step(grad_fn) # Take step
opt.state_dict() # Get state
opt.load_state_dict(d) # Load state
opt.get_lr() # Get LR
opt.set_lr(lr) # Set LR
Adapters
from quantopt.adapters import TorchAdapter, TensorFlowAdapter
adapter = Adapter(model)
adapter.get_weights() # Get flat weights
adapter.set_weights(w) # Set weights
adapter.get_bounds() # Get bounds
adapter.optimize(optimizer, loss_fn, dataset)
Tests
pytest tests/ -v
License
MIT
Metadata
Release files for qoptlib 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qoptlib-0.1.0.tar.gz | 21.7 kB | With provenance | Details for qoptlib-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qoptlib-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for qoptlib-0.1.0-py3-none-any.whl |
Total release size: 46.7 kB
Release files / qoptlib-0.1.0.tar.gz
| Download URL | qoptlib-0.1.0.tar.gz |
|---|---|
| Size | 21.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
959323915b0ca5ee143c8b8e79019d397659019901157ebd4a1337cd8118be2b
|
|
BLAKE2b-256 checksum How to use checksums |
75adad3793cdbf792074d1654b1e474ac6b4fcdfb4caace680352d873b8c1032
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.
Transparency logRelease files / qoptlib-0.1.0-py3-none-any.whl
| Download URL | qoptlib-0.1.0-py3-none-any.whl |
|---|---|
| Size | 25.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0fc71efd56297768d0b17a924d414155eb487d44331c7fe54a0546723c6990f9
|
|
BLAKE2b-256 checksum How to use checksums |
4feb0038fc3e6510e930bca7e58b092a35e41a5b1f5ce60dc0f6d852c0384076
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.
Transparency logSecurity for qoptlib 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for qoptlib-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.