Skip to main content

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cvxgenrust-0.1.0.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cvxgenrust-0.1.0-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

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

Hashes for cvxgenrust-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f4989fabfac9e862fa201e517ed56180ac856fed549b129e2b640903c9cddab2
MD5 9101e57e75f29ce10a9cc6990d15d993
BLAKE2b-256 cac2e94e5d9c5453d3912424617f068a9142a2cf3b177d4c38152c2680c7c1f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for cvxgenrust-0.1.0.tar.gz:

Publisher: release.yml on dxogrp/cvxgenrust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for cvxgenrust-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a2fe377c751da8a66eb7df5eb3b33f651219c9f8c1f888b328e47494864cb97
MD5 723131883c0daec2dfc5de4168bfee6d
BLAKE2b-256 75ac57398ad9010eff68959bb961275fe6687cef1f6387310289a405bd3f5b2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cvxgenrust-0.1.0-py3-none-any.whl:

Publisher: release.yml on dxogrp/cvxgenrust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page