Fix Clarabel PSD cone permutation for multiple cones #77
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.
Summary
Fix two bugs in
solve_internal()when using Clarabel with PSD cones.Problem
When using
diffcp.solve_and_derivative(..., solve_method='CLARABEL')with problems containing multiple PSD cones, the solution was incorrect. For example, a problem with optimal objective ~0.088 would return ~1.3e-10.Root Cause
Two bugs in the Clarabel code path:
Bug 1: Wrong
start_rowincrement (line 542)For a PSD cone of dimension
n(an n×n matrix), the vectorized representation hasn*(n+1)/2elements, notn. This caused incorrect row permutations when problems have multiple PSD cones.Bug 2: Missing inverse permutation for
yandsAfter solving with Clarabel, the returned
yandsvectors are in Clarabel's upper-triangular convention but were not permuted back to SCS's lower-triangular convention.Added
inverse_permute_psd_solution()function to handle this conversion.Testing
Added comprehensive test file
tests/test_clarabel_psd.pywith 6 tests:test_multiple_psd_cones_objective_match- verifies fix for the reported issuetest_single_psd_cone- single PSD cone works correctlytest_mixed_cones- problems with zero, nonneg, and PSD conestest_constraint_satisfaction- verifies Ax + s = btest_derivative_lsqr_mode- derivatives work in lsqr modetest_psd_permutation_logic- permutation logic is correctVerification
Before fix:
After fix: