Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Validate skills

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

jobs:
unittest:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.13"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: skills/osqp-solver/requirements-test.txt
- name: Install OSQP test dependency
run: python -m pip install -r skills/osqp-solver/requirements-test.txt
- name: Run repository tests with zero skips
run: python -m unittest discover -s tests -v
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ attribution ledger.
| Module | Source | Contributor(s) | Contribution scope | Attribution record |
| --- | --- | --- | --- | --- |
| Root repository router | Current `VeryMath/AI4Math-Optimization` repository | [Conan Xu](https://github.com/ConanXu-math), conanxu <1845830029@qq.com> | Root README, bilingual repository map, package routing layer, and public repository structure. | Preserved through repository commit history. |
| `skills/osqp-solver` | New package prepared in the AI4Math Skill Library from official OSQP documentation | [Conan Xu](https://github.com/ConanXu-math) | Package commissioning, integration, review, and release stewardship; implementation was AI-assisted and independently tested. | Preserve through the upstream integration commit and pull request. |
| Optimization skill packages | Repository history and imported optimization work | [ricercar77](https://github.com/ricercar77) | Optimization skill contributions and package content. | Preserved through GitHub contributor graph, repository history, and this ledger. |
| `skills/linear-programming`, `skills/mixed-integer-programming`, `skills/second-order-cone-programming`, `skills/or-solver` | Current package metadata | 李爽夕 | LP, MIP, SOCP, solver-setup workflow content, examples, and benchmark materials. | Recorded in package metadata and this ledger. |

Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

# AI4Math · Optimization

Skill packages for mathematical optimization modeling, solver setup, LP/MIP/SOCP
workflows, and manifold-constrained optimization.
Skill packages for mathematical optimization modeling, solver setup,
LP/MIP/SOCP workflows, continuous convex QP/OSQP, and
manifold-constrained optimization.

[中文说明](README.zh-CN.md) · [Contributors](CONTRIBUTORS.md) · [Skill packages](#skill-packages) · [Installation](#installation) · [Quick start](#quick-start) · [Security model](#security-and-scope)

![version](https://img.shields.io/badge/version-0.1.0-blue)
![skills](https://img.shields.io/badge/skills-6-2ea44f)
![skills](https://img.shields.io/badge/skills-7-2ea44f)
![license](https://img.shields.io/badge/license-MIT-green)

</div>
Expand Down Expand Up @@ -37,6 +38,7 @@ package that matches the problem class.
| [`mixed-integer-programming`](skills/mixed-integer-programming/) | MILP/MIP modeling with binary, integer, and continuous decision variables. | [`README`](skills/mixed-integer-programming/README.md) · [`SKILL`](skills/mixed-integer-programming/SKILL.md) |
| [`second-order-cone-programming`](skills/second-order-cone-programming/) | SOCP modeling and cvxpy-based conic solver workflows. | [`README`](skills/second-order-cone-programming/README.md) · [`SKILL`](skills/second-order-cone-programming/SKILL.md) |
| [`or-solver`](skills/or-solver/) | Shared solver detection, installation planning, license checks, and solver selection for OR skills. | [`README`](skills/or-solver/README.md) · [`SKILL`](skills/or-solver/SKILL.md) |
| [`osqp-solver`](skills/osqp-solver/) | OSQP modeling, repeated solves, status gates, and independent verification for continuous convex QPs. | [`README`](skills/osqp-solver/README.md) · [`SKILL`](skills/osqp-solver/SKILL.md) |

## Installation

Expand All @@ -54,6 +56,7 @@ Skill paths:
- skills/mixed-integer-programming
- skills/second-order-cone-programming
- skills/or-solver
- skills/osqp-solver

Steps:
1. Clone or update the repository locally.
Expand All @@ -76,6 +79,7 @@ ln -s "$PWD/skills/linear-programming" ~/.codex/skills/linear-programming
ln -s "$PWD/skills/mixed-integer-programming" ~/.codex/skills/mixed-integer-programming
ln -s "$PWD/skills/second-order-cone-programming" ~/.codex/skills/second-order-cone-programming
ln -s "$PWD/skills/or-solver" ~/.codex/skills/or-solver
ln -s "$PWD/skills/osqp-solver" ~/.codex/skills/osqp-solver
```

If your agent uses a different local Skill directory, replace `~/.codex/skills` with that configured path.
Expand All @@ -102,6 +106,12 @@ For general LP/MIP/SOCP modeling, start with the matching package under
skills/cdopt-optimization/SKILL.md
```

For continuous convex QPs solved with OSQP, start with:

```text
skills/osqp-solver/SKILL.md
```

## Repository Layout

```text
Expand All @@ -115,6 +125,7 @@ AI4Math-Optimization/
├── linear-programming/
├── mixed-integer-programming/
├── or-solver/
├── osqp-solver/
└── second-order-cone-programming/
```

Expand Down
15 changes: 13 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

# AI4Math · 优化

面向数学优化建模、求解器配置、LP/MIP/SOCP workflow 和流形约束优化的 AI4Math 技能集合。
面向数学优化建模、求解器配置、LP/MIP/SOCP workflow、连续凸 QP/OSQP
和流形约束优化的 AI4Math 技能集合。

[English](README.md) · [贡献者](CONTRIBUTORS.md) · [技能包](#技能包) · [安装](#安装) · [快速开始](#快速开始) · [安全边界](#安全边界)

![version](https://img.shields.io/badge/version-0.1.0-blue)
![skills](https://img.shields.io/badge/skills-6-2ea44f)
![skills](https://img.shields.io/badge/skills-7-2ea44f)
![license](https://img.shields.io/badge/license-MIT-green)

</div>
Expand All @@ -33,6 +34,7 @@
| [`mixed-integer-programming`](skills/mixed-integer-programming/) | 含 binary、integer 和 continuous 变量的 MILP/MIP 建模。 | [`README`](skills/mixed-integer-programming/README.md) · [`SKILL`](skills/mixed-integer-programming/SKILL.md) |
| [`second-order-cone-programming`](skills/second-order-cone-programming/) | SOCP 建模和基于 cvxpy 的锥优化求解流程。 | [`README`](skills/second-order-cone-programming/README.md) · [`SKILL`](skills/second-order-cone-programming/SKILL.md) |
| [`or-solver`](skills/or-solver/) | 为 OR skills 提供统一求解器检测、安装规划、license 检查和选择策略。 | [`README`](skills/or-solver/README.md) · [`SKILL`](skills/or-solver/SKILL.md) |
| [`osqp-solver`](skills/osqp-solver/) | 面向连续凸 QP 的 OSQP 建模、重复求解、状态门槛与独立验证。 | [`README`](skills/osqp-solver/README.zh-CN.md) · [`SKILL`](skills/osqp-solver/SKILL.md) |

## 安装

Expand All @@ -50,6 +52,7 @@ Skill 路径:
- skills/mixed-integer-programming
- skills/second-order-cone-programming
- skills/or-solver
- skills/osqp-solver

请执行:
1. 本地 clone 或更新仓库。
Expand All @@ -72,6 +75,7 @@ ln -s "$PWD/skills/linear-programming" ~/.codex/skills/linear-programming
ln -s "$PWD/skills/mixed-integer-programming" ~/.codex/skills/mixed-integer-programming
ln -s "$PWD/skills/second-order-cone-programming" ~/.codex/skills/second-order-cone-programming
ln -s "$PWD/skills/or-solver" ~/.codex/skills/or-solver
ln -s "$PWD/skills/osqp-solver" ~/.codex/skills/osqp-solver
```

如果你的 agent 使用别的本地 Skill 目录,把 `~/.codex/skills` 替换成对应配置路径。
Expand All @@ -97,6 +101,12 @@ skills/or-solver/SKILL.md
skills/cdopt-optimization/SKILL.md
```

连续凸 QP 与 OSQP workflow 从这里开始:

```text
skills/osqp-solver/SKILL.md
```

## 仓库结构

```text
Expand All @@ -110,6 +120,7 @@ AI4Math-Optimization/
├── linear-programming/
├── mixed-integer-programming/
├── or-solver/
├── osqp-solver/
└── second-order-cone-programming/
```

Expand Down
2 changes: 2 additions & 0 deletions SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Use this repository as a routing layer for optimization workflows.
- `skills/mixed-integer-programming/`: MIP and MILP modeling workflows.
- `skills/second-order-cone-programming/`: SOCP modeling and solver workflows.
- `skills/or-solver/`: shared optimization solver setup and selection.
- `skills/osqp-solver/`: continuous convex QP modeling, OSQP execution,
status gates, and independent solution or infeasibility-certificate checks.

Prefer package-local instructions over this router when running a concrete
workflow.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies = []

[project.optional-dependencies]
dev = ["pytest>=8.0"]
osqp = ["osqp>=1,<2"]

[tool.pytest.ini_options]
testpaths = ["tests"]
115 changes: 115 additions & 0 deletions skills/osqp-solver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# OSQP Solver Skill

Chinese guide: [README.zh-CN.md](README.zh-CN.md)

This AI4Math skill models, solves, updates, and independently checks continuous
convex quadratic programs with the native OSQP Python interface. It is a
release-ready local candidate for
[`VeryMath/AI4Math-Optimization`](https://github.com/VeryMath/AI4Math-Optimization);
it is not an official upstream package until that repository accepts and merges
it.

## Scope

Use the skill for

\[
\min_x \tfrac12 x^\top P x + q^\top x
\quad\text{subject to}\quad l \leq Ax \leq u,
\qquad P=P^\top\succeq0.
\]

Do not route mixed-integer, nonconvex, nonlinear-constraint, SDP, or general
SOCP models to this package. The bundled JSON runner is an auditable tool for
small dense examples, not a production sparse-data format.

## Isolated installation

Create an isolated environment and install the supported OSQP major version:

```bash
python3 -m venv .venv-osqp
source .venv-osqp/bin/activate
python -m pip install -r requirements-test.txt
python scripts/check_osqp_environment.py --json
```

The probe reports `ready: true` only when `osqp`, `numpy`, and `scipy` import
successfully and the OSQP version is in the supported range. Obtain approval
before installing into an existing environment.

## Quick start

From this package directory:

```bash
python scripts/solve_qp.py references/feasible-example.json
python scripts/solve_qp.py references/primal-infeasible-example.json
python scripts/solve_qp.py references/dual-infeasible-example.json
```

Use `--validate-only` for dependency-free structural validation. It does not
run PSD or numerical solution checks:

```bash
python scripts/solve_qp.py references/feasible-example.json --validate-only
```

For a persistent report, choose a path different from the input:

```bash
python scripts/solve_qp.py references/feasible-example.json \
--output outputs/feasible-result.json
```

## CLI contract and limits

- Successful validation or an accepted solve exits `0`. Input/dependency
failures exit `2`; a rejected numerical status or solver failure exits `3`.
- Standard output is exactly one JSON document on success. Machine-readable
errors are written as exactly one JSON document to standard error.
- Result documents use `schema_version: osqp-solver-result-v1`; structural-only
reports use `osqp-solver-validation-v1`.
- `settings.verbose: true` is rejected because OSQP logging would corrupt the
single-JSON standard-output contract.
- The runner rejects resolved input/output paths that are the same. A distinct
existing output file may be atomically replaced, so use a run-specific path.
- The default dense guard accepts at most a 32 MiB input, `n <= 1000`, and
`2,000,000` logical entries across `P` and `A`. Use the native sparse API for
larger problems.
- An accepted solution must pass primal feasibility, stationarity,
normal-cone/complementarity, objective, and PSD checks. Infeasibility
certificates are normalized and must pass scale-aware residual, sign, and
strict negative-margin checks.

Read [SKILL.md](SKILL.md) for the workflow and
[references/verification.md](references/verification.md) for the mathematical
acceptance conditions.

## Validation

From the AI4Math Skill Library root, with the isolated environment active:

```bash
python -m unittest discover -s tests -p 'test_osqp_solver_skill.py' -v
python scripts/validate_skill_repo.py
```

Do not treat skipped numerical tests as release evidence. The OSQP-enabled
suite must run without skips before publishing; inspect the unittest summary
and require `skipped=0`.

## License, citation, and provenance

This package is intended to follow the AI4Math repository's MIT license after
maintainer authorization and upstream acceptance. The separately installed
OSQP project is Apache-2.0 licensed; this package does not vendor or relicense
OSQP code. Software licensing and academic citation are separate obligations.
Use [references/citation.md](references/citation.md) for the official OSQP
citation.

The workflow and references were prepared from the official OSQP documentation
linked in [references/python-api.md](references/python-api.md). Before public
release, a human maintainer must confirm publication authorization and record
factual contributor attribution. Packaging by an AI agent is not that
authorization.
101 changes: 101 additions & 0 deletions skills/osqp-solver/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# OSQP Solver Skill

English guide: [README.md](README.md)

这个 AI4Math skill 使用原生 OSQP Python 接口,对连续凸二次规划进行建模、求解、
参数更新和独立复核。它目前是
[`VeryMath/AI4Math-Optimization`](https://github.com/VeryMath/AI4Math-Optimization)
的发布就绪本地候选;只有目标仓库接受并合并后,才能称为官方上游 package。

## 适用范围

使用本 skill 处理

\[
\min_x \tfrac12 x^\top P x + q^\top x
\quad\text{subject to}\quad l \leq Ax \leq u,
\qquad P=P^\top\succeq0.
\]

不要把混合整数、非凸、非线性约束、SDP 或一般 SOCP 模型路由到本 package。
附带的 JSON runner 用于可审查的小型 dense 示例,不是生产级 sparse 数据格式。

## 隔离安装

创建隔离环境并安装受支持的 OSQP 主版本:

```bash
python3 -m venv .venv-osqp
source .venv-osqp/bin/activate
python -m pip install -r requirements-test.txt
python scripts/check_osqp_environment.py --json
```

只有 `osqp`、`numpy`、`scipy` 均可导入,而且 OSQP 版本落在支持范围内时,探针才会
报告 `ready: true`。修改已有环境前先取得批准。

## 快速开始

在本 package 目录运行:

```bash
python scripts/solve_qp.py references/feasible-example.json
python scripts/solve_qp.py references/primal-infeasible-example.json
python scripts/solve_qp.py references/dual-infeasible-example.json
```

`--validate-only` 可在不安装数值依赖时做结构校验,但不会执行 PSD 或数值解检查:

```bash
python scripts/solve_qp.py references/feasible-example.json --validate-only
```

需要保存报告时,输出路径必须与输入路径不同:

```bash
python scripts/solve_qp.py references/feasible-example.json \
--output outputs/feasible-result.json
```

## CLI 合同与边界

- 结构校验成功或求解结果被接受时退出码为 `0`;输入/依赖错误为 `2`;数值状态未被
接受或 solver 失败为 `3`。
- 成功时标准输出严格为一个 JSON 文档;机器可读错误严格以一个 JSON 文档写入标准错误。
- 求解报告使用 `schema_version: osqp-solver-result-v1`;仅结构校验的报告使用
`osqp-solver-validation-v1`。
- 拒绝 `settings.verbose: true`,避免 OSQP 日志破坏标准输出的单 JSON 合同。
- runner 会拒绝解析后相同的输入/输出路径,从而保留输入。不同路径上的已有输出文件
可能被原子替换,因此应使用每次运行独立的路径。
- 默认 dense guard 接受的输入最大为 32 MiB,要求 `n <= 1000`,并且 `P` 与 `A`
的 logical entry 总数不超过 `2,000,000`。更大问题应直接使用原生 sparse API。
- 被接受的解必须通过 primal feasibility、stationarity、
normal-cone/complementarity、objective 和 PSD 检查;不可行性证书会先归一化,
再接受尺度化 residual、方向符号和严格负裕量检查。

完整工作流见 [SKILL.md](SKILL.md),数学验收条件见
[references/verification.md](references/verification.md)。

## 验证

激活隔离环境后,在 AI4Math Skill Library 根目录运行:

```bash
python -m unittest discover -s tests -p 'test_osqp_solver_skill.py' -v
python scripts/validate_skill_repo.py
```

被跳过的数值测试不能作为发布证据;公开发布前必须在安装 OSQP 的环境中做到该测试集
零跳过,并检查 unittest 汇总中 `skipped=0`。

## 许可证、引用与来源边界

在维护者授权并被上游接受后,本 package 预期沿用 AI4Math 仓库的 MIT license。
单独安装的 OSQP 项目采用 Apache-2.0 license;本 package 不打包、也不重新许可
OSQP 代码。软件许可和学术引用是两项不同义务。官方 OSQP 引用见
[references/citation.md](references/citation.md)。

本工作流和参考材料依据
[references/python-api.md](references/python-api.md) 所列 OSQP 官方文档整理。
公开发布前,人类维护者必须确认发布授权,并如实记录贡献者署名;AI agent 完成打包
不能替代这项授权。
Loading
Loading