Skip to content

Conversation

@7astro7
Copy link
Contributor

@7astro7 7astro7 commented Oct 27, 2025

Summary

Replaces custom validation logic with NumPy's input validation for better robustness and error messages.

Changes

  • hstack, vstack: Replace custom validation with NumPy delegation using mock arrays (np.empty)
  • concatenate: Enhance existing NumPy validation by adding AxisError handling and contextual error wrapping
  • sum: Override AxisAtom validation with NumPy's sum-specific validation
  • Error messages: Wrap all NumPy errors with CVXPY context (e.g., "Invalid arguments for hstack: ...")
  • Tests: Add comprehensive test_hstack (was missing) and update error assertions

Issues

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

  • New feature (backwards compatible)
  • New feature (breaking API changes)
  • Bug fix
  • Other (Documentation, CI, ...)

Contribution checklist

  • Add our license to new files.
  • Check that your code adheres to our coding style.
  • Write unittests.
  • Run the unittests and check that they’re passing.
  • Run the benchmarks to make sure your change doesn’t introduce a regression.

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.
Copy link
Collaborator

@Transurgeon Transurgeon left a 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
@github-actions
Copy link

github-actions bot commented Nov 4, 2025

Benchmarks that have improved:

   before           after         ratio
 [1344f030]       [22b339bc]
  •    53.0±0ms         44.5±0ms     0.84  matrix_stuffing.SmallMatrixStuffing.time_compile_problem
    

Benchmarks that have stayed the same:

   before           after         ratio
 [1344f030]       [22b339bc]
      3.30±0s          3.60±0s     1.09  quantum_hilbert_matrix.QuantumHilbertMatrix.time_compile_problem
      1.72±0s          1.79±0s     1.05  tv_inpainting.TvInpainting.time_compile_problem
      311±0ms          320±0ms     1.03  slow_pruning_1668_benchmark.SlowPruningBenchmark.time_compile_problem
      258±0ms          264±0ms     1.03  simple_QP_benchmarks.SimpleQPBenchmark.time_compile_problem
      11.9±0s          12.1±0s     1.02  simple_LP_benchmarks.SimpleLPBenchmark.time_compile_problem
      5.38±0s          5.47±0s     1.02  svm_l1_regularization.SVMWithL1Regularization.time_compile_problem
      575±0ms          583±0ms     1.01  simple_QP_benchmarks.ParametrizedQPBenchmark.time_compile_problem
      1.14±0s          1.15±0s     1.01  gini_portfolio.Cajas.time_compile_problem
      876±0ms          881±0ms     1.01  simple_QP_benchmarks.LeastSquares.time_compile_problem
      291±0ms          292±0ms     1.01  matrix_stuffing.ParamSmallMatrixStuffing.time_compile_problem
      1.92±0s          1.93±0s     1.00  simple_QP_benchmarks.UnconstrainedQP.time_compile_problem
      744±0ms          744±0ms     1.00  matrix_stuffing.ConeMatrixStuffingBench.time_compile_problem
      2.36±0s          2.35±0s     1.00  simple_LP_benchmarks.SimpleFullyParametrizedLPBenchmark.time_compile_problem
      23.1±0s          23.0±0s     0.99  sdp_segfault_1132_benchmark.SDPSegfault1132Benchmark.time_compile_problem
      1.14±0s          1.13±0s     0.99  finance.FactorCovarianceModel.time_compile_problem
      1.00±0s          992±0ms     0.99  simple_LP_benchmarks.SimpleScalarParametrizedLPBenchmark.time_compile_problem
      4.80±0s          4.74±0s     0.99  huber_regression.HuberRegression.time_compile_problem
      14.0±0s          13.9±0s     0.99  finance.CVaRBenchmark.time_compile_problem
      249±0ms          244±0ms     0.98  high_dim_convex_plasticity.ConvexPlasticity.time_compile_problem
      1.42±0s          1.37±0s     0.97  matrix_stuffing.ParamConeMatrixStuffing.time_compile_problem
      251±0ms          242±0ms     0.97  gini_portfolio.Murray.time_compile_problem
      563±0ms          544±0ms     0.97  semidefinite_programming.SemidefiniteProgramming.time_compile_problem
      360±0ms          347±0ms     0.96  gini_portfolio.Yitzhaki.time_compile_problem
      5.26±0s          5.02±0s     0.96  optimal_advertising.OptimalAdvertising.time_compile_problem

@PTNobel PTNobel merged commit b09db0a into cvxpy:master Nov 4, 2025
43 of 44 checks passed
Transurgeon added a commit to cvxgrp/DNLP that referenced this pull request Nov 12, 2025
* 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]>
Transurgeon pushed a commit that referenced this pull request Nov 24, 2025
* 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
@Transurgeon Transurgeon mentioned this pull request Nov 24, 2025
Transurgeon added a commit that referenced this pull request Nov 24, 2025
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants