Skip to main content

cvxgenrust

CI PyPI License

cvxgenrust takes a parameterized CVXPY optimization problem and generates a Rust solver crate tailored to that problem family. The generated crate reconstructs canonical cone-program data and solves it with Clarabel. It also includes a Python wrapper that can be registered as a custom CVXPY solve method for prototyping.

More details can be found in the associated paper.

Installation

Install the released package from PyPI with:

pip install cvxgenrust

Generated solver projects use Rust, Cargo, Clarabel, and, when the Python wrapper is enabled, a PyO3/maturin build. Install a stable Rust toolchain before building or importing generated extension wrappers.

For development from this repository, use uv to manage dependencies. Once uv is installed, run:

make sync

This installs the default development environment defined by the repository Makefile.

Quick Start

Generate a small nonnegative least-squares solver as a Rust crate:

import cvxpy as cp
import cvxgenrust as cgr

m, n = 3, 2
A = cp.Parameter((m, n), name="A")
b = cp.Parameter(m, name="b")
x = cp.Variable(n, name="x")

problem = cp.Problem(
    cp.Minimize(cp.sum_squares(A @ x - b)),
    [x >= 0],
)

project = cgr.generate_code(
    problem,
    code_dir="nonneg_ls_cgr",
    module_name="nonneg_ls",
)
print("generated:", project.output_dir)

You should always set name= on CVXPY parameters and variables. The generated Rust setters, extractors, metadata, and Python wrapper use those names after code generation.

You can build and run the generated Rust project with:

cd nonneg_ls_cgr
cargo run --example solve

By default, generate_code also compiles the generated Python extension wrapper into the generated project's python/ directory. Pass wrapper=False to only write the Rust crate and Python wrapper sources.

An HTML documentation of the generated project is written to nonneg_ls_cgr/README.html, where you can find more details of the generated code and usage examples.

Structured parameters

cvxgenrust supports real dense, diagonal, symmetric, PSD, NSD, and explicitly sparse CVXPY parameters. Declaring invariant structure with sparsity= keeps known zero entries out of the generated canonical matrices; declaring the same parameter as dense can increase generated code size and solver work. The coordinates excluded by a parameter's sparsity= pattern must remain structural zeros for every update; use a dense parameter if any excluded entry may later become nonzero. Complex and Hermitian parameter layouts are not supported.

Each generated README.html reports the logical shape, packed size, offset, layout, and exact Rust setter order for every parameter. Its generated Python example also shows how to assign values for that problem's layouts.

  • CVXPYgen: C code generation from CVXPY problems.
  • CVXGEN: C code generation for convex optimization in MATLAB.

Release files for cvxgenrust 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cvxgenrust 0.1.1
File Size Uploaded
cvxgenrust-0.1.1.tar.gz 37.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cvxgenrust 0.1.1
File Interpreter ABI Platform
cvxgenrust-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 82.4 kB

Release files / cvxgenrust-0.1.1.tar.gz

Download URL cvxgenrust-0.1.1.tar.gz
Size 37.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d749ab9a6e19d5e4f202a855e09ad6e2cf07f5acdcdd6d0d4445e6b983ae0787
BLAKE2b-256 checksum
How to use checksums
92b0e1bf527b95458b685d82150edeb555adc4adf69cbc9a0cf9cf3545f36cef
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 Sep 22, 2026.

Transparency log

Release files / cvxgenrust-0.1.1-py3-none-any.whl

Download URL cvxgenrust-0.1.1-py3-none-any.whl
Size 44.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c586bf903552694444446cc2763758cbdff1a022bcbf71a7e13616a0fae129a
BLAKE2b-256 checksum
How to use checksums
122dba0909ff0c41ba0b2cc2e558d9c2be51f7a386bec1a59b904de3b5a53cf9
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 Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release 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