It looks like tracing the function fails due to Interpolations.jl. Not really sure what I can do about that, since if I wrote my own interpolation function it would surely require conditionals. The second part of the function not shown here involves FFTs, which is likely even harder to trace…
using FastSymbolicDifferentiation, Symbolics
using ForwardDiff, DiffResults, PreallocationTools, Interpolations
using BenchmarkTools
struct SimApp
# variables
nx::Int
Δt::Float64
Δx::Float64
# coordinates
x::AbstractRange
end
SimApp(nx, Δt) = SimApp(nx, Δt, 2π / nx, range(0., 2π*(1-1/nx), nx))
function step(y, app::SimApp)
# initialize interpolation
itp = interpolate(y, BSpline(Linear(Periodic())))
sitp = scale(itp, app.x)
extp = extrapolate(sitp, Periodic())
# interpolate solution at departure points
x_back = app.x .- app.Δt * y
y_intp = extp.(x_back)
return y_intp
end
julia> @variables u[1:64];
julia> nu = [Node(u_i) for u_i ∈ u];
julia> app = SimApp(64, 0.02);
julia> fs = step!(nu, app)
TypeError: non-boolean (SymbolicUtils.BasicSymbolic{Bool}) used in boolean context
Stacktrace:
[1] is_zero
@ ~/Projects/FastSymbolicDifferentiation/FastSymbolicDifferentiation.jl/src/ExpressionGraph.jl:113 [inlined]
[2] simplify_check_cache(#unused#::typeof(*), na::Float64, nb::Node{SymbolicUtils.BasicSymbolic{Real}, 0}, cache::IdDict{Any, Any})
@ Main.FastSymbolicDifferentiation ~/Projects/FastSymbolicDifferentiation/FastSymbolicDifferentiation.jl/src/ExpressionGraph.jl:161
[3] *(a::Float64, b::Node{SymbolicUtils.BasicSymbolic{Real}, 0})
@ Main.FastSymbolicDifferentiation ~/.julia/packages/SymbolicUtils/H684H/src/methods.jl:54
[4] Interpolations.BSplineInterpolation(#unused#::Type{Float64}, A::OffsetArrays.OffsetVector{Node{SymbolicUtils.BasicSymbolic{Real}, 0}, Vector{Node{SymbolicUtils.BasicSymbolic{Real}, 0}}}, it::BSpline{Linear{Periodic{OnCell}}}, axs::Tuple{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}})
@ Interpolations ~/.julia/packages/Interpolations/nDwIa/src/b-splines/b-splines.jl:104
[5] interpolate
@ ~/.julia/packages/Interpolations/nDwIa/src/b-splines/b-splines.jl:166 [inlined]
[6] interpolate
@ ~/.julia/packages/Interpolations/nDwIa/src/b-splines/b-splines.jl:189 [inlined]
[7] step!(y::OffsetArrays.OffsetVector{Node{SymbolicUtils.BasicSymbolic{Real}, 0}, Vector{Node{SymbolicUtils.BasicSymbolic{Real}, 0}}}, app::SimApp)
@ Main ~/Projects/FastSymbolicDifferentiation/trace_kflow_step.ipynb:22
[8] top-level scope
@ ~/Projects/FastSymbolicDifferentiation/trace_kflow_step.ipynb:4
This happens if I try to trace with just the symbols from Symbolics.jl:
julia> fs = step(collect(u), app)
MethodError: no method matching unsafe_trunc(::Type{Int64}, ::Num)
Closest candidates are:
unsafe_trunc(::Type{T}, !Matched::Integer) where T<:Integer
@ Base int.jl:604
unsafe_trunc(::Type{T}, !Matched::BigFloat) where T<:Integer
@ Base mpfr.jl:321
unsafe_trunc(::Type{Int64}, !Matched::Union{Float16, Float32, Float64})
@ Base float.jl:335
Stacktrace:
[1] fast_trunc(#unused#::Type{Int64}, x::Num)
@ Interpolations ~/.julia/packages/Interpolations/nDwIa/src/utils.jl:40
[2] positions(deg::Linear{Periodic{OnCell}}, ax::Base.OneTo{Int64}, x::Num)
@ Interpolations ~/.julia/packages/Interpolations/nDwIa/src/b-splines/linear.jl:47
[3] weightedindex_parts(fs::Tuple{typeof(Interpolations.value_weights)}, deg::Linear{Periodic{OnCell}}, ax::Base.OneTo{Int64}, x::Num)
@ Interpolations ~/.julia/packages/Interpolations/nDwIa/src/b-splines/indexing.jl:149
[4] weightedindex_parts
@ ~/.julia/packages/Interpolations/nDwIa/src/b-splines/indexing.jl:145 [inlined]
[5] map3argf
@ ~/.julia/packages/Interpolations/nDwIa/src/b-splines/indexing.jl:70 [inlined]
[6] weightedindexes
@ ~/.julia/packages/Interpolations/nDwIa/src/b-splines/indexing.jl:66 [inlined]
[7] BSplineInterpolation
...