Skip to content

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.

CVXPY, pymoo, or skfoliocodeCheck DCP, solver status,units, and holdout hygieneproblems() --adapterMeasure solver status,gaps, residuals, and ParetofrontsFinding ledger andper-problem checkliststart -> plan -> gate ->finish
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

In a Git project, save a small CVXPY problem as solve.py.

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-6

Copy the problem ID from xpd math-opt solve.py --format json | jq -r '.read.problems[0].id' into adapter.py.

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.

Terminal window
$ 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'
optimal

The example check uses tight tolerances for a small fixture. Choose tolerances and fallback behavior that fit the real decision.

  1. Commit the project files and start the ledger with xpd math-opt start solve.py --check "python solve.py" --adapter adapter.py.
  2. List again with the same paths and adapter, then run xpd math-opt plan plan.json with ordered fixes, accepted findings, and checklist verdicts with reasons.
  3. Run xpd math-opt approve <fix> for approved interface changes, commit one fix, and verify it with xpd math-opt gate <fix>.
  4. Resume across sessions with xpd math-opt status. To abandon a fix, restore the last kept commit and run xpd math-opt drop <fix> --reason "<reason>".
  5. Update any revised answers with xpd math-opt plan - and close the run with xpd math-opt finish.

See the command reference for all library adapter schemas, flags, and stage commands.