Python · CUDA/C++ · Factor graphs · Manifolds · RANSAC · Constraints · Agent-ready
pip install pycunls-cu13
python -m pycunls doctorWheels for x86_64 Linux, Python 3.10-3.14, CUDA 13 (R580+ driver). The C++ library builds with CUDA 12.6+ and 13, including Jetson Orin and Thor. CUDA libraries, cuDSS and source builds: INSTALL.md.
cuNLS solves nonlinear least-squares problems entirely on the GPU: any factor graph over Euclidean and manifold states, with robust losses, constraints and bounds,
from curve fitting and thousands of small independent problems in one call to bundle adjustment, pose graphs, visual-inertial odometry and model-predictive control. On the BAL Venice problem (1,776 cameras, 993k points) it converges in 0.53 s, 53× faster than Ceres; on the torus3D pose graph it is 24-34× faster than Ceres, GTSAM and g2o.1
- Python (
pycunls) works on NVIDIA Warp arrays (or any__cuda_array_interface__array); custom factors, states andfitmodels are Warp kernels. C++ (cunls): shared or static library, x86_64 and Jetson. - Agent-ready: problems are checked before solving, every result carries a
termination_reasonand amessagewith the fix, andpython -m pycunls guideprints the agent guide shipped in the wheel.
| States | Vectors, SO(2), SO(3), SE(2), SE(3), Sim(2), Sim(3), SL(4), articulated robots |
| Factors | Reprojection, PnP, between, prior, point-to-point / plane, IMU, motion priors, vehicle and robot dynamics, robot kinematics, clearance; custom factors in Warp or CUDA |
| Solvers | Gauss-Newton, Levenberg-Marquardt; batched subproblems with their own steps and stopping |
| Constraints | Equality, inequality and box bounds (augmented Lagrangian) |
| RANSAC | Hundreds of hypotheses in parallel, any factor and state type (free dimension ≤ 64) |
| Robust losses | Huber, Cauchy, Arctan, SoftL1, Tolerant, Tukey, Scaled |
| Linear solvers | Supernodal block-sparse Cholesky (default, also for the Schur complement), block-sparse PCG, cuDSS, block-tridiagonal, dense LDLT / Cholesky / QR |
| Jacobians | Analytic, Warp autodiff, or finite differences per factor |
| Real time | Fully asynchronous on CUDA streams; fixed buffers re-solved with new data, no reallocation |
import numpy as np, warp as wp, pycunls
@wp.func
def decay(x: float, p: wp.vec3) -> float: # y = a exp(-b x) + c, for one sample
return p[0] * wp.exp(-p[1] * x) + p[2]
x = np.linspace(0.0, 4.0, 200)
y = 2.0 * np.exp(-1.3 * x) + 0.5 + np.random.default_rng(0).normal(0.0, 0.02, x.size)
res = pycunls.fit(decay, x, y, p0=[1.0, 1.0, 0.0], sigma=0.02)
print(res.report()) # p = [1.9964 ± 0.0063, 1.28707 ± 0.0087, 0.497294 ± 0.0027], reduced chi2 0.927Give y one row per fit (e.g. (10000, 200)) and all fits are solved in one call, each with its
own steps and stopping rule. Robust losses, bounds and multiple starts are one argument each:
Quick setup.
pb = pycunls.ProblemBuilder()
poses = pb.add_states(pycunls.SE2StateBatch, start, constant=[0]) # (N, 3, 3); pose 0 fixes the gauge
pb.add_factors(pycunls.SE2BetweenFactorBatch, deltas, connect=(poses, edges)) # edges (M, 2)
result = pb.solve() # checks the problem, then Levenberg-Marquardt
print(result.message) # why it stopped, and the fix if it failed
T = result[poses] # solved posespycunls.describe("SE2BetweenFactorBatch") gives a factor's states, residual, layout and
conventions; pycunls.catalog() lists them all. Mistakes such as a missing anchor or a wrong state
type are reported with the fix before solving: Troubleshooting.
Swap the minimizer; the problem stays the same. Sampled factor batches may contain outliers:
options = pycunls.RansacLevenbergMarquardtMinimizerOptions()
options.base_options.factor_batches = [pycunls.RansacFactorBatchOptions(pycunls.RansacRole.sampled, 0.01)]
minimizer = pycunls.RansacLevenbergMarquardtMinimizer(options)
summary = minimizer.minimize(stream, problem)
inliers = minimizer.inlier_mask(0)PnP with up to 90% outliers: 1.4 ms for 1,000 correspondences (RANSAC).
fit and ProblemBuilder build an ordinary pycunls.Problem; built directly on your own Warp
buffers it is re-solved every frame without reallocation. Every batch has a fixed capacity and
an active count that starts at zero (set_num_active_states / set_num_active_factors):
Capacity and active count, C++ quick start,
Custom factors and states.
- Python examples (fitting, pose graphs, bundle adjustment, RANSAC PnP, visual-inertial odometry, batched MPC of a drone fleet) and C++ examples.
- Documentation (build:
python -m sphinx -b html docs/sphinx docs/sphinx/_build), CONTRIBUTING.md, AGENTS.md for the architecture. - License: Apache 2.0; third-party notices in
NOTICEandthird_party/LICENSES/.
1 cuNLS (fp32) on an NVIDIA RTX PRO 5000 Blackwell; Ceres, GTSAM and g2o (fp64) on an Intel Core i9-14900K with OpenBLAS; same problem, start and stopping rule, median of 5 runs.
