generated from AlgebraicJulia/AlgebraicTemplate.jl
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Oscillator Decapode code generation, state inference fails #28
Comments
I manually overrode the state names for
yields quote
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:570 =#
function simulate(mesh, operators, hodge = GeometricHodge())
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:570 =#
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:571 =#
begin
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:174 =#
end
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:572 =#
begin
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:468 =#
end
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:573 =#
begin
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:227 =#
var"__•1" = Decapodes.FixedSizeDiffCache(Vector{Float64}(undef, nparts(mesh, :V)))
__V̇ = Decapodes.FixedSizeDiffCache(Vector{Float64}(undef, nparts(mesh, :V)))
end
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:574 =#
f(du, u, p, t) = begin
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:574 =#
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:575 =#
begin
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:252 =#
X = u.X
k = p.k
V = u.V
end
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:576 =#
var"•1" = Decapodes.get_tmp(var"__•1", u)
V̇ = Decapodes.get_tmp(__V̇, u)
var"•1" .= (.-)(k)
V̇ .= var"•1" .* X
#= /Users/fairbanksj/AlgebraicJulia/Decapodes.jl/src/simulation.jl:577 =#
getproperty(du, :X) .= V
getproperty(du, :V) .= V̇
end
end
end |
I think this would be a slightly more generic fix: # Original definition of state variables, which is those that cannot be directly calculuted by the formulas.
# function DiagrammaticEquations.infer_states(d::SummationDecapode)
# filter(parts(d, :Var)) do v
# length(incident(d, v, :tgt)) == 0 &&
# length(incident(d, v, :res)) == 0 &&
# length(incident(d, v, :sum)) == 0 &&
# d[v, :type] != :Literal
# end
# end
infer_state_names(oscillator)
# Definition of state variables as "things that have time derivatives, plus stuff that we can't compute implicitly."
function variables_having_derivative(d::SummationDecapode)
union(d[incident(d,:∂ₜ, :op1), :src],
filter(parts(d, :Var)) do v
length(incident(d, v, :tgt)) == 0 &&
length(incident(d, v, :res)) == 0 &&
length(incident(d, v, :sum)) == 0 &&
d[v, :type] != :Literal
end)
end
DiagrammaticEquations.infer_states(d::SummationDecapode) = variables_having_derivative(d)
variables_having_derivative(oscillator)
decapode_code = gensim(oscillator, dimension = 1) @lukem12345, what do you think about upstreaming this to DiagrammaticEquations? |
Yeah the boolean check here just needs to be a little different since |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gensim(oscillator, dimension = 1)
generates:The value of
V
is never set or updated.infer_state_names(oscillator)
does not includeV
:The text was updated successfully, but these errors were encountered: