Repository navigation
Conversation
CVXPY's MOREAU interface moves constraints on variables (x >= 0, nonneg=True, PSD=True, SOC/exp/power cones on variables) out of the rows of A into `dir_cones`. cvxpylayers built Moreau's cones from the cone dimensions alone, so these constraints were silently dropped. - Pass `dir_cones` to MOREAU_ctx and set them on moreau.Cones. - For psd_triangle direct cones, apply CVXPY's sqrt(2) off-diagonal scaling (solve in x_solver = scale * x) in the Torch and JAX paths, including constant P/A setup and the JAX warm-start cache. - Append Moreau's direct-cone duals (z_x) to the dual vector and map those constraints' duals in parse_args, so their dual variables can still be requested. Fixes #252 Claude-generated. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Collaborator
|
I think #248 is the better approach here |
Collaborator
Author
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.
Fixes #252.
Problem
With
solver="MOREAU", CVXPY moves constraints on variables (x >= 0,nonneg=True,PSD=True, and SOC/exp/power cones on variables) out of the rows ofAintodata["dir_cones"]. cvxpylayers built Moreau'sConesfrom the cone dimensions alone, so the layer silently ignored these constraints. On cvxpy 1.9.3 this also caused 26 failures in the existingtest_moreau.py/test_moreau_dual_variables.py.Changes
get_solver_ctxpassesdir_conestoMOREAU_ctx, which sets them onmoreau.Cones(as CVXPY's own interface does).x_solver = scale * x.MOREAU_ctxprecomputes a scale for each CSR nonzero. The Torch and JAX paths scaleP,Aandqand unscale the primal, and so does the constant-P/Asetup()path. The JAX warm-start cache stores the scaled primal, since that is Moreau's coordinate system.param_probis cached by CVXPY and shared between layers built from the same problem, so rescaling it in place would compound.z_x. Both backends now appendz_xto the dual vector, and_build_constr_id_to_slicemaps those constraints after the conic rows. Soconstraint.dual_variables[0]for e.g.x >= 0still works, including gradients.Only MOREAU produces
dir_cones, so other solvers are unaffected.Tests
New
tests/test_moreau_direct_cones.pycovers each direct-cone kind: nonneg constraint, nonneg attribute, SOC, exp, power, PSD (quadratic) and PSD with a parameter inA. It checks:A.Locally (cvxpy 1.9.3, moreau 0.4.1, CPU):
pytest tests/gives 288 passed and 3 failed. The 3 failures (test_torch.py::test_sdpand 2 DIFFCP dual gradchecks intest_dual_variables.py) also fail on master. CUDA paths were not tested.Found while working on this (not fixed here)
Building a second MOREAU layer from the same
cp.Problemgives wrong results, even on master and without direct cones (reproduced with MOREAU only; CUCLARABEL/MPAX share the code path but were not tested).get_solver_ctxre-permutes CVXPY's cachedparam_prob.reduced_{P,A}.reduced_matin place on every build. I'll leave that for a separate issue/PR.🤖 Generated with Claude Code