Skip to content

Upcoming CVXPY change (#3525) breaks ConvexProgram.to_conic #20

Closed

Description

@Transurgeon

Hello Tobia, we've been cleaning up some CVXPY code and unfortunately it has a small effect on GSCOPT.

Here's the suggested fix message which was generated by Claude (but it summarizes things quite well!):

An upcoming CVXPY change, cvxpy#3525, moves cone formatting out of the individual solver interfaces and into its own reduction, ConeFormat, appended to the solving chain immediately before the solver. Previously each conic interface applied the layout itself inside apply().

That changes what gcsopt/programs.py:222 gives you:

chain = cp_convex._construct_chain(solver_opts=solver_opts)
chain.reductions = chain.reductions[:-1]   # strips the solver only

ConeFormat is now reductions[-2], so [:-1] keeps it and the program comes back already in the solver's cone layout — Zero rows negated, and multi-cone SOC/exp rows interleaved cone-major. _constrain_in_cone (programs.py:76) decodes CVXPY's stuffed layout instead, so the two no longer agree.

The test suite here catches it. Against a CVXPY build with #3525, tests/test_programs.py::TestConvexProgram::test_to_conic fails with the conic round-trip returning inf where the convex program gives -0.95477…; the other 19 tests pass.

Fix

Filter the solver-facing steps rather than slicing off the last one — the same thing CVXPY does internally in reductions/dcp2cone/canonicalizers/perspective_canon.py, which needed it for exactly this reason:

+from cvxpy.reductions.solvers.solver import Solver
+try:  # cvxpy applies the solver's cone layout as its own chain step
+    from cvxpy.reductions import ConeFormat
+    _SOLVER_FACING = (Solver, ConeFormat)
+except ImportError:  # cvxpy <= 1.9
+    _SOLVER_FACING = (Solver,)

         chain = cp_convex._construct_chain(solver_opts=solver_opts)
-        chain.reductions = chain.reductions[:-1]
+        chain.reductions = [r for r in chain.reductions
+                            if not isinstance(r, _SOLVER_FACING)]

Thank you! and please let me know if you have any questions about this :).

Activity

  1. TobiaMarcucci commented on Sep 15, 2026

    @TobiaMarcucci
    Owner

    Thank you very much for letting me know! That fix seems easy enough to try when the new release is out. Can you please ping me when you publish the cvxpy release so that I try that fix? Thanks again!

  2. Transurgeon commented on Sep 15, 2026

    @Transurgeon
    Author

    Thank you very much for letting me know! That fix seems easy enough to try when the new release is out. Can you please ping me when you publish the cvxpy release so that I try that fix? Thanks again!

    yes of course, I'll keep that in mind!
    It should be out in CVXPY 1.10 which would be in a few months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions