Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/systems/parameter_buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ function MTKParameters(
elseif u0 === nothing || isempty(u0)
u0 = Dict()
end
for sym in keys(u0)
if is_parameter(sys, sym)
error("Encountered parameter $sym in initial conditions")
end
end
defs = merge(defs, u0)
defs = merge(Dict(eq.lhs => eq.rhs for eq in observed(sys)), defs)
p = merge(defs, p)
Expand Down
12 changes: 12 additions & 0 deletions test/mtkparameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,15 @@ function loss(x)
end

@test_nowarn ForwardDiff.gradient(loss, collect(tunables))

# Issue#2692
@variables x(t)
@parameters p d
@mtkbuild osys = ODESystem(D(x) ~ p - d * x, t)
u0 = [x => 5.0, d => 0.2]
ps = [p => 5.0]
@test_throws "Encountered parameter $d in initial conditions" ODEProblem(
osys, u0, (0.0, 1.0), ps)
u0 = [x => 5.0]
ps = [p => 5.0, d => 0.2]
@test_nowarn ODEProblem(osys, u0, (0.0, 1.0), ps)