Skip to content

Conversation

@Transurgeon
Copy link
Member

  • Simplify _verify_hess_vec_args and _verify_jacobian_args in log.py and exp.py to check self.args[0].is_affine() instead of requiring isinstance(Variable)
  • Remove _hess_vec methods from both atoms (NLP solver handles derivatives via C diff engine)
  • Fix _extract_affine_as_linear_op in converters.py to create column vector (n_vars, 1) instead of row vector for compatibility with C new_linear function
  • Add comprehensive test suite for affine argument handling including gradient verification, Hessian structure tests, edge cases, and constraint tests

Transurgeon and others added 2 commits January 19, 2026 13:03
* Implement diag_vec Jacobian for NLP solving

- Add _jacobian() and _hess_vec() methods to diag_vec atom for NLP support
- Fix diagonal variable value propagation in CvxAttr2Constr reduction
- Add tests for diagonal variables in NLP problems

The diag_vec Jacobian maps input vector positions to diagonal matrix
positions using the formula i*(n+1) for Fortran-order flattening.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Handle sparse value initialization for diag variables in NLP

When a diag variable has its value stored as a sparse matrix (e.g., after
solving), np.diag() fails on it. This adds a check for sparse values and
uses .diagonal() to extract the diagonal elements correctly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
- Simplify _verify_hess_vec_args and _verify_jacobian_args in log.py
  and exp.py to check self.args[0].is_affine() instead of requiring
  isinstance(Variable)
- Remove _hess_vec methods from both atoms (NLP solver handles
  derivatives via C diff engine)
- Fix _extract_affine_as_linear_op in converters.py to create column
  vector (n_vars, 1) instead of row vector for compatibility with C
  new_linear function
- Add comprehensive test suite for affine argument handling including
  gradient verification, Hessian structure tests, edge cases, and
  constraint tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Transurgeon Transurgeon marked this pull request as draft January 20, 2026 20:08
@github-actions
Copy link

github-actions bot commented Jan 20, 2026

Benchmarks that have stayed the same:

   before           after         ratio
 [2ed0cd09]       [2b198459]
     41.5±0ms         43.8±0ms     1.06  matrix_stuffing.SmallMatrixStuffing.time_compile_problem
      321±0ms          336±0ms     1.05  gini_portfolio.Yitzhaki.time_compile_problem
      13.7±0s          14.3±0s     1.04  finance.CVaRBenchmark.time_compile_problem
      293±0ms          304±0ms     1.04  matrix_stuffing.ParamSmallMatrixStuffing.time_compile_problem
      942±0ms          971±0ms     1.03  gini_portfolio.Cajas.time_compile_problem
      246±0ms          252±0ms     1.02  simple_QP_benchmarks.SimpleQPBenchmark.time_compile_problem
      236±0ms          241±0ms     1.02  gini_portfolio.Murray.time_compile_problem
      148±0ms          151±0ms     1.02  high_dim_convex_plasticity.ConvexPlasticity.time_compile_problem
      1.47±0s          1.50±0s     1.02  matrix_stuffing.ParamConeMatrixStuffing.time_compile_problem
      927±0ms          939±0ms     1.01  simple_LP_benchmarks.SimpleScalarParametrizedLPBenchmark.time_compile_problem
     14.3±0ms         14.4±0ms     1.01  simple_QP_benchmarks.ParametrizedQPBenchmark.time_compile_problem
      1.90±0s          1.92±0s     1.01  simple_QP_benchmarks.UnconstrainedQP.time_compile_problem
      690±0ms          696±0ms     1.01  matrix_stuffing.ConeMatrixStuffingBench.time_compile_problem
      1.07±0s          1.08±0s     1.01  finance.FactorCovarianceModel.time_compile_problem
      3.22±0s          3.23±0s     1.00  quantum_hilbert_matrix.QuantumHilbertMatrix.time_compile_problem
      289±0ms          290±0ms     1.00  slow_pruning_1668_benchmark.SlowPruningBenchmark.time_compile_problem
      4.39±0s          4.40±0s     1.00  huber_regression.HuberRegression.time_compile_problem
      5.10±0s          5.10±0s     1.00  optimal_advertising.OptimalAdvertising.time_compile_problem
      854±0ms          852±0ms     1.00  simple_QP_benchmarks.LeastSquares.time_compile_problem
      548±0ms          546±0ms     1.00  semidefinite_programming.SemidefiniteProgramming.time_compile_problem
      5.15±0s          5.11±0s     0.99  svm_l1_regularization.SVMWithL1Regularization.time_compile_problem
      1.65±0s          1.64±0s     0.99  tv_inpainting.TvInpainting.time_compile_problem
      23.0±0s          22.6±0s     0.98  sdp_segfault_1132_benchmark.SDPSegfault1132Benchmark.time_compile_problem
      11.8±0s          11.5±0s     0.97  simple_LP_benchmarks.SimpleLPBenchmark.time_compile_problem
     15.2±0ms         14.5±0ms     0.95  simple_LP_benchmarks.SimpleFullyParametrizedLPBenchmark.time_compile_problem

Transurgeon and others added 4 commits January 20, 2026 15:35
Use is_affine() check instead of isinstance(Variable) so that any
affine expression (e.g., 2*x + 3) passes through without creating
unnecessary auxiliary variables and equality constraints.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Keep AFFINE_ARG_ATOMS special handling for coefficient extraction
while incorporating latest diffengine-setup changes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add diag_vec to ATOM_CONVERTERS for cp.diag(vector) support
- Add automatic reshape when linear_op flattens matrix expressions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants