Skip to content

fix: promote the output array of initialization to the tunable eltype#4469

Merged
AayushSabharwal merged 5 commits into
SciML:masterfrom
SebastianM-C:smc/init_promotion
May 7, 2026
Merged

fix: promote the output array of initialization to the tunable eltype#4469
AayushSabharwal merged 5 commits into
SciML:masterfrom
SebastianM-C:smc/init_promotion

Conversation

@SebastianM-C
Copy link
Copy Markdown
Member

@SebastianM-C SebastianM-C commented Apr 23, 2026

This adresses the cases where the we generate output arrays from fully constant RHS, which would end up being incompatible with the elype of parameters in ForwardDiff and other similar contexts.

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

After digging through what's going on in #4457 with Claude I think that I found a fix. The issue is that we generate observed functions that hardcode Vector{Float64} regardless of the eltype of the tunables which ends up defeating the u0 promotion mechanisms that we have.

This should fix #4457 and probably #3924 too, I think that the underlying issue is the same, but #4457 is the simpler reproducer.

Copy link
Copy Markdown
Member

@AayushSabharwal AayushSabharwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments.

Comment thread lib/ModelingToolkitBase/test/initializationsystem.jl Outdated
Comment thread lib/ModelingToolkitBase/test/initializationsystem.jl Outdated
Comment thread lib/ModelingToolkitBase/test/initializationsystem.jl Outdated
Copy link
Copy Markdown
Member

@AayushSabharwal AayushSabharwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged #4459 and this needs a rebase now 😅 but otherwise looks good.

@SebastianM-C SebastianM-C force-pushed the smc/init_promotion branch 2 times, most recently from 4faee0d to ddc82e4 Compare April 27, 2026 15:46
@SebastianM-C
Copy link
Copy Markdown
Member Author

rebased

@AayushSabharwal
Copy link
Copy Markdown
Member

This PR introduces failures in the initialization test group

@SebastianM-C SebastianM-C force-pushed the smc/init_promotion branch from ddc82e4 to 33acf53 Compare May 2, 2026 00:31
SebastianM-C and others added 3 commits May 6, 2026 23:54
This adresses the cases where the
we generate output arrays from
fully constant RHS, which would
end up being incompatible
with the elype of parameters
in ForwardDiff and other similar
contexts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Aayush Sabharwal <aayush.sabharwal@gmail.com>
Co-authored-by: Aayush Sabharwal <aayush.sabharwal@gmail.com>
@SebastianM-C SebastianM-C force-pushed the smc/init_promotion branch from 33acf53 to 65b1ac4 Compare May 6, 2026 21:23
SebastianM-C and others added 2 commits May 7, 2026 00:31
Hardcoding Float64 silently promoted Float32
problems to Float64. Threading floatT preserves
user-chosen precision while still rescuing
integer RHS, and the dynamic tunable eltype
read from nlsol still wins for ForwardDiff.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

Float64(::ForwardDiff.Dual{..}) error when using initialization_eqs

2 participants