Skip to content

Conversation

SebastianM-C
Copy link
Contributor

@SebastianM-C SebastianM-C commented Oct 14, 2025

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add wrapper for https://github.com/MadNLP/MadNLP.jl

Currently MadNLP does not support user defined callbacks :( I'll look into PRing that after this gets in.

While working on the tests I also found a couple of bugs in the AD subpackages and fixed them with some help from Claude Code. Should I PR the fixes separately? This passes the tests locally, but in CI it fails due to what I fixed in 90b5b1c

Speaking of bugs, I think the SecondOrder warning has a bug when AutoSparse is used, but I'm not sure if I should address that now. I see

┌ Warning: The selected optimization algorithm requires second order derivatives, but `SecondOrder` ADtype was not provided. 
│         So a `SecondOrder` with AutoSparse(dense_ad=SecondOrder(AutoForwardDiff(), AutoReverseDiff())) for both inner and outer will be created, this can be suboptimal and not work in some cases so 
│         an explicit `SecondOrder` ADtype is recommended.
└ @ OptimizationBase ~/.julia/dev/Optimization/lib/OptimizationBase/src/cache.jl:49

This is currently WIP, it needs

  • [ ] callback support
  • [ ] progress support
  • more tests

Interface wise, I'm wondering if I should make the linear_solver and kkt_system more easily accessible instead of being in the additional options. The reason for the current approach is that MadNLP picks the defaults for those based on the system and in our optimizer struct we don't have the system yet. One option would be to use some dummy value that is then later translated internally.

@SebastianM-C SebastianM-C changed the title Smc/madnlp Add OptimizationMadNLP Oct 14, 2025
@SebastianM-C SebastianM-C force-pushed the smc/madnlp branch 2 times, most recently from 14ce037 to 90f20ed Compare October 16, 2025 02:06
@SebastianM-C SebastianM-C marked this pull request as ready for review October 16, 2025 02:08
lagrangian, soadtype, x, Constant(one(eltype(x))),
Constant(ones(eltype(x), num_cons)), Constant(p), strict = Val(false))
lag_hess_prototype = zeros(Bool, num_cons, length(x))
lag_hess_prototype = zeros(Bool, length(x), length(x))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the Hessian a square n*n matrix with n being the length of the vector we're taking derivatives against? All the tests that I've added error with out of bounds memory access otherwise. The tests don't catch this because we don't actually call with the generated prototype.

@ChrisRackauckas
Copy link
Member

MadNLP tests failing

@SebastianM-C
Copy link
Contributor Author

SebastianM-C commented Oct 16, 2025

yeah, it's due to the bug fixed in 90b5b1c, there are several bugs that lead to CI failures on the latest releases, which is why I was wondering if I should split those to a separate PR

@SebastianM-C SebastianM-C mentioned this pull request Oct 16, 2025
5 tasks
@SebastianM-C
Copy link
Contributor Author

I split the bugfixes to #1069

@SebastianM-C
Copy link
Contributor Author

I rebased, I'll bump the OptimizationBase compat once we have a release

SebastianM-C and others added 12 commits October 16, 2025 15:47
This is a wrapper for https://github.com/MadNLP/MadNLP.jl

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
no support in MadNLP :(
Co-authored-by: Claude <noreply@anthropic.com>
Fixes dimension mismatch errors when using sparse Lagrangian Hessians & corrects constraint Jacobian structure initialization

Co-authored-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Ensure Hessian buffers are created with numeric type T instead of
inheriting Bool from sparsity prototypes. Fixes InexactError when
storing Hessian values.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@ChrisRackauckas ChrisRackauckas merged commit 72c3e67 into SciML:master Oct 16, 2025
36 of 79 checks passed
@ChrisRackauckas
Copy link
Member

Needs a follow up with a doc page, but since this is at least correct let's start the 3 day timer.

@SebastianM-C SebastianM-C deleted the smc/madnlp branch October 16, 2025 15:40
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