Metadata-Version: 2.4
Name: pycunls-cu13
Version: 0.4.5
Summary: Python bindings for cuNLS: CUDA-accelerated nonlinear least squares solver
Keywords: nonlinear least squares,optimization,factor graph,bundle adjustment,SLAM,CUDA,GPU,Warp
Author: NVIDIA Corporation
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
License-File: third_party/LICENSES/cudss.LICENSE
License-File: third_party/LICENSES/nanobind.LICENSE
License-File: third_party/LICENSES/nvtx.LICENSE
License-File: third_party/LICENSES/spdlog.LICENSE
License-File: third_party/LICENSES/warp.LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: GPU :: NVIDIA CUDA :: 13
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Mathematics
Project-URL: Homepage, https://github.com/nvidia-isaac/cuNLS
Project-URL: Repository, https://github.com/nvidia-isaac/cuNLS
Project-URL: Documentation, https://github.com/nvidia-isaac/cuNLS/blob/main/docs/sphinx/index.rst
Project-URL: Issues, https://github.com/nvidia-isaac/cuNLS/issues
Requires-Python: >=3.10
Requires-Dist: numpy
Requires-Dist: warp-lang>=1.18
Requires-Dist: cuda-toolkit[cublas,cudart,cusolver,cusparse,nvjitlink]<14,>=13.0
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: cupy-cuda13x; extra == "test"
Description-Content-Type: text/markdown

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nvidia-isaac/cuNLS/v0.4.5/docs/sphinx/_static/cuNLS_logo_dark.svg">
    <img src="https://raw.githubusercontent.com/nvidia-isaac/cuNLS/v0.4.5/docs/sphinx/_static/cuNLS_logo_light.svg" alt="cuNLS" width="360">
  </picture>
</p>

<h3 align="center">GPU-Accelerated Nonlinear Least Squares</h3>

<p align="center">
  <code>Python</code>&ensp;·&ensp;<code>CUDA/C++</code>&ensp;·&ensp;<code>Factor graphs</code>&ensp;·&ensp;<code>Manifolds</code>&ensp;·&ensp;<code>RANSAC</code>&ensp;·&ensp;<code>Constraints</code>&ensp;·&ensp;<code>Agent-ready</code>
</p>


---

```bash
pip install pycunls-cu13
python -m pycunls doctor
```

Wheels 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](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/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,

<p align="center">
  <img src="https://raw.githubusercontent.com/nvidia-isaac/cuNLS/v0.4.5/assets/cunls_problem.png" alt="The cuNLS problem: objective, constraints and a factor graph" width="100%">
</p>

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](https://grail.cs.washington.edu/projects/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.<sup>1</sup>

- **Python (`pycunls`)** works on [NVIDIA Warp](https://github.com/NVIDIA/warp) arrays (or any
  `__cuda_array_interface__` array); custom factors, states and `fit` models 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_reason` and a `message` with the fix, and `python -m pycunls guide` prints the
  [agent guide](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/python/pycunls/AGENT_GUIDE.md) shipped in the wheel.

## Features

| | |
|---|---|
| **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 |

## Quick start

### Fit a model

```python
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.927
```

Give `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](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/docs/sphinx/simple_api.rst).

### Solve a factor graph

```python
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 poses
```

`pycunls.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](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/docs/sphinx/troubleshooting.rst).

### RANSAC

Swap the minimizer; the problem stays the same. Sampled factor batches may contain outliers:

```python
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](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/docs/sphinx/ransac.rst)).

### Real-time loops

`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](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/docs/sphinx/introduction.rst), [C++ quick start](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/docs/sphinx/quick_start.rst),
[Custom factors and states](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/docs/sphinx/custom_factors_and_states.rst).

## More

- [Python examples](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/python/examples/README.md) (fitting, pose graphs, bundle adjustment, RANSAC
  PnP, visual-inertial odometry, batched MPC of a drone fleet) and
  [C++ examples](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/examples/README.md).
- [Documentation](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/docs/sphinx/index.rst) (build: `python -m sphinx -b html docs/sphinx
  docs/sphinx/_build`), [CONTRIBUTING.md](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/CONTRIBUTING.md), [AGENTS.md](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/AGENTS.md) for the
  architecture.
- License: [Apache 2.0](https://github.com/nvidia-isaac/cuNLS/blob/v0.4.5/LICENSE); third-party notices in `NOTICE` and `third_party/LICENSES/`.

---

<sup>1</sup> 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.
