-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enhance atom validation with NumPy and improve error messages #2976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Replaces custom validation with NumPy's input validation using mock arrays. Improves error messages by adding CVXPY context. Adds missing test_hstack coverage. This addresses the atoms specifically mentioned in cvxpy#2613 and improves error message traceability as requested in cvxpy#2620. Other atoms may benefit from similar improvements in future work.
Transurgeon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@7astro7 really nice changes! and sorry it took some time to review your PR. I had some comments, but mostly to discuss the error message and structure of the code. Otherwise your changes look great, thanks for cleaning up lots of stacking functionality :).
- Consolidate validation: validate_arguments() now calls shape_from_args() - Add cp. prefix to error messages for clarity - Eliminates code duplication while maintaining error handling
|
Benchmarks that have improved:
Benchmarks that have stayed the same: |
* Various fixes to help CVXPYlayers (cvxpy#2951) * Removes assert that prevents canonicalizing without parameter values * renames c -> q in the ParamConicProg so it has the same API as ParamQuadProg * Fixes a bug in the tests * Fixes a bug * Fix qoco links (cvxpy#2963) * Bump astral-sh/setup-uv from 6 to 7 (cvxpy#2967) Bumps [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) from 6 to 7. - [Release notes](https://github.com/astral-sh/setup-uv/releases) - [Commits](astral-sh/setup-uv@v6...v7) --- updated-dependencies: - dependency-name: astral-sh/setup-uv dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Fixes .name() for multiply expressions and HiGHS tests (cvxpy#2983) * Fixes .name() for multiply expressions * Fixes tests lol * Fixes HiGHS tests * Bump github/codeql-action from 3.30.6 to 4.31.2 (cvxpy#2986) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.30.6 to 4.31.2. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@64d10c1...0499de3) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 4.31.2 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * adding variable bounds to PDLP (cvxpy#2974) * adding variable bounds to pdlp * add check for none variable bounds --------- Co-authored-by: William Zijie Zhang <[email protected]> * Fix issue 1222 (cvxpy#2971) * dev container + powconeND template * working on supporting powconeND * added more support for powconeND * trying to add support for ND cone * tested passing generalized power cones to clarabel * continuing working on nd, new example * preliminary version, pre-dual handling. Need to check axis * fixed axis handling, starting tests for general variable orderin * tested variable switching for powconeND * fix shape problems for power cone nd dual vars * fix shape problems for power cone nd dual vars * found bug in conversion of nd->3d cones * clean-up changes, removed stale TODOs, more testing * "cleaning up" * moved checking for exotic constraints to within each solver loop * slight logic improvement * removed stale TODOs and cleaned up code * fixed powconeND shape property when axis=1 * implemented additional checks in solving_chain, made powconeND tests compatible with cvxpy test set * improved testing depth and readability * suggested changes by Steven and William * added explanation in power.py * fixed bug causing unnecessary constraints to be added to the problem * removed redundant axis checks in cone_matrix_stuffing * Removed stale note in power.py Removed note about potential 3-tuple return type. * Extend sum_largest/sum_smallest to support float k and optimize cvar implementation (cvxpy#2985) * support float k in sum_largest and sum_smallest * support float k in lambda_sum_largest and lambda_sum_smallest * reimplement cvar using sum_largest instead of dotsort * Enhance atom validation with NumPy and improve error messages (cvxpy#2976) * Use NumPy validation in hstack, vstack, concatenate, and sum Replaces custom validation with NumPy's input validation using mock arrays. Improves error messages by adding CVXPY context. Adds missing test_hstack coverage. This addresses the atoms specifically mentioned in cvxpy#2613 and improves error message traceability as requested in cvxpy#2620. Other atoms may benefit from similar improvements in future work. * Refactor per reviewer feedback - Consolidate validation: validate_arguments() now calls shape_from_args() - Add cp. prefix to error messages for clarity - Eliminates code duplication while maintaining error handling * Update cuopt_conif.py for cuopt 25.10 (cvxpy#2989) * Added feasibility example (cvxpy#2990) * Added feasibility example + associated test * Added feasibility example + associated test * Modified feasibility speedup test to ensure same rng * Apply suggestions from code review Co-authored-by: Parth Nobel <[email protected]> --------- Co-authored-by: Parth Nobel <[email protected]> * CI: change copt write test to use pytest skipif (cvxpy#2993) * change copt write test to use pytest skipif * change gurobi as well * revret changes to sum --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Parth Nobel <[email protected]> Co-authored-by: Govind Chari <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: William Zijie Zhang <[email protected]> Co-authored-by: Nika Zahedi <[email protected]> Co-authored-by: David Pérez Piñeiro <[email protected]> Co-authored-by: Zak Kraehling <[email protected]> Co-authored-by: Trevor McKay <[email protected]> Co-authored-by: RyuGood0 <[email protected]> Co-authored-by: Parth Nobel <[email protected]>
* Use NumPy validation in hstack, vstack, concatenate, and sum Replaces custom validation with NumPy's input validation using mock arrays. Improves error messages by adding CVXPY context. Adds missing test_hstack coverage. This addresses the atoms specifically mentioned in #2613 and improves error message traceability as requested in #2620. Other atoms may benefit from similar improvements in future work. * Refactor per reviewer feedback - Consolidate validation: validate_arguments() now calls shape_from_args() - Add cp. prefix to error messages for clarity - Eliminates code duplication while maintaining error handling
* adding MIP warmstart for XPRESS (#2945) Co-authored-by: Marc Bataillou Almagro <[email protected]> * Support for cvxpy.convolve into complex2real, fix sparse convolutions in Scipy (#2947) * Add support for cvxpy.convolve into complex2real Altough cvxpy.conv is supported, cvxpy.convolve is a different atom and thus requires to be explicitly specified in order to be supported. Fixes #2946 * Add a test for complex cp.conv and cp.convolve * Fix sparse convolution for the Scipy backend If the lhs operand has zeroes in it, they get consumed by the .tocoo call. This means that the amount of nonzero elements computed beforehand is no longer correct, yielding a dimension mismatch a few lines later. This is a tentative attempt at fixing this, should be carefully analyzed by someone that can actually read this numpy juggling. Fixes #2949 * passing original variable names and constraint ids to improve debugging (#2948) Co-authored-by: Marc Bataillou Almagro <[email protected]> * Revert "Passing original variable names and constraint ids to improve debugging" (#2950) * Revert "passing original variable names and constraint ids to improve debuggi…" This reverts commit 9fb1974. * Revert "patch empty breaking empty rownames for xpress>=9.5 (#2745)" This reverts commit 6870f5f. * Revert "adding MIP warmstart for XPRESS (#2945)" This reverts commit 9e36b12. --------- Co-authored-by: William Zijie Zhang <[email protected]> * Update Python version in devcontainer configuration (#2955) * consolidate warmstart and varname changes (#2957) * Various fixes to help CVXPYlayers (#2951) * Removes assert that prevents canonicalizing without parameter values * renames c -> q in the ParamConicProg so it has the same API as ParamQuadProg * Fixes a bug in the tests * Fixes a bug * Fix qoco links (#2963) * Fixes .name() for multiply expressions and HiGHS tests (#2983) * Fixes .name() for multiply expressions * Fixes tests lol * Fixes HiGHS tests * adding variable bounds to PDLP (#2974) * adding variable bounds to pdlp * add check for none variable bounds --------- Co-authored-by: William Zijie Zhang <[email protected]> * Enhance atom validation with NumPy and improve error messages (#2976) * Use NumPy validation in hstack, vstack, concatenate, and sum Replaces custom validation with NumPy's input validation using mock arrays. Improves error messages by adding CVXPY context. Adds missing test_hstack coverage. This addresses the atoms specifically mentioned in #2613 and improves error message traceability as requested in #2620. Other atoms may benefit from similar improvements in future work. * Refactor per reviewer feedback - Consolidate validation: validate_arguments() now calls shape_from_args() - Add cp. prefix to error messages for clarity - Eliminates code duplication while maintaining error handling * Extend sum_largest/sum_smallest to support float k and optimize cvar implementation (#2985) * support float k in sum_largest and sum_smallest * support float k in lambda_sum_largest and lambda_sum_smallest * reimplement cvar using sum_largest instead of dotsort * Update cuopt_conif.py for cuopt 25.10 (#2989) * CI: change copt write test to use pytest skipif (#2993) * change copt write test to use pytest skipif * change gurobi as well * Make get_problem_data work with gp = True and parameter values not set (#3005) * make get_problem_data work with dgp and no param values * add tests for get_problem_data(gp=True, ...) with no param values * clearer comment and another test * fix comment for tests * more comments --------- Co-authored-by: Marc Bataillou Almagro <[email protected]> Co-authored-by: Marc Bataillou Almagro <[email protected]> Co-authored-by: Josef Gajdusek <[email protected]> Co-authored-by: Parth Nobel <[email protected]> Co-authored-by: Nika Zahedi <[email protected]> Co-authored-by: Govind Chari <[email protected]> Co-authored-by: William Zijie Zhang <[email protected]> Co-authored-by: Zak Kraehling <[email protected]> Co-authored-by: David Pérez Piñeiro <[email protected]> Co-authored-by: Trevor McKay <[email protected]> Co-authored-by: Steven Diamond <[email protected]>
Summary
Replaces custom validation logic with NumPy's input validation for better robustness and error messages.
Changes
np.empty)AxisErrorhandling and contextual error wrappingAxisAtomvalidation with NumPy'ssum-specific validationtest_hstack(was missing) and update error assertionsIssues
This addresses the atoms specifically mentioned in #2613 and improves error message traceability as requested in #2620. Other atoms may benefit from similar improvements in future work.
Addresses #2613
Addresses #2620
Type of change
Contribution checklist