Skip to content

Charlescai123/ecvxcone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NeurIPS 2025: Real-DRL: ECVXCONE Toolbox


ecvxcone (embedded CVX for cone programming) is a lightweight solver tailored for embedded system use, which supports general conic optimization problems.

cvxopt [1] is a Python-based optimization library that leverages C-based high-performance computation backends such as LAPACK and BLAS. In contrast, ecvxcone removes the Python API layer and re-implements the solver logic entirely in pure C, making it better suited for embedded and real-time applications. Its core conic solver is an implementation of the Interior-Point Method [2]. It further optimizes the canonicalization process for problem families to enhance real-time performance.

Note

Currently this library supports the constraints in the linear form. The support for quadratic form of constraints may be added in the future version.


Convex Optimization

📐 Conic Optimization

The mathematical formulation of a generalized cone linear program can be written as:

$$ \begin{aligned} &\underset{x}{\text{minimize}} && \mathbf{c}^T x \\ &\text{subject to} && \mathbf{G}x + \mathbf{s} = \mathbf{h} \\ &&& \mathbf{A}x = \mathbf{b} \\ &&& \mathbf{s} \succeq 0 \end{aligned} $$

with $\mathbf{s}$ being the slack variable. An overview of Conic Optimization problem is shown below:

cone_program
Figure. Overview of Conic Optimization

Problem Representation Conic Type Objective Constraints Figure
LP
(Linear Programming)
$\min_{\mathbf{x}} \ \mathbf{c}^\top\mathbf{x} + d$
s.t. $\mathbf{A}\mathbf{x}\le\mathbf{b}$,
$\mathbf{G}\mathbf{x}=\mathbf{h}$
Nonnegative orthant cone $\mathbb{R}^n_+$ Linear Polyhedron (half-space intersection)
QP
(Quadratic Programming)
$\min_{\mathbf{x}} \ \frac{1}{2}\mathbf{x}^\top\mathbf{Q}\mathbf{x} + \mathbf{p}^\top\mathbf{x} + r$
s.t. $\mathbf{A}\mathbf{x} \le \mathbf{b}$
$\mathbf{G}\mathbf{x} = \mathbf{h}$
Nonnegative orthant cone $\mathbb{R}^n_+$ Quadratic (convex if $Q \succeq 0$) Polyhedral set
SOCP
(Second-Order Conic Programming)
$\min_{\mathbf{x}} \ \mathbf{f}^\top\mathbf{x}$
s.t. $||\mathbf{A}_i\mathbf{x} + \mathbf{b}_i||_2 \le \mathbf{c}_i^\top\mathbf{x}$
$\ + d_i, \ i=1,\dots,n$
$\mathbf{G}\mathbf{x} = \mathbf{h}$
Second-order (Lorentz) cone $\mathcal{Q}^n_+$ Linear Intersection of second-order cones and affine sets
SDP
(Semi-Definite Programming)
$\min_{\mathbf{x}} \ \mathbf{c}^\top\mathbf{x}$
s.t. $\mathbf{x}_1\mathbf{A}_1^i + \dots + \mathbf{x}_n\mathbf{A}_1^n $
$\ + \mathbf{B}^i \preceq 0,\ i=1,\dots,n$
$\mathbf{G}\mathbf{x} = \mathbf{h}$
Positive semidefinite cone $\mathbb{S}^n_+$ Linear Matrix PSD constraint (convex cone)

🔄 Solving Pipeline

The typical workflow for solving an optimization problem consists of:

  • Canonicalization: Using domain-specific languages (DSLs) to transform a problem formulated under disciplined convex programming (DCP) rules into a canonical (standardized mathematical) form

  • Solver Execution: Applying an appropriate solver to the canonical problem (e.g., LP, QP, SOCP, SDP).

canonicalization
Figure. A Typical Workflow for Solving a Convex Optimization Problem

📏 Disciplined Parametrized Programming (DPP)

In a problem family, the optimization problem’s structure remains fixed, with only certain parameters changing. Most DSLs (e.g., CVXPY) recompile the problem into a canonical form for each solve, which can be unnecessary and costly—especially for embedded systems with hard real-time constraints. CVXPYgen addresses this by precompiling the Python-based canonicalization into C code, enabling faster execution for repeated solves.

canonicalization
Figure. Precompilation for a Problem Family with CVXPYgen


⚖️ Solver Comparison

The table below compares popular solvers based on their features. DPP indicates whether the solver supports precompilation of a problem family for embedded deployment.

Solver Open
Source
Problem Type Support Language
Support
DPP Stability License
LP QP SOCP SDP
CLP Yes C++, Python 🟢 High EPL-2.0
OSQP Yes C, Python, MATLAB 🟢 High Apache-2.0
qpOASES Yes C++, Python 🟢 High LGPL-2.1
HiGHS Yes C++, Python 🟢 High MIT
SDPA Yes C++, MATLAB 🟡 Medium BSD
ECOS Yes C, Python 🟡 Medium GPLv3
SCS Yes C, Python, MATLAB 🔴 Low MIT
MOSEK No C, Java, Python, R, MATLAB 🟢 High Commercial (Academic Free)
CVXOPT Yes Python 🟢 High GPLv3
ecvxcone Yes C, C++ 🟢 High Apache-2.0

💡 User Guide

⚙️ Dependencies

  • LAPACK (Linear Algebra PACKage)
  • BLAS (Basic Linear Algebra Subprograms)

🔨 Setup

  1. Clone this repository:
git clone https://github.com/Charlescai123/ecvxcone.git
  1. Create and activate a Conda environment:
conda create --name ecvxcone python==3.10.6
conda activate ecvxcone
  1. Install Python dependencies:
pip install cvxpy cvxopt
  1. Install CVXPYgen:
cd ecvxcone/third_party/cvxpygen
pip install -e .

🤖 Generate C Code

  1. Write your DDP-compliant python code in ecvxcone/third_party/cvxpygen/ecvxcone_cpg.py

  2. Generate the embedded C code:

cd ecvxcone/third_party/cvxpygen && python ecvxcone_cpg.py
  1. Write your real-time parameter update logic in C code, an example is provided in ecvxcone/examples/lmi.c.
graph LR
    subgraph PY["In DDP-compliant (Python)"]
        A1["A_param"]
        A2["B_param"]
        A3["zz_param"]
    end

    subgraph CC["In generated C code"]
        B1["cpg_update_A()"]
        B2["cpg_update_B()"]
        B3["cpg_update_zz()"]
    end

    A1 --> B1
    A2 --> B2
    A3 --> B3

    style A1 fill:#4A90E2,stroke:#2C3E50,stroke-width:2px,color:#fff,rx:10,ry:10
    style A2 fill:#4A90E2,stroke:#2C3E50,stroke-width:2px,color:#fff,rx:10,ry:10
    style A3 fill:#4A90E2,stroke:#2C3E50,stroke-width:2px,color:#fff,rx:10,ry:10

    style B1 fill:#1e1e1e,stroke:#ffffff,color
    style B2 fill:#1e1e1e,stroke:#ffffff,color
    style B3 fill:#1e1e1e,stroke:#ffffff,color
Loading

🛠️ Build

  1. Add configuration to ecvxcone/CMakeLists.txt or use the example lmi.c

  2. Build the project:

cd ecvxcone && mkdir build && cd build
cmake .. && make -j$(nproc)

Tips: Enable unit tests for the solver with cmake command cmake -DBUILD_TESTS=ON ..

  1. Run the example with taskset:
taskset -c 1 ./lmi

Note

A practical ROS 2 implementation for robotics use—featuring a physical model-based safety controller design, is available in phy_teacher_ros2.

🕒 Runtime Validation

The table below presents results for running the example Linear Matrix Inequalities on different embedded platforms, comparing execution time and memory usage between the original Python solver and the C-based ecvxcone implementation.

Hardware Platforms CPU Runtime Memory Usage Solve Time
Arch Core Frequency Python C Python C
Dell XPS 8960 Desktop x86/64 32 5.4 GHz 485 MB 9.87 MB 49.15 ms 13.81 ms
Intel GEEKOM XT13 Pro Mini x86/64 20 4.7 GHz 443 MB 7.32 MB 61.76 ms 33.26 ms
NVIDIA Jetson AGX Orin ARM64 12 2.2 GHz 423 MB 8.16 MB 137.54 ms 35.73 ms
Raspberry Pi 4 Model B ARM64 4 1.5 GHz 436 MB 8.21 MB 509.41 ms 149.87 ms

🏷️ Misc

👁️ Vision

With the growing adoption of machine learning and optimization at the edge, we envision an optimization toolchain that can run efficiently on devices with limited computational resources, delivering real-time performance in those resource-constrained environments.

In addition, there remains a gap between academic research and industrial deployment. Many optimization algorithms stay confined to theory, limited by hardware constraints and the lack of practical, open-source implementations. This repository aspires to bridge that gap—empowering both academic exploration and real-world deployment, while fostering closer collaboration between research and industry.

🚀 Applications

  • Control Theory: Safety Controller Design [4], Decentralized Control and Optimization [5]
  • Trustworthy AI: Robustness Certification [6], Neural Network Verification [7], Fairness-Aware ML [8]
  • Robotics Systems: Obstacle Avoidance [9], Pose Estimation [10], Grasping & Force Optimization [11]

🤝 Contributing

We welcome contributions from developers to add new optimization algorithms and expand hardware validation for demanding real-time embedded applications.


📝 References

[1] Lieven Vandenberghe. Conic Programming. Department of Electrical and Computer Engineering, UCLA. Available at: https://www.seas.ucla.edu/~vandenbe/publications/coneprog.pdf

[2] Martin S. Andersen and Lieven Vandenberghe. Introduction to Mathematical Optimization. Unpublished manuscript. Available at: https://www.seas.ucla.edu/~vandenbe/publications/mlbook.pdf

[3] J. Nocedal and S. J. Wright, Numerical Optimization, 2nd ed. New York, NY, USA: Springer, 2006.

[4] Cai, Yihao, Yanbing Mao, Lui Sha, Hongpeng Cao, and Marco Caccamo. "Runtime Learning Machine." ACM Transactions on Cyber-Physical Systems.

[5] Falsone, Alessandro, Kostas Margellos, and Maria Prandini. "A decentralized approach to multi-agent MILPs: finite-time feasibility and performance guarantees." Automatica 103 (2019): 141-150.

[6] Li, Linyi, Tao Xie, and Bo Li. "Sok: Certified robustness for deep neural networks." 2023 IEEE symposium on security and privacy (SP). IEEE, 2023.

[7] Dathathri, Sumanth, et al. "Enabling certification of verification-agnostic networks via memory-efficient semidefinite programming." Advances in Neural Information Processing Systems 33 (2020): 5318-5331.

[8] Cotter, Andrew, et al. "Optimization with non-differentiable constraints with applications to fairness, recall, churn, and other goals." Journal of Machine Learning Research 20.172 (2019): 1-59.

[9] Deits, Robin & Tedrake, Russ. (2015). Computing Large Convex Regions of Obstacle-Free Space Through Semidefinite Programming. Springer Tracts in Advanced Robotics. 107. 109-124. 10.1007/978-3-319-16595-0_7

[10] Rosen, David M., et al. "SE-Sync: A certifiably correct algorithm for synchronization over the special Euclidean group." The International Journal of Robotics Research 38.2-3 (2019): 95-125.

[11] Dai, Hongkai & Majumdar, Anirudha & Tedrake, Russ. (2015). Synthesis and Optimization of Force Closure Grasps via Sequential Semidefinite Programming.


📝 Citation

Please cite the paper below or star this repo if you find it helpful 🙏

@inproceedings{
anonymous2025realdrl,
title={Real-{DRL}: Teach and Learn at Runtime},
author={Mao, Yanbing and Cai, Yihao and Sha, Lui},
booktitle={The Thirty-ninth Annual Conference on Neural Information Processing Systems},
year={2025},
url={https://openreview.net/forum?id=gXZlZAeqay}


🎉 Acknowledgments

  • cvxopt: Base references for implementation of cone programming.
  • cvxpygen: Some base codes for modeling DPP-compliant problem.

About

A general solver for conic optimization, integrated with a CVX-style interface for efficient real-time and embedded applications.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors