Repository navigation
Add requiresconsvjp/requiresconsjvp and tighten allowsconsvjp/allowsconsjvp to matrix-free products - #1622
Merged
ChrisRackauckas merged 1 commit intoSep 28, 2026
Conversation
…duct traits `allowsconsvjp`/`allowsconsjvp` could not distinguish a solver that can use a constraint product (and falls back to `cons_j` otherwise) from one that calls it unconditionally, so function-instantiation code had to always provide the product, materializing the full Jacobian when that was the only way. Add `requiresconsvjp`/`requiresconsjvp` for solvers that must be given the product, and document that `allows*` products should only be provided when they are matrix-free. All four default to `false`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
SebastianM-C
force-pushed
the
smc/requires-cons-vjp-jvp
branch
from
September 28, 2026 09:38
6843a44 to
07b1709
Compare
SebastianM-C
marked this pull request as ready for review
September 28, 2026 11:45
ChrisRackauckas
referenced
this pull request
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The constraint-product traits only had an
allows*form, so function-instantiation code (OptimizationBase) could not tell a solver that merely can usecons_vjpapart from one that calls it unconditionally. OptimizationBase therefore always generated the product, even when the only way to do that was to materialize the full constraint Jacobian (a user-suppliedcons_j, or a forward-mode backend for a vjp). For solvers that already fall back tocons_jthis buys nothing and costs an extra Jacobian preparation and an m×n buffer, and it also meant a user'scons_jwas silently replaced by an AD Jacobian ofcons.This adds the missing half and states the contract for both:
requiresconsvjp(opt)/requiresconsjvp(opt)(new, public, defaultfalse): the solver must be given the product, even if it has to be built through the full Jacobian.allowsconsvjp(opt)/allowsconsjvp(opt): the solver can use the product but has its own fallback, so it should only be provided when it does not materialize the Jacobian (user-supplied, or a native reverse / forward mode of the AD backend). A solver that requires a product should declare both traits; like the other traits, both default tofalse.No behavior changes in this package: the new traits default to
falseand theallows*change is to their documented contract. The only code that implements that contract, and the only consumers of these traits I could find on GitHub, are in SciML/Optimization.jl. The consumer side is SciML/Optimization.jl#1363, which uses the traits inOptimizationCache, has AugLag declarerequiresconsvjp, and gives the NLPModels adaptor (used by MadNLP) acons_jfallback.Also: docs entries,
@public, and the public-interface test list. Version bumped to 3.57.0 since this adds public API.Written by Claude Code on Sebastian's behalf.
🤖 Generated with Claude Code · model: claude-opus-5-5[1m]
Review: unreviewed