Skip to main content

SoftOpt

A standalone optimizer that excels against leading market optimizers like Adam, in problems with a known, differentiable computation graph.

Each step is an update followed by an exact Newton correction computed from your own model, through Klein–Maimon soft-number calculus (Foundations of Soft Logic, Klein & Maimon, Springer 2024). Free, open source, and runs locally.

Where it helps

If your problem has a known computation graph — a quantum circuit, a physical simulator, a projection or measurement model, anything you can write down exactly, even if the measurements of it are noisy — SoftOpt computes an exact directional derivative of that model on every step, plus the curvature along the same direction, and uses them to correct the optimizer's trajectory. Validated, with real hardware-noise-model data, across:

  • Quantum chemistry (VQE) — H₂, H₄, BeH₂, HeH⁺, and larger multireference molecules
  • Quantum control (GRAPE) — the single cleanest result across every domain tested
  • Computer vision — multi-camera bundle adjustment / camera calibration
  • Finance — portfolio optimization (Markowitz mean-variance)
  • Condensed-matter physics — quasicrystal and spin-chain models (Ising, XY, Heisenberg, SSH, Kitaev)
  • Pharmacokinetics, logistic regression, and more

Where it does not help

Full reinforcement learning (or anything else with a continuously moving target — a policy, an adversary, a non-stationary distribution) is outside SoftOpt's validated scope. The mechanism needs a fixed objective to compute a meaningful correction against; a moving target breaks that assumption. Use plain Adam/SGD there.

Installation

pip install softopt

Quick start

import numpy as np
from softopt import SoftOpt, soft_compile

# Write your model once, in plain Python. No special arithmetic.
def my_model(theta):
    x, y = theta
    return (x - 2.0)**2 + np.exp(y) * x

# soft_compile turns it into the exact directional-derivative function
# SoftOpt needs, and verifies the result against your own model.
g_delta = soft_compile(my_model, n_params=2)

opt = SoftOpt(2, g_delta, lr=0.02)

for step in range(num_steps):
    grad_estimate = my_gradient_estimate(theta)   # e.g. from SPSA on real hardware
    theta = opt.step(theta, grad_estimate)

Your model needs to be built from arithmetic and the elementary functions the soft algebra defines: + - * / ** (including negative and fractional exponents, and 2.0 ** x), abs, sqrt, exp, log, log10, sin, cos, tanh, comparisons, and numpy's versions of those. Loops and if/else branching on parameter values work too — the compiled derivative is then valid on the branch your parameters are actually in.

The one thing to avoid is converting a traced value back to a plain number mid-model — float(x), or np.array(params) on the parameter list, both silently discard the derivative. soft_compile's verification catches this and says so.

If you'd rather write the derivative function yourself — because your model lives in a simulator SoftOpt can't trace, or because you want the speed of a hand-tuned implementation — pass any g_delta(theta, delta) that returns the exact directional derivative, and skip soft_compile entirely.

Validated results

All results below use IBM's FakeFez noise model via Qiskit + Aer, or realistic finite-sample/measurement noise for the non-quantum domains, with torch.optim.Adam as the baseline. Improvement is the reduction in gap to the known optimum (or, for Portfolio, the reduction in loss).

Quantum chemistry (VQE)

Domain Improvement Win rate
H₂ 66.6% 5/5
H₄ 89.8% 5/5
C₁₃Cl₂ (13-term Hamiltonian, incl. a 4-body term) 81.3% 5/5
BeH₂ 94.7% 5/5
HeH⁺ 90.9% 5/5

Quantum control

Domain Improvement Win rate
GRAPE (2-qubit) 84.0% 20/20

Condensed-matter & spin models

Domain Improvement Win rate
Ferromagnetic Ising (6-qubit chain) 82.1% 5/5
Transverse Ising (6-qubit chain) 71.2% 5/5
XY model (6-qubit chain) 62.3% 5/5
Antiferromagnetic Heisenberg (6-qubit chain) 61.3% 5/5
SSH model (topological, 6-qubit chain) 71.7% 5/5
Kitaev chain (6-qubit) 68.8% 5/5
Fibonacci chain (classical antiferromagnetic XY, N=16) 95.4% 10/10
Penrose quasicrystal XY-model (50 sites) 146.4% 10/10

Computer vision

Domain Improvement Win rate
Camera calibration (bundle adjustment, realistic pixel + outlier noise) 91.6% 16/20

Finance

Domain Improvement Win rate
Portfolio optimization (realistic backtest noise) ~58x lower loss 20/20

See benchmarks/ for the exact, runnable scripts behind every one of these numbers, including the raw per-seed results.

A performance table cannot show why a method wins. tests/test_causal.py runs the optimizer's own code path while replacing the genuine soft-computed curvature with a frozen constant, or with real curvature measured at an unrelated point. Both perform worse than using no correction at all — the specific computed value is doing the work. Run it directly for the full report:

python3 tests/test_causal.py

The math

The full soft-number algebra is available from the package (from softopt import SoftNumber, sadd, smul, ...), each operation cited to its exact source in Foundations of Soft Logic (Klein & Maimon, Springer 2024):

Operation Book source Formula
sadd(a,b) §3.3.1, p.19 (a+c, b+d)
smul(a,b) §3.3.2, p.19 (ad+bc, bd)
sinv(a,b) Lemma 3.1, p.20 (−a/b², 1/b)
spow(x, n) Lemma 3.3, p.21 (n·a·bⁿ⁻¹, bⁿ)
sroot(x, n), ssqrt(x) Lemma 3.4 (p.22) & 3.5 (p.23) inverts spow
ssin, scos, sexp Lemma 6.1 (p.40) & §6.2 (p.41) f(a,b) = (a·f′(b), f(b))
sdiv(x,y) composition smul(x, sinv(y))

SoftNumber wraps these with operator syntax (x + y, x * y, x ** 3, x.sqrt()) and is verified, axiom by axiom, against the book's own proofs that bridge numbers form an abelian group under addition and a ring under both operations (tests/test_soft_number.py).

What SoftOpt is not

  • Not a claim to beat specialized full-Jacobian second-order solvers (Levenberg–Marquardt, L-BFGS) where those are already practical — SoftOpt's validated niche is genuine improvement over first-order optimizers (Adam, SGD) already in use, particularly where switching to a full second-order method isn't practical (embedded in a larger pipeline, high dimensionality, or measurement noise).
  • Not a general-purpose black-box optimizer — it requires a known computation graph, as described above.

License

MIT. See LICENSE.

Download files

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

Source Distribution

softopt-0.5.5.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

softopt-0.5.5-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file softopt-0.5.5.tar.gz.

File metadata

  • Download URL: softopt-0.5.5.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.7

File hashes

Hashes for softopt-0.5.5.tar.gz
Algorithm Hash digest
SHA256 45c51d8c09500f572a13447c9fb641778a89fd3e624155a5a29cba0a9b5c4859
MD5 6448a8289e118248bbd55d331bdfd87f
BLAKE2b-256 5fddda87fcee499347ff81522a5552cc99284f6f3e3c9a388b222379346d73f8

See more details on using hashes here.

File details

Details for the file softopt-0.5.5-py3-none-any.whl.

File metadata

  • Download URL: softopt-0.5.5-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.7

File hashes

Hashes for softopt-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 00e33a6cbf28a818bdec27e9c9ac01ebf3ed7326391db7db6631f6828b973315
MD5 c89f5b4165ed56a2bc1d6bd18e5b07b7
BLAKE2b-256 4465883d63f188607492901d9b69e3bde341b0021f0472381799e292a801377c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.7

2 files

0.5.6

2 files

This release

0.5.5 This release

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page