Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/systems/problem_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ takes a value provider of `srcsys` and a value provider of `dstsys` and returns
# Keyword Arguments
- `initials`: Whether to include the `Initial` parameters of `dstsys` among the values
to be transferred.
- `unwrap_initials`: Whether initials in `dstsys` corresponding to unknowns in `srcsys` are
unwrapped.
- `p_constructor`: The `p_constructor` argument to `process_SciMLProblem`.
"""
function get_mtkparameters_reconstructor(srcsys::AbstractSystem, dstsys::AbstractSystem;
Expand All @@ -740,7 +742,7 @@ function get_mtkparameters_reconstructor(srcsys::AbstractSystem, dstsys::Abstrac
end
initials_getter = if initials && !isempty(syms[2])
initsyms = Vector{Any}(syms[2])
allsyms = Set(all_symbols(srcsys))
allsyms = Set(variable_symbols(srcsys))
if unwrap_initials
for i in eachindex(initsyms)
sym = initsyms[i]
Expand Down
30 changes: 30 additions & 0 deletions test/code_generation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,33 @@ end
@test val[] == 2
end
end

@testset "Do not codegen redundant expressions" begin
@variables v1(t) = 1
@variables v2(t) [guess = 0]

mutable struct Data
count::Int
end
function update!(d::Data, t)
d.count += 1 # Count the number of times the data gets updated.
end
function (d::Data)(t)
update!(d, t)
rand(1:10)
end

@parameters (d1::Data)(..) = Data(0)
@parameters (d2::Data)(..) = Data(0)

eqs = [
D(v1) ~ d1(t),
v2 ~ d2(t) # Some of the data parameters are not actually needed to solve the system.
]

@mtkbuild sys = System(eqs, t)
prob = ODEProblem(sys, [], (0.0, 1.0))
sol = solve(prob, Tsit5())

@test sol.ps[d2].count == 0
end
Loading