Skip to content

fix: fix @mtkbuild not working when @mtkcompile is not imported #3841

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 2 commits 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
3 changes: 2 additions & 1 deletion src/deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
macro mtkbuild(exprs...)
return quote
Base.depwarn("`@mtkbuild` is deprecated. Use `@mtkcompile` instead.", :mtkbuild)
@mtkcompile $(exprs...)
$(Expr(:macrocall, var"@mtkcompile",
LineNumberNode(@__LINE__, @__FILE__), exprs...))
end |> esc
end

Expand Down
10 changes: 6 additions & 4 deletions src/systems/solver_nlprob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ function generate_ODENLStepData(sys::System, u0, p, mm = calculate_massmatrix(sy
end
nlprob = NonlinearProblem(nlsys, op; build_initializeprob = false)

subsetidxs = [findfirst(isequal(y),unknowns(sys)) for y in unknowns(nlsys)]
subsetidxs = [findfirst(isequal(y), unknowns(sys)) for y in unknowns(nlsys)]
set_gamma_c = setsym(nlsys, (ODE_GAMMA..., ODE_C))
set_outer_tmp = setsym(nlsys, outer_tmp)
set_inner_tmp = setsym(nlsys, inner_tmp)
nlprobmap = generate_nlprobmap(sys, nlsys)

return SciMLBase.ODENLStepData(nlprob, subsetidxs, set_gamma_c, set_outer_tmp, set_inner_tmp, nlprobmap)
return SciMLBase.ODENLStepData(
nlprob, subsetidxs, set_gamma_c, set_outer_tmp, set_inner_tmp, nlprobmap)
end

const ODE_GAMMA = @parameters γ₁ₘₜₖ, γ₂ₘₜₖ, γ₃ₘₜₖ
const ODE_GAMMA = @parameters γ₁ₘₜₖ, γ₂ₘₜₖ, γ₃ₘₜₖ
const ODE_C = only(@parameters cₘₜₖ)

function get_outer_tmp(n::Int)
Expand Down Expand Up @@ -55,7 +56,8 @@ function inner_nlsystem(sys::System, mm)

new_dvs = unknowns(sys)
new_ps = [parameters(sys); [gamma1, gamma2, gamma3, c, inner_tmp, outer_tmp]]
nlsys = mtkcompile(System(new_eqs, new_dvs, new_ps; name = :nlsys); split = is_split(sys))
nlsys = mtkcompile(
System(new_eqs, new_dvs, new_ps; name = :nlsys); split = is_split(sys))
return nlsys, outer_tmp, inner_tmp
end

Expand Down
7 changes: 7 additions & 0 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1614,3 +1614,10 @@ end
@test_nowarn push!(arr, sys)
@test_nowarn TestWrapper(sys)
end

module MtkbuildTestModule
import ModelingToolkit: @variables, System, t_nounits as t, D_nounits as D, @mtkbuild
@variables x(t)
@mtkbuild sys = System(D(x) ~ t, t)
@test sys isa System
end
Loading