Repository navigation
Fix three bugs before patch release - #130
Conversation
1. prob.value had the wrong sign for maximization problems. The function return value was de-negated, but the value written to prob.value was the raw (negated) subproblem value. Now set prob.value from the original objective so the sign matches the problem sense, in both the single-init and multi-init paths. 2. The constraint-convexification damping loop was unbounded and could hang forever when damping could not recover a valid linearization point (e.g. a variable outside a function's domain). It is now bounded by max_iter_damp and raises NonDCCPError, mirroring the objective path. Extracted into _convexify_constr_with_damping. 3. Multi-restart initializations (k_ccp > 1) ignored the configured seed, so seed= did not make restart runs reproducible. Restarts now derive a distinct, reproducible seed per restart via _restart_seed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@d-002 these are other bugs that I will fix in the v1.1.1 patch release. If you have anything else you would like fixed besides the bug you already identified, post here. |
prob.value is typed as a union that doesn't support > / float(), so coerce via float(...) with a type: ignore (matching the existing test pattern) before comparing. CI runs pyright over tests too. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Hi, Edit: after a discussion with Gemini, it appears this warning could be suppressed, as it means CVXPY converted a sparse array into a dense one in a specific case where it could lead to loss of performance. |
|
Thanks! The warning turned out to be only fixable on the cvxpy side, and it's also spurious (just checking if something is None). But I'll create a cvxpy issue about it. For the moment I suppressed the warnings. |
DCCP creates sparse-pattern gradient parameters for efficiency and sets them via .value_sparse, but cvxpy's solve loop still reads .value on those leaves, emitting a "Reading from a sparse CVXPY expression via `.value` is discouraged" RuntimeWarning on every solve. Scope a filter for that one message around the public dccp() entry point and around _solve_one_init (re-applied there since the parallel path runs in a worker process that does not inherit the parent's filters). Add regression tests that reset the warning filters to verify DCCP's own suppression, not the pytest config. Tracked upstream: cvxpy/cvxpy#3367. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Three bugs found while auditing the codebase ahead of the patch release. Each is covered by a new regression test.
🔴 1.
prob.valuehad the wrong sign for maximization problemsThe
dccp()return value was correctly de-negated forMaximize, but the value written toprob.valuewas the raw (negated) subproblem value. So a solved maximization problem returned the right number whileprob.valueheld its negation.Fixed in both the single-init (
_solve) and multi-init (solve_multi_init) paths by settingprob.valuefrom the original objective after writing the variables back, so the sign matches the problem sense.🔴 2. Infinite loop in constraint convexification damping
The constraint-convexification damping loop was unbounded (
while c_conv is None:), unlike the objective path which is bounded bymax_iter_damp. When damping could not recover a valid linearization point (e.g. a variable lands outside a function's domain such assqrt/logand_apply_dampingis a no-op for it), the solve hung forever. Now bounded bymax_iter_dampand raisesNonDCCPError, mirroring the objective path. Extracted into_convexify_constr_with_damping.🟡 3.
seedignored for multi-restart runs_solve_multi_sequential/_solve_multi_parallelcalledinitialize(..., random=True)without passing the configuredseed, soseed=did not make multi-restart (k_ccp > 1) runs reproducible. Restarts now derive a distinct, reproducible per-restart seed via_restart_seed.Testing
uv run pytest: 85 passed, 1 skipped (was 63; added 4 regression tests)uv run ruff check: cleanuv run pyright: 0 errors🤖 Generated with Claude Code