Review numerical optimization
Run xpd math-opt <paths> to check CVXPY, pymoo, and skfolio formulations, inspect real solver statuses and residuals, catch portfolio holdout leakage, and gate changes against project tolerances.
What xpd math-opt checks
Section titled “What xpd math-opt checks”| Group | Finding kinds | What it catches |
|---|---|---|
| Formulation | non-dcp-problem, constraint-unit-mismatch |
Non-DCP CVXPY expressions and mismatched constraint units |
| Solving | unchecked-solver-status |
Reading problem.value without checking problem.status |
| Portfolio validation | fit-on-holdout |
Fitting a skfolio estimator on holdout returns |
| Pack rules | pack-rule |
Built-in cvxpy, pymoo, skfolio, and pymc pack findings |
Measure an actual solution
Section titled “Measure an actual solution”In a Git project, save a small CVXPY problem as solve.py.
import cvxpy as cp
def build(): x = cp.Variable() problem = cp.Problem(cp.Minimize(cp.abs(x)), [x >= 1]) return problem
if __name__ == "__main__": problem = build() problem.solve(solver="SCS", eps_abs=1e-8, eps_rel=1e-8) assert problem.status == cp.OPTIMAL assert abs(problem.value - 1) < 1e-6 assert problem.constraints[0].violation() < 1e-6Copy the problem ID from xpd math-opt solve.py --format json | jq -r '.read.problems[0].id' into adapter.py.
from solve import build
def problems(): return { "<problem-id>": { "library": "cvxpy", "problem": build(), "solve_kwargs": {"solver": "SCS", "eps_abs": 1e-8, "eps_rel": 1e-8}, }, }The adapter reports the solver status and measured facts for the problem.
$ git init -q$ python solve.py$ sed -i "s/<problem-id>/$(xpd math-opt solve.py --format json | jq -r '.read.problems[0].id')/" adapter.py$ xpd math-opt solve.py --adapter adapter.py --format json | jq -r '.read.facts.problems[0].facts["solver-status"].value.status'optimalThe example check uses tight tolerances for a small fixture. Choose tolerances and fallback behavior that fit the real decision.
Record and finish
Section titled “Record and finish”- Commit the project files and start the ledger with
xpd math-opt start solve.py --check "python solve.py" --adapter adapter.py. - List again with the same paths and adapter, then run
xpd math-opt plan plan.jsonwith ordered fixes, accepted findings, and checklist verdicts with reasons. - Run
xpd math-opt approve <fix>for approved interface changes, commit one fix, and verify it withxpd math-opt gate <fix>. - Resume across sessions with
xpd math-opt status. To abandon a fix, restore the last kept commit and runxpd math-opt drop <fix> --reason "<reason>". - Update any revised answers with
xpd math-opt plan -and close the run withxpd math-opt finish.
See the command reference for all library adapter schemas, flags, and stage commands.