Skip to content

Add requiresconsvjp/requiresconsjvp and tighten allowsconsvjp/allowsconsjvp to matrix-free products - #1622

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
SebastianM-C:smc/requires-cons-vjp-jvp
Sep 28, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
SebastianM-C:smc/requires-cons-vjp-jvp

Conversation

@SebastianM-C

Copy link
Copy Markdown
Member

The constraint-product traits only had an allows* form, so function-instantiation code (OptimizationBase) could not tell a solver that merely can use cons_vjp apart 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-supplied cons_j, or a forward-mode backend for a vjp). For solvers that already fall back to cons_j this buys nothing and costs an extra Jacobian preparation and an m×n buffer, and it also meant a user's cons_j was silently replaced by an AD Jacobian of cons.

This adds the missing half and states the contract for both:

  • requiresconsvjp(opt) / requiresconsjvp(opt) (new, public, default false): 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 to false.

No behavior changes in this package: the new traits default to false and the allows* 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 in OptimizationCache, has AugLag declare requiresconsvjp, and gives the NLPModels adaptor (used by MadNLP) a cons_j fallback.

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

…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
SebastianM-C force-pushed the smc/requires-cons-vjp-jvp branch from 6843a44 to 07b1709 Compare September 28, 2026 09:38
@SebastianM-C
SebastianM-C marked this pull request as ready for review September 28, 2026 11:45
@ChrisRackauckas
ChrisRackauckas merged commit 0106b17 into SciML:master Sep 28, 2026
65 of 73 checks passed
@SebastianM-C
SebastianM-C deleted the smc/requires-cons-vjp-jvp branch September 28, 2026 16:33
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