Skip to content

Fix Issue #995#1383

Open
arn97 wants to merge 1 commit intoSciML:masterfrom
arn97:fix-issue-995
Open

Fix Issue #995#1383
arn97 wants to merge 1 commit intoSciML:masterfrom
arn97:fix-issue-995

Conversation

@arn97
Copy link

@arn97 arn97 commented Mar 2, 2026

Fixes a failure in GaussAdjoint when p === nothing.

Previously, the GaussAdjoint path assumed tunables supports length and Functors traversal. When p === nothing, this resulted in errors (e.g. length(::Nothing) or recursive traversal failures), causing Zygote.gradient(..., nothing) to error.

The fix represents the no-parameter case using an empty tunables container (Float64[]) while preserving repack = _ -> nothing to maintain RHS semantics. This allows Zygote.gradient(..., nothing) to correctly return (nothing,), consistent with InterpolatingAdjoint.

Checklist

  • Appropriate tests were added: No new tests were added; verified with a minimal reproducer.
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated: Not applicable; internal fix
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Testing:

  1. Ran Pkg.test() locally.
  2. Confirmed the reproduction snippet from Issue Nothing handling for GaussAdjoint #995 now succeeds: Zygote(loss2, nothing) returns nothing as expected.

Docs:
No documentation updates were required (internal fix; no public API changes).

I have not yet added a dedicated regression test; I can add one if you can point me to the preferred test location/pattern for SciMLSensitivity.

…of p === nothing: Use an empty tunables container instead of nothing to avoid length/Functors errors, while preserving repack = _ -> nothing. Enables Zygote.gradient(loss2, nothing) to return (nothing,).]
# minimal fix 4 for #995
#---------------------------------------------------
if p === nothing
tunables = Float64[] # 0-length, Functors-safe
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 necessarily typed correctly, and would result in doing unnecessary computations

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