Fix Clarabel PSD cone permutation for multiple cones#77
Merged
SteveDiamond merged 1 commit intocvxgrp:masterfrom Jan 21, 2026
Merged
Fix Clarabel PSD cone permutation for multiple cones#77SteveDiamond merged 1 commit intocvxgrp:masterfrom
SteveDiamond merged 1 commit intocvxgrp:masterfrom
Conversation
Two bugs fixed in solve_internal() for Clarabel: 1. Wrong start_row increment: Changed from `start_row += v` to `start_row += v * (v + 1) // 2` because for a PSD cone of dimension n, the vectorized representation has n*(n+1)/2 elements. 2. Missing inverse permutation: Added inverse_permute_psd_solution() to convert y and s from Clarabel's upper-triangular convention back to SCS's lower-triangular convention after solving. The first bug caused incorrect row permutations when problems have multiple PSD cones - the second cone's permutation was applied to the wrong rows, scrambling the problem. Includes comprehensive tests verifying solution and constraint satisfaction match between SCS and Clarabel solvers.
SteveDiamond
approved these changes
Jan 21, 2026
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.
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: