Skip to content

Conversation

@simenhu
Copy link

@simenhu simenhu commented Dec 9, 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

BacksolveAdjoint now works with SciMLStructures

@ChrisRackauckas-Claude
Copy link
Contributor

I've rebased this PR onto the latest master to resolve the merge conflicts.

The rebased branch is available at: https://github.com/ChrisRackauckas-Claude/SciMLSensitivity.jl/tree/feature/custom_structs_backsolve_adjoint

@simenhu To update your PR with the rebased changes, you can run:

git remote add claude https://github.com/ChrisRackauckas-Claude/SciMLSensitivity.jl.git
git fetch claude feature/custom_structs_backsolve_adjoint
git checkout feature/custom_structs_backsolve_adjoint
git reset --hard claude/feature/custom_structs_backsolve_adjoint
git push --force origin feature/custom_structs_backsolve_adjoint

The rebase resolved the following conflicts in src/derivative_wrappers.jl:

  1. Added both the gclosure1/gclosure2 helper functions from master AND the repack_ode_function from this PR
  2. Combined the Enzyme.Duplicated logic to use the PR's tunables approach for SciMLStructures and master's shadow_p optimization for regular parameters

Co-Authored-By: Chris Rackauckas [email protected]

@ChrisRackauckas-Claude
Copy link
Contributor

Opened a rebased version of this PR at #1335.

claude and others added 4 commits January 21, 2026 12:51
Minor optimization: cache the result of isscimlstructure(p) in a local
variable to avoid calling it twice in the hot _vecjacobian! path.

Co-Authored-By: Chris Rackauckas <[email protected]>
Performance optimization: use the pre-cached wrapped function (pf) from
S.diffcache.pf instead of calling repack_ode_function in every
_vecjacobian! call. The function wrapping is already done during setup
in adjoint_common.jl, so we can reuse it directly.

This avoids:
- Closure creation in the hot path
- Calling repack inside the closure on every ODE evaluation

Co-Authored-By: Chris Rackauckas <[email protected]>
…ions

The closure was only defined for inplace signature (du, u, p, t), but
out-of-place functions need (u, p, t) signature. Added isinplace parameter
to generate the correct closure based on the function type.

Co-Authored-By: Chris Rackauckas <[email protected]>
For some sensitivity algorithms (QuadratureAdjoint, etc.), pf is set to
nothing in adjointdiffcache. Fall back to the original behavior of using
SciMLBase.Void(f) for inplace or f for out-of-place when pf is nothing.

Co-Authored-By: Chris Rackauckas <[email protected]>
@simenhu simenhu force-pushed the feature/custom_structs_backsolve_adjoint branch from 0e9e939 to d7661ab Compare January 28, 2026 14:51
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.

3 participants