Skip to content

[CMake 6/7] Initialize CVODES adjoint quadrature derivative buffers - #3508

Open
SteveBronder wants to merge 2 commits into
cmake-split/05-unit-testsfrom
fix/cvodes-adjoint-quadrature-output
Open

SteveBronder wants to merge 2 commits into
cmake-split/05-unit-testsfrom
fix/cvodes-adjoint-quadrature-output

Conversation

@SteveBronder

@SteveBronder SteveBronder commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The adjoint cosine ODE tests fail on Windows x64 with incorrect gradients and on Windows ARM64 with CVodeB error -3 in the CMake CI run. CVODES reuses its quadrature derivative output buffer, but accumulate_adjoints adds to that buffer with +=, retaining stale or uninitialized values between callbacks.

Clear the output before accumulating derivatives. Add an analytic value/gradient regression covering scalar and vector parameters, repeated solves, and repeated reverse passes. This is a solver correctness fix reviewed separately from the CMake infrastructure; existing tolerances stay unchanged.

Tests

  • Observed failures before the fix in the existing adjoint tests and the new regression when allocator poisoning fills reused memory with nonzero bytes (MALLOC_PERTURB_).
  • After the fix, all 56 cosine ODE cases pass ten shuffled repetitions with allocator poisoning; the 12 adjoint/regression cases pass ten repetitions with a second poison value.
  • ARM64 Linux under QEMU: the regression fails before the fix and passes three repetitions after it.
  • Windows x64 and ARM64 LLVM-Mingw cross-compilation passes with -Wall -Werror; native Windows runtime validation remains for CI.
  • Dependency checks, cpplint, and git diff --check pass.

Side Effects

Adjoint quadrature derivatives no longer depend on previous output-buffer contents. Public APIs and solver tolerances are unchanged.

Release notes

Fix incorrect adjoint ODE parameter gradients and intermittent CVODES backward-integration failures caused by stale quadrature output.

Checklist

  • Copyright holder: Simons Foundation
  • New value and gradient regression added
  • Focused validation passes as described above
  • Complete CI matrix passes
  • C++ idioms and Doxygen documentation have completed review

Related PRs

Native stack: https://github.com/stan-dev/math/stack/3509

Clear the quadrature derivative output before accumulating adjoints.
Cover analytic values and gradients across repeated solves and reverse passes.
@WardBrian
WardBrian force-pushed the fix/cvodes-adjoint-quadrature-output branch from 005153a to 77455ad Compare November 6, 2026 20:06

This branch has not been deployed

No deployments
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.

1 participant