Embedded Rust code generation for CVXPY
Project description
cvxgenrust
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.
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.
An HTML summary of the generated project is written to
nonneg_ls_cgr/README.html.
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.
Related projects
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cvxgenrust-0.1.0.tar.gz.
File metadata
- Download URL: cvxgenrust-0.1.0.tar.gz
- Upload date:
- Size: 33.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4989fabfac9e862fa201e517ed56180ac856fed549b129e2b640903c9cddab2
|
|
| MD5 |
9101e57e75f29ce10a9cc6990d15d993
|
|
| BLAKE2b-256 |
cac2e94e5d9c5453d3912424617f068a9142a2cf3b177d4c38152c2680c7c1f8
|
Provenance
The following attestation bundles were made for cvxgenrust-0.1.0.tar.gz:
Publisher:
release.yml on dxogrp/cvxgenrust
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cvxgenrust-0.1.0.tar.gz -
Subject digest:
f4989fabfac9e862fa201e517ed56180ac856fed549b129e2b640903c9cddab2 - Sigstore transparency entry: 1766387966
- Sigstore integration time:
-
Permalink:
dxogrp/cvxgenrust@b3fa2e106893d54fc16a7ca7c658f7c55a6fc33e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dxogrp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b3fa2e106893d54fc16a7ca7c658f7c55a6fc33e -
Trigger Event:
release
-
Statement type:
File details
Details for the file cvxgenrust-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cvxgenrust-0.1.0-py3-none-any.whl
- Upload date:
- Size: 40.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a2fe377c751da8a66eb7df5eb3b33f651219c9f8c1f888b328e47494864cb97
|
|
| MD5 |
723131883c0daec2dfc5de4168bfee6d
|
|
| BLAKE2b-256 |
75ac57398ad9010eff68959bb961275fe6687cef1f6387310289a405bd3f5b2c
|
Provenance
The following attestation bundles were made for cvxgenrust-0.1.0-py3-none-any.whl:
Publisher:
release.yml on dxogrp/cvxgenrust
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cvxgenrust-0.1.0-py3-none-any.whl -
Subject digest:
4a2fe377c751da8a66eb7df5eb3b33f651219c9f8c1f888b328e47494864cb97 - Sigstore transparency entry: 1766388100
- Sigstore integration time:
-
Permalink:
dxogrp/cvxgenrust@b3fa2e106893d54fc16a7ca7c658f7c55a6fc33e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dxogrp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b3fa2e106893d54fc16a7ca7c658f7c55a6fc33e -
Trigger Event:
release
-
Statement type: