Skip to content

[Ready for review] Adds problem struct, neg and promote atoms and a lot more tests#5

Merged
Transurgeon merged 31 commits intomainfrom
problem-struct
Jan 9, 2026
Merged

[Ready for review] Adds problem struct, neg and promote atoms and a lot more tests#5
Transurgeon merged 31 commits intomainfrom
problem-struct

Conversation

@Transurgeon
Copy link
Collaborator

This PR adds the problem struct. It is currently still in draft mode because I have yet to give a thorough review of what Claude has vibed out. But I think it is mostly in a good state, so I thought you could have a look and give some initial feedback.

I have added your feedback and made sure the problem struct would use pointers for the jacobian, gradient and constraint values. The constraints are stored as a pointer to a pointer.. I think it makes sense, since we want to know where the list begins in memory.

I will also try to cleanup the tests and review them more carefully.

The next step will be to shortcut the expression trees and form the A matrices of affine arguments using the CoeffExtractor. I had initial doubts that it would work.. but after more thought being put into it I think it will work just fine.
My concern was as follows: we might have to build the corresponding x in \phi(Ax) by retrieving the variables that appear in the tree and zeroing out everything else. However, this is not true, since the A in question is global, the columns of variables that don't appear will already be filled with zeros.. so we can actually replace the entire affine subtree with this A in the convert method.

@dance858
Copy link
Collaborator

dance858 commented Jan 5, 2026

I did a quick scan and it looks good. But I want to go through it very carefully once you think it's ready.

Add some more tests, and carefully check them. For example, in test_problem.h there seems to be no test for a problem with several constraints.

Nice job!

@Transurgeon Transurgeon changed the title Draft: Adds problem struct and more tests [Ready for review] Adds problem struct, neg and promote atoms and a lot more tests Jan 6, 2026
Copy link
Collaborator Author

@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.

I think this is good to go.. many more changes since we last talked, but I have a much better understanding of the tests (I did look at them, finally) and the overall code structure.
Here's the structure:

  • test_native.py just tests manual formation of a problem using the python bindings. By manual, I mean trees are formed manually.
  • test_unconstrained.py tests the objective and gradient of many different problems.
  • test_constrained.py tests the constraint forward and jacobian for many other different problems.
  • I also added a few C tests (similar to test_native) and some Claude generated tests for neg and promote (please double check those and the implementations carefully.. they seem fine at first glance, but maybe some subtle errors can be there).

Let's go man! Huge progress today. Next step will be to add the retrieval of LinearOperators and getting them to work.

@dance858
Copy link
Collaborator

dance858 commented Jan 6, 2026

Huge progress man! You're a machine.

I left a few comments.

Perhaps it's good if you don't add any code with new functionality to this PR. It would be nice to get it merged soon!

Transurgeon and others added 5 commits January 6, 2026 12:40
Split Python binding functions into separate header files:
- atoms/: one file per atom type (variable, constant, linear, log,
  exp, add, sum, neg, promote)
- problem/: one file per method (make_problem, init_derivatives,
  objective_forward, constraint_forward, gradient, jacobian)

Removed standalone forward/jacobian bindings (use problem_* instead).
bindings.c now only contains includes and module definition.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Values are now accessed directly from the problem struct:
- prob->constraint_values for constraint forward results
- prob->gradient_values for objective gradient
- prob->stacked_jac for constraint jacobian

Also updated Python bindings and tests to use the new API.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dance858
Copy link
Collaborator

dance858 commented Jan 7, 2026

Nice, we're getting there. I left a few easy to fix comments

Transurgeon and others added 2 commits January 7, 2026 15:48
- Replace manual loops with memcpy for copying row pointers and column
  indices in neg.c and promote.c
- Move workspace allocation from eval_wsum_hess to wsum_hess_init in
  promote.c, using memset to zero before use
- Remove unused promote_expr struct (had no extra fields beyond base)
- Simplify new_promote to use new_expr directly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- promote.c: Use memcpy for wsum_hess values in eval_wsum_hess
- problem.c: Simplify row pointer loop to directly copy cjac->p with offset

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Transurgeon
Copy link
Collaborator Author

@dance858 just committed fixes to your review, thanks again!
I am literally so useless without Claude haha.. but it is what it is, its a great tool and we are getting stuff done :).

@dance858
Copy link
Collaborator

dance858 commented Jan 8, 2026

@dance858 just committed fixes to your review, thanks again! I am literally so useless without Claude haha.. but it is what it is, its a great tool and we are getting stuff done :).

You are a machine man! A well-crafted machine from Canada. Keep the good work up.

This matches CVXPY's promote atom behavior which only broadcasts scalars
to vectors/matrices. Removes vector-to-vector promotion support and
the associated dwork allocation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Transurgeon and others added 2 commits January 8, 2026 14:16
- Use memcpy instead of loops for copying jacobian indices and values
- Use pointer arithmetic style (ptr + offset) instead of &ptr[offset]
- Remove unnecessary nnz == 0 guard in jacobian_init
- Move jacobian tests from forward_pass/ to jacobian_tests/

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dance858
Copy link
Collaborator

dance858 commented Jan 9, 2026

Awesome, I'm approving this PR now. Once you have fixed the small comments above, please merge it.

Very nice job WZZ!!!

Transurgeon and others added 4 commits January 9, 2026 12:07
Remove duplicate function definition that was causing compilation errors,
likely introduced during merge from main.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace manual element-by-element array assertions with helper functions
for cleaner, more maintainable test code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Relocate test_neg_jacobian and test_neg_chain from forward_pass/affine/
to jacobian_tests/ for better test organization.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Transurgeon Transurgeon merged commit 56a5bc9 into main Jan 9, 2026
9 checks passed
@dance858 dance858 deleted the problem-struct branch January 11, 2026 10:37
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