Skip to content

don't error on implicit parameter equation #3686

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 7 additions & 9 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2808,18 +2808,16 @@ function process_parameter_equations(sys::AbstractSystem)
vars!(varsbuf, eq; op = Union{Differential, Initial, Pre})
# singular equations
isempty(varsbuf) && continue

# only consider explicit parameter dependencies
isparameter(eq.lhs) || continue

if all(varsbuf) do sym
is_parameter(sys, sym) ||
symbolic_type(sym) == ArraySymbolic() &&
is_sized_array_symbolic(sym) &&
all(Base.Fix1(is_parameter, sys), collect(sym))
end
if !isparameter(eq.lhs)
throw(ArgumentError("""
LHS of parameter dependency equation must be a single parameter. Found \
$(eq.lhs).
"""))
end
is_sized_array_symbolic(sym) &&
all(Base.Fix1(is_parameter, sys), collect(sym))
end
push!(pareq_idxs, i)
end
end
Expand Down
14 changes: 14 additions & 0 deletions test/input_output_handling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,17 @@ end
x = [1.0]
@test_nowarn f[1](x, u, p, 0.0)
end

@testset "implicit focing of inputs" begin
@mtkmodel ImplicitForcing begin
@variables begin
u(t), [description = "Input Variable", input=true]
y(t), [description = "fully implicit output", output=true]
end
@equations begin
0 ~ sqrt(u) # implicitly forces output y because u=f(y) in closed loop
end
end
@named implicit = ImplicitForcing()
mtkcompile(implicit; inputs = unbound_inputs(implicit)) # test for no error
end
Loading