xpd math-opt
Use xpd math-opt to review CVXPY, pymoo, and skfolio problem definitions, solver results and validation.
Run xpd math-opt <paths> --limit 0 --format json to list read.problems, read.facts, findings and checklist. Problem IDs come from repository-relative paths and qualified definition sites. Comments above a definition do not change its ID. The inventory skips dynamic factories and ambiguous bindings. A static-only list has null read.facts. Use --questions to print the catalog without scanning or running an adapter.
$ xpd math-opt --questions --format json | jq -c '{facts:(.facts|length),questions:(.questions|length)}'{"facts":12,"questions":12}xpd math-opt [OPTIONS] [PATHS]... xpd math-opt <COMMAND>Subcommands
Section titled “Subcommands”| Subcommand | What it does |
|---|---|
xpd math-opt start |
Start a run: record the commit it starts from, the paths, line count, checks and optional benchmark of the project |
xpd math-opt plan |
Record the plan of a round: the fixes in order, and the findings that are right as they are |
xpd math-opt approve |
Record that the user said yes to a fix that changes what callers or users see |
xpd math-opt gate |
Gate a fix that is committed: run the checks, time --bench when set, count lines and compare the findings with the commit before it. Exit 1 when the fix is not kept |
xpd math-opt drop |
Record that a fix was given up, after its files were restored |
xpd math-opt status |
Print the run and the stage that comes next |
xpd math-opt finish |
End the run: compare findings, line count and benchmark timing with the start commit. Exit 1 while a fix is open or a new finding has no reason |
Arguments
Section titled “Arguments”| Argument | What it does |
|---|---|
<PATHS>... |
Files or directories (directories respect .gitignore) |
Options
Section titled “Options”| Option | Default | What it does |
|---|---|---|
--kind <KIND> |
List only the findings of these kinds, separated by commas. Repeatable. Values: non-dcp-problem, unchecked-solver-status, constraint-unit-mismatch, fit-on-holdout, pack-rule. |
|
--limit <LIMIT> |
20 |
The most findings to list of each kind, strongest first. 0 lists every finding. |
--since <COMMIT> |
Count the findings at this commit too, and print each count beside the count of today. | |
--group-by <GROUP_BY> |
none |
Group findings and checklist items by owning module or shared cause. Values: none (Keep the default flat per-kind listing), module (Group findings and checklist items by owning module path), cause (Group related findings by shared kind and anchor files). |
--packet <N> |
Emit one 1-indexed deterministic context-budgeted review packet for the Nth cluster. | |
--budget-lines <LINES> |
300 |
Maximum source lines included across excerpts inside a --packet view. |
--all-modules |
Include checklist review items for every surveyed module, not only modules with findings. | |
--format <FORMAT> |
Output format. Default: text on a terminal, json otherwise. Values: text, json. |
|
--adapter <ADAPTER> |
Project Python adapter or shell command that emits solver facts. | |
--questions |
Print the evidence catalog without surveying files. |
Recorded stages
Section titled “Recorded stages”| Command | Result |
|---|---|
xpd math-opt start |
Record committed paths, optional adapter and baseline project checks. |
xpd math-opt <paths> |
List problems, findings, facts and checklist items. |
xpd math-opt plan |
Record fixes, accepted findings and reasoned checklist answers. |
xpd math-opt approve |
Approve an interface change. |
xpd math-opt gate |
Compare committed surveys and run the checks that passed at start. |
xpd math-opt drop |
Explain an abandoned fix after restoring the last kept commit. |
xpd math-opt status |
Read the run and next stage. |
xpd math-opt finish |
Close the run when fixes, findings and checklist items are settled. |
Adapters
Section titled “Adapters”Use --adapter adapter.py or pass a command that prints normalized JSON. Adapters run at the selected project root. Commit the adapter and its inputs before recording a run. The Python runner calls problems(), which returns one descriptor per inventory ID.
| Library | Descriptor fields |
|---|---|
cvxpy |
problem and optional solve_kwargs. |
skfolio |
runs, each with an estimator, fit_args, fit_indices, optional fit_kwargs and optional evaluation_indices. Index positions must share an input axis. |
pymoo |
problem, algorithm, seed, termination, checkpoint generations in checkpoints, a fixed reference_point for multiobjective problems and optional positive objective_scales. |
Any descriptor can declare matrices as a name-to-array mapping. To label a matrix, provide a mapping with matrix, role and units. Use unmeasured with a reason for an intentionally unmeasured problem.
Commands emit the same {"problems":[{"id":"<id>","library":"cvxpy","facts":{}}]} shape as read.facts, with one entry per inventory ID. Each measured fact includes value and method. An unavailable value is null and includes a reason. Use the catalog for fact names. Invalid payloads fail a list or recorded action.
See the optimization review guide for a recorded example.
Recorded example
Section titled “Recorded example”Save this as solve.py.
import cvxpy as cp
def solve(): x = cp.Variable() p = cp.Problem(cp.Minimize(cp.abs(x)), [x >= 1]) p.solve(solver="SCS", eps_abs=1e-8, eps_rel=1e-8) return p.valueCommit it alongside this project check in solution.py.
from solve import solve
assert abs(solve() - 1) < 1e-6$ git init -q && git config user.name Example && git config user.email example@example.invalid && git config commit.gpgsign false && git add solve.py solution.py && git commit -qm 'Record the solve'$ xpd math-opt start solve.py --check 'python solution.py' --format json | jq -r '.next.stage'plan$ xpd math-opt solve.py --limit 0 --format json | jq -c '[.findings[].kind]'["unchecked-solver-status"]$ xpd math-opt solve.py --format json | jq '{fixes:[{id:"fix-status",title:"Check solver status",findings:[.findings[].id]}]}' | xpd math-opt plan - --format json | jq -r '.next.stage'fixUpdate the return to run only under if p.status == cp.OPTIMAL: and commit the fix. The gate reads the new code and reruns the solution check.
$ python -c 'from pathlib import Path; p = Path("solve.py"); p.write_text(p.read_text().replace(" return p.value", " if p.status == cp.OPTIMAL:\n return p.value"))' && git add solve.py && git commit -qm 'Check solver status'$ xpd math-opt gate fix-status --format json | jq -r '.run.rounds[-1][0].outcome'kept$ xpd math-opt solve.py --format json | jq -c '[.findings[].kind]'[]Inspect the checklist and record your reasons before finishing. The scratch review accepts the items with a reason because it makes no allocation decision.
$ xpd math-opt solve.py --format json | jq '{answered:[.checklist[]|{item:.id,verdict:"accepted",reason:"Scratch solve verified against its known optimum; no allocation decision is made."}]}' | xpd math-opt plan - --format json | jq -r '.next.stage'plan$ xpd math-opt finish --format json | jq -r '.next.stage'xpd: 1 findings at the start, 0 now: 1 fixed, 0 added, 0 accepted, 0 left without a reason; lines 8 -> 9finishedExit status
Section titled “Exit status”A successful list or stage exits 0. A rejected gate or blocked finish exits 1. Invalid input and adapter errors exit 2.