Skip to content

Commit 37ae899

Browse files
Fix callable interpolation builder symtype
Register CachedInterpolation's symbolic result as a callable Real-to-Real value, derived through public SymbolicUtils APIs. Add a regression that calls the bound interpolator before building and solving the ODEProblem. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent aa22067 commit 37ae899

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/Blocks/Blocks.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Blocks
55
using ModelingToolkitBase: ModelingToolkitBase, @component, @connector, @named,
66
@parameters, @unpack, System, compose, connect, extend,
77
getdefault, t_nounits as t, D_nounits as D
8+
using SymbolicUtils: @syms, symtype
89
using Symbolics: Symbolics, @register_symbolic, @variables, Differential, Equation
910
import Base: ifelse
1011
import ..@symcheck

src/Blocks/sources.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,15 @@ end
864864

865865
Base.nameof(::CachedInterpolation) = :CachedInterpolation
866866

867-
@register_symbolic (f::CachedInterpolation)(u::AbstractArray, x::AbstractArray, args::Tuple)
867+
const _INTERPOLATOR_SYMTYPE = let
868+
@syms interpolator(::Real)::Real
869+
symtype(interpolator)
870+
end
871+
872+
# Calling the builder returns the interpolation function, not an interpolated scalar.
873+
@register_symbolic (f::CachedInterpolation)(
874+
u::AbstractArray, x::AbstractArray, args::Tuple
875+
)::_INTERPOLATOR_SYMTYPE
868876

869877
"""
870878
ParametrizedInterpolation(interp_type, u, x, args...; name, t = ModelingToolkitBase.t_nounits)

test/sources.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using SymbolicIndexingInterface
1414
using SciMLStructures: SciMLStructures, Tunable
1515
using ForwardDiff
1616
using ADTypes
17+
using SymbolicUtils: symtype
1718

1819
@testset "Constant" begin
1920
@named src = Constant(k = 2)
@@ -650,6 +651,9 @@ end
650651

651652
@testset "LinearInterpolation" begin
652653
@named i = ParametrizedInterpolation(LinearInterpolation, u, x)
654+
interpolator = only(values(bindings(i)))
655+
@test symtype(interpolator(0.0)) === Real
656+
653657
eqs = [i.input.u ~ t, D(y) ~ i.output.u]
654658

655659
@named model = System(eqs, t, systems = [i])

0 commit comments

Comments
 (0)