FOMTools
Development, analysis, and code generation for first-order methods.
FOMTools is an open-source Python package for developing, analyzing, and deploying first-order methods for parametric linear and convex quadratic optimization. You write the iteration in Python, with syntax close to its mathematical description, and FOMTools records it as a computation graph of affine and piecewise affine steps. From that single description you can:
- Verify worst-case performance: a mixed-integer program maximizes a convergence residual
over a set of problem instances and initial iterates (
method="mip"). - Simulate at scale: a batched CPU/GPU simulator collects trajectories and bounds the
probability of exceeding a convergence tolerance (
method="simulator"). - Generate code: FOMTools builds the numerical data, factorizations, and matrix-vector routines, and an LLM coding agent writes and optimizes C, OpenMP, or CUDA code. Each phase is checked against a reference run on sampled inputs.
- Solve CVXPY problems: FOMTools works as a CVXPYgen backend, generating first-order solvers for parametric CVXPY problems.
Example
The following code verifies FISTA on a family of Lasso problems
minimize 0.5 ||D s - x||_2^2 + lambda ||s||_1
where s in R^n is the optimization variable and the data vector x ranges over the box
[0, 1]^m. After each iteration it computes the worst-case fixed-point residual
||s^{k+1} - s^k||_inf over all such x.
import numpy as np
import fomtools as ft
# Problem data
m, n, lambd, K = 10, 15, 0.1, 10
D = np.random.normal(size=(m, n))
eta = 1 / np.linalg.norm(D, 2) ** 2
VP = ft.Verifier() # MIP verification with HiGHS; use solver="gurobi" for Gurobi
# Parameter set and initial iterate
x = VP.add_param(m, lb=0, ub=1)
s = [VP.add_iterate(n, lb=0, ub=0)]
w, beta = s[0], 1.0
results = []
for k in range(K):
# FISTA iteration
s.append(VP.step.soft_threshold(w - eta * D.T @ (D @ w - x), lambd=lambd * eta))
beta_old, beta = beta, 0.5 * (1 + np.sqrt(1 + 4 * beta**2))
w = s[k + 1] + (beta_old - 1) / beta * (s[k + 1] - s[k])
# Worst-case residual after k + 1 iterations
VP.set_objective_norm(s[k + 1] - s[k], np.inf)
results.append(VP.solve())
Steps can also be written with proximal operators and projections, e.g.,
VP.prox(NormL1(lambd), v, eta) or VP.project(Box(l, u), v). See the
documentation for the full list of proxable functions and sets.
Beyond worst-case verification
Simulation. Write the same loop with ft.Verifier(method="simulator"), and give
parameters sample arrays of shape (N, d) (or let them be sampled from their bounds). The
simulator runs all samples as batched operations, on a GPU through CuPy when one is
available. It then reports summary statistics and a KL-inverse bound on the probability that
the residual exceeds a tolerance epsilon:
VP.solve(epsilon=1e-3)
VP["quantiles"][0.95], VP["risk_bound"], VP["throughput"]
Code generation. Pass the recorded iterates, unchanged, to codegen. It produces a
specialized solver together with a Python wrapper:
result = VP.codegen("out/fista", iterates=s, code_optimization=True)
Targets include embedded C, multicore CPUs (OpenMP), and GPUs (CUDA). The package works with any coding agent.
CVXPYgen. You can model a parametric problem in CVXPY and generate both its canonicalization code and a first-order solver for it:
import fomtools.cvxpygen as fcpg
fcpg.generate_solver(problem, "out/qp", fom="admm", param_bounds={q: (q_lb, q_ub)})
Installation
FOMTools requires Python 3.12 or later. Install it from PyPI:
pip install fomtools
To install from source instead:
git clone https://github.com/stellatogrp/fomtools.git
cd fomtools
pip install -e .
Optional extras:
| Extra | Description |
|---|---|
gurobi |
Gurobi solver backend |
gpu |
CuPy for GPU-accelerated simulation |
cuda |
cuDSS for direct linear solves in CUDA codegen |
codegen |
LLM coding-agent backends for code generation |
cvxpygen |
CVXPYgen integration |
nn |
Neural-network verification (PyTorch, JAX, Flax) |
dev |
Development tools |
docs |
Documentation build dependencies |
For example, pip install "fomtools[gurobi,codegen]", or
pip install -e ".[gurobi,codegen]" from source.
FOMTools is not a solver. It relies on mathematical programming solvers such as HiGHS (the default) and Gurobi to solve the verification problems it builds.
Examples
The tutorials cover sparse coding (Lasso), nonnegative least squares, network optimization, optimal control, and portfolio rebalancing. Code to reproduce the experiments in our paper is available at stellatogrp/fomtools_experiments.
Contributing
If you'd like to add a new example to our library, or implement a new feature, please get in touch with us first to make sure that your priorities align with ours.
Team
FOMTools is developed by Vinit Ranjan, Daniel Deza, Anushka Acharya, Jisun Park, and Bartolomeo Stellato.
Citing
If you use FOMTools for published work, we encourage you to cite our paper:
@article{ranjan2026fomtools,
title = {{FOMTools}: Development and {AI}-Assisted Code Generation for First-Order Methods},
author = {Ranjan, Vinit and Deza, Daniel and Acharya, Anushka and Park, Jisun and Stellato, Bartolomeo},
journal = {arXiv preprint arXiv:2610.26743},
year = {2026},
}
Metadata
Release files for fomtools 0.0.2
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 | |
|---|---|---|---|---|
| fomtools-0.0.2.tar.gz | 897.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fomtools-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.3 MB
Release files / fomtools-0.0.2.tar.gz
| Download URL | fomtools-0.0.2.tar.gz |
|---|---|
| Size | 897.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ddf89f122cb69348e85251fbae67e6ae86443430dda9db36057e80c7c72f988b
|
|
BLAKE2b-256 checksum How to use checksums |
cb65830779b4c1bcf7c164a6cdcb355ee264c18064688ccd35b767ed1162ef47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 20, 2026.
Transparency logRelease files / fomtools-0.0.2-py3-none-any.whl
| Download URL | fomtools-0.0.2-py3-none-any.whl |
|---|---|
| Size | 420.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e2e38f007e1b624aea82e567eb210a1a5eea78fb6ec3d2c5708e099a9d14e2d
|
|
BLAKE2b-256 checksum How to use checksums |
904aaee6c8bc433f8f2699382905623fab5f20cebb22ac7dfa650d438f8cc61c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 20, 2026.
Transparency logSecurity for fomtools 0.0.2
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 fomtools-0.0.2.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 Oct 20, 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.