Skip to content

ParametrizedInterpolation: fntype_X_Y(::Type{Real}) MethodError on Initialization on master #4527

Description

@ChrisRackauckas-Claude

Summary

ModelingToolkitStandardLibrary.Blocks.ParametrizedInterpolation cannot build an ODEProblem on current master: building the InitializationProblem raises MethodError: no method matching fntype_X_Y(::Type{Real}). This blocks the Blocks/sources.jl testsuite of SciML/ModelingToolkitStandardLibrary.jl#452 (3 sub-testset errors: LinearInterpolation, BSplineInterpolation, and Initialization).

Reproducer

using ModelingToolkitStandardLibrary.Blocks: ParametrizedInterpolation
using DataInterpolations: LinearInterpolation
using ModelingToolkit, OrdinaryDiffEq, SciMLBase
using ModelingToolkit: t_nounits as t, D_nounits as D

u = rand(15); x = 0:14.0
@variables y(t) = 0
@named i = ParametrizedInterpolation(LinearInterpolation, u, x)
eqs = [i.input.u ~ t, D(y) ~ i.output.u]
@named model = System(eqs, t, systems = [i])
sys = mtkcompile(model)
prob = ODEProblem{true, SciMLBase.FullSpecialize}(sys, [], (0.0, 4.0))
# -> ERROR: MethodError: no method matching fntype_X_Y(::Type{Real})

Stacktrace (head)

ERROR: MethodError: no method matching fntype_X_Y(::Type{Real})

Closest candidates are:
  fntype_X_Y(!Matched::Type{<:SymbolicUtils.FnType{X, Y}}) where {X, Y}
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/.../types.jl:990

[1] promote_symtype(f::BasicSymbolic, args::Type)
    @ SymbolicUtils types.jl:1051
[2] _promote_symtype(f::BasicSymbolic, args::SmallVec{...})
    @ SymbolicUtils types.jl:1075
[3] maketerm(::Type{BasicSymbolic{SymReal}}, f::Any, args, metadata)
    @ SymbolicUtils terminterface.jl:259
[4] substitute_ir!(sub::IRSubstituter{...}, idx::Int32)
    @ SymbolicUtils irstructure.jl:822
[5] IRSubstituter
    @ SymbolicUtils irstructure.jl:838
[6] get_ir_info(sys::System)
    @ ModelingToolkitBase ir_info.jl:54
[7] build_function_wrapper(::System, ...)
    @ ModelingToolkitBase codegen_utils.jl:336
[8] generate_rhs(sys::System; ...)
    @ ModelingToolkitBase codegen.jl:111
[9] (NonlinearFunction{true, SciMLBase.AutoSpecialize})(sys::System; ...)
    @ ModelingToolkitBase nonlinearproblem.jl:12
...
[14] InitializationProblem{true, ...}(sys::System, t::Float64, op; ...)
    @ ModelingToolkitBase initializationproblem.jl:126
...
[19] (ODEProblem{true, SciMLBase.FullSpecialize})(sys::System, op, tspan; ...)
    @ ModelingToolkitBase odeproblem.jl:111

Diagnosis (provisional)

ParametrizedInterpolation declares a callable parameter via

@parameters (interpolator::interp_type)(..)::eltype(u)

i.e. a FnType{X, Y} parameter whose return type is the concrete element type of u (typically Float64). After substitution through IRSubstituter/maketerm, the call-site has a symbolic whose symtype is Real rather than FnType{...}. Then promote_symtype(f::BasicSymbolic, args...) at SymbolicUtils/types.jl:1051 dispatches fntype_X_Y(T) with T == Type{Real}, and the only method defined is

fntype_X_Y(::Type{<: FnType{X, Y}}) where {X, Y} = (X, Y)

So we get a MethodError. The bug is one of:

  1. IRSubstituter/maketerm losing the FnType wrapper while substituting symbols that originated as @parameters (f::T)(..)::R.
  2. Missing fallback fntype_X_Y(::Type) returning (Tuple, T) (or similar) for non-FnType symbols (a defensive workaround).

I'm flagging (1) because the test was passing on this codepath up through ~Feb and started erroring once the IR substitution path landed. (2) is the quick fix but it would just paper over the real loss-of-type-info.

Versions

ModelingToolkit v11.26.0
ModelingToolkitBase v1.35.1
Symbolics v7.23.0
SymbolicUtils v4.29.1
DataInterpolations v8
Julia 1.10

Impact

Currently blocking 3 sub-testsets in Blocks/sources.jl of MTKStdLib (see SciML/ModelingToolkitStandardLibrary.jl#452). The MTKStdLib PR cannot be merged green until this is resolved upstream.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions