Add ConvexOptimization subpackage (disciplined convex programming backend)#1263
Draft
ChrisRackauckas-Claude wants to merge 2 commits into
Draft
Conversation
…kend) New lib/ConvexOptimization: solves a SciMLBase.ConvexOptimizationProblem by certifying convexity with SymbolicAnalysis.jl, lowering the affine objective and each ConeConstraint to MathOptInterface via Symbolics.linear_expansion, and solving with a conic solver (default Clarabel). Returns a ConvexOptimizationSolution carrying primal AND dual multipliers — the optimality certificate OptimizationSolution lacks. Primary purpose: verify the new SciMLBase ConvexOptimizationProblem / ConvexOptimizationSolution interface (SciML/SciMLBase.jl#1440) end to end. - Routing: ConvexOptimizationProblem is a sibling of OptimizationProblem, so the backend defines SciMLBase.init(::ConvexOptimizationProblem, alg) and SciMLBase.solve!(::ConvexOptimizationCache); solve = solve! ∘ init via CommonSolve. - Constraints: Vector{ConeConstraint}, each pairing a callable affine map g(u,p)->Vector with an MOI cone, giving 1:1 constraint→dual alignment and construction-time dual signs (duals already in user variables). - Scope: LP + second-order-cone constraints; non-convex objectives are rejected by certification, not mis-solved. Blocked on SciML/SciMLBase.jl#1440 (the problem/solution types are unreleased); the [sources] git-rev is a temporary bridge until it lands. Verified locally: Pkg.test() Core 15/15 pass (LP primal+dual machine-exact vs analytic/Convex.jl, SOC solve, non-convex rejection, cache glue). Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…imizationSolution SciMLBase v3.36.0 registers ConvexOptimizationProblem and folds the convex solution into the single OptimizationSolution (with a type-stable `dual` field), removing ConvexOptimizationSolution. So: - Drop the temporary [sources] git-rev to the SciMLBase #1440 branch and bump the compat floor to SciMLBase = "3.36" (the release carrying the types). - Use OptimizationSolution instead of ConvexOptimizationSolution in the backend and its test; the solve already returns the one struct with duals populated (build_convex_solution defaults calculate_dual = Val(true)). Verified against released SciMLBase 3.36.0: resolves, LP/SOC solves return correct primal + dual, non-convex objective rejected; all core tests pass. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Draft / experimental, and blocked on SciML/SciMLBase.jl#1440 (the
ConvexOptimizationProblem/ConvexOptimizationSolutiontypes are unreleased). Please ignore until reviewed by @ChrisRackauckas. CI will be red until #1440 merges and SciMLBase releases — the[sources]git-rev is a temporary bridge.New
lib/ConvexOptimizationsubpackage: the disciplined-convex-programming backend for the SciML optimization stack, and the first vertical slice of the Convex.jl / cvxpy replacement effort (SymbolicAnalysis.jl#121).What it does
solve(::ConvexOptimizationProblem, ConvexMOI(Clarabel.Optimizer)):analyze), erroring (route-to-NLP) if not — a non-convex problem is rejected, never silently mis-solved.ConeConstraintto MathOptInterface viaSymbolics.linear_expansion.optimizer_constructor).ConvexOptimizationSolutioncarrying the primal and the dual multipliers — the optimality certificate thatOptimizationSolutionlacks (OptimizationMOI never surfaces duals).Purpose of this PR
Primarily to verify the new SciMLBase interface end-to-end — that a
ConvexOptimizationProblemconstructs,solveroutes to a backend, and aConvexOptimizationSolutionwith correct duals comes back. It does.Design notes
ConvexOptimizationProblem <: AbstractOptimizationProblemis a sibling ofOptimizationProblem, and OptimizationBase'ssolve/initdispatch on the concreteOptimizationProblem, so the standard indirection is not inherited. The backend therefore definesSciMLBase.init(::ConvexOptimizationProblem, alg)andSciMLBase.solve!(::ConvexOptimizationCache);solve=solve! ∘ initcomposes them via CommonSolve.ConvexOptimizationProblem.constraintsfield): aVector{ConeConstraint}, eachConeConstraint(g, set)pairing a callable affine mapg(u,p)->Vectorwith an MOI cone. This is symmetric with the callable objective (one tracing path), gives exact 1:1 constraint→dual alignment, and fixes the dual sign at construction (>=→Nonnegatives,<=→Nonpositives,==→Zeros) so the returnedConstraintDualis already in the user's variables — verified to match Convex.jl with no sign flip.Scope (MVP)
Affine objective + affine-in-cone constraints (LP), plus second-order-cone constraints. A
norm2-in-objective epigraph atom (add auxt,[t; Ax+b] ∈ SOC) and the full symbolic atom→cone canonicalizer are the next steps.Verification
Pkg.test()locally (against the #1440 SciMLBase branch): Core 15/15 pass, coveringmin x₁+2x₂ s.t. x₁+x₂=1, x≥0→ primal[1,0], obj1, duals[1](equality) and[0,1](nonneg cone) — machine-exact vs the analytic values (which equal Convex.jl's);min t s.t. ‖(x₁,x₂)‖≤t, x=(3,4)→t=5);x₁x₂) rejected by certification;u0/pglue fields.An optional Convex.jl cross-check is included (skipped when Convex isn't in the env, since the analytic assertions already pin the same numbers).
🤖 Generated with Claude Code