The following Julia code (that uses ModelingToolkit) runs with no troubles in REPL, but errors when run within a code cell in a Quarto qmd file (for convenience it is also listed below together with the error message):
using ModelingToolkit, Plots, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t
using ModelingToolkit: D_nounits as D
function plant(; name)
@variables x₁(t)=0 x₂(t) = 0 u(t) y(t)
eqs = [D(x₁) ~ x₂
D(x₂) ~ -0.2x₂ + u
y ~ x₁ + x₂]
ODESystem(eqs, t; name = name)
end
function controller(; name)
@variables x(t)=0 u(t) y(t)
eqs = [D(x) ~ -x + u
y ~ x]
ODESystem(eqs, t, name = name)
end
@named C = controller()
@named P = plant()
t_of_step = 1.0
r(t) = t >= t_of_step ? 1.0 : 0.0
@register_symbolic r(t)
connections = [C.u ~ r(t) - P.y
C.y ~ P.u]
@named T = ODESystem(connections, t, systems = [C, P])
T = structural_simplify(T)
using DifferentialEquations: solve
prob = ODEProblem(complete(T), [], (0.0, 30.0), [])
sol = solve(prob, Tsit5(), saveat = 0.1)
Here is the minimum quarto qmd source document:
---
title: "Demonstration of the error"
format: html
engine: julia
---
``` {julia}
using ModelingToolkit, Plots, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t
using ModelingToolkit: D_nounits as D
function plant(; name)
@variables x₁(t)=0 x₂(t) = 0 u(t) y(t)
eqs = [D(x₁) ~ x₂
D(x₂) ~ -0.2x₂ + u
y ~ x₁ + x₂]
ODESystem(eqs, t; name = name)
end
function controller(; name)
@variables x(t)=0 u(t) y(t)
eqs = [D(x) ~ -x + u
y ~ x]
ODESystem(eqs, t, name = name)
end
@named C = controller()
@named P = plant()
t_of_step = 1.0
r(t) = t >= t_of_step ? 1.0 : 0.0
@register_symbolic r(t)
connections = [C.u ~ r(t) - P.y
C.y ~ P.u]
@named T = ODESystem(connections, t, systems = [C, P])
T = structural_simplify(T)
using DifferentialEquations: solve
prob = ODEProblem(complete(T), [], (0.0, 30.0), [])
sol = solve(prob, Tsit5(), saveat = 0.1)
And here is the the error output
➜ www quarto preview /Users/hurak/Documents/vyuka/hybrid/www/demo_error.qmd --no-browser --no-watch-inputs
pandoc
to: html
output-file: demo_error.html
standalone: true
title-prefix: B(E)3M35HYS – Hybrid systems
section-divs: true
html-math-method: mathjax
wrap: none
default-image-extension: png
css:
- styles.css
toc: true
metadata
document-css: false
link-citations: true
date-format: long
lang: en
theme: cosmo
title: Demonstration of the error
Output created: _site/demo_error.html
Preparing to preview
[1/1] classes_reset.qmd
Running [1/3] at line 74: using OrdinaryDiffEq
Running [2/3] at line 119: using OrdinaryDiffEq
Running [3/3] at line 166: using ModelingToolkit, Plots, OrdinaryDiffEq
ERROR: Julia server returned error after receiving "run" command:
Failed to run notebook: /Users/hurak/Documents/vyuka/hybrid/www/classes_reset.qmd
ERROR: EvaluationError: Encountered 1 error during evaluation
Error 1 of 1
@ /Users/hurak/Documents/vyuka/hybrid/www/classes_reset.qmd:166
MethodError: no method matching occursin(::Vector{Float64}, ::Vector{Float64})
Closest candidates are:
occursin(!Matched::SymbolicUtils.Symbolic, ::Any)
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/5UmB7/src/substitute.jl:51
occursin(::Any, !Matched::SymbolicUtils.Symbolic)
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/5UmB7/src/substitute.jl:50
occursin(::Any)
@ Base strings/search.jl:724
Stacktrace:
[1] _occursin(needle::Vector{Float64}, haystack::SymbolicUtils.BasicSymbolic{Real})
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/5UmB7/src/substitute.jl:58
[2] occursin
@ ~/.julia/packages/SymbolicUtils/5UmB7/src/substitute.jl:50 [inlined]
[3] check_variables(dvs::Vector{SymbolicUtils.BasicSymbolic{Real}}, iv::Vector{Float64})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/UXr3S/src/utils.jl:151
[4] ODESystem(tag::UInt64, deqs::Vector{Equation}, iv::Vector{Float64}, dvs::Vector{SymbolicUtils.BasicSymbolic{Real}}, ps::Vector{Any}, tspan::Nothing, var_to_name::Dict{Any, Any}, ctrls::Vector{Any}, observed::Vector{Equation}, tgrad::Base.RefValue{Vector{Num}}, jac::Base.RefValue{Any}, ctrl_jac::Base.RefValue{Any}, Wfact::Base.RefValue{Matrix{Num}}, Wfact_t::Base.RefValue{Matrix{Num}}, name::Symbol, systems::Vector{ODESystem}, defaults::Dict{Any, Any}, guesses::Dict{Any, Any}, torn_matching::Nothing, initializesystem::Nothing, initialization_eqs::Vector{Equation}, schedule::Nothing, connector_type::Nothing, preface::Nothing, cevents::Vector{ModelingToolkit.SymbolicContinuousCallback}, devents::Vector{ModelingToolkit.SymbolicDiscreteCallback}, parameter_dependencies::Vector{Equation}, metadata::Nothing, gui_metadata::Nothing, tearing_state::Nothing, substitutions::Nothing, complete::Bool, index_cache::Nothing, discrete_subsystems::Nothing, solved_unknowns::Nothing, split_idxs::Nothing, parent::Nothing; checks::Bool)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/UXr3S/src/systems/diffeqs/odesystem.jl:188
[5] ODESystem(deqs::Vector{Equation}, iv::Vector{Float64}, dvs::Vector{Any}, ps::Vector{Any}; controls::Vector{Num}, observed::Vector{Equation}, systems::Vector{ODESystem}, tspan::Nothing, name::Symbol, default_u0::Dict{Any, Any}, default_p::Dict{Any, Any}, defaults::Dict{Any, Any}, guesses::Dict{Any, Any}, initializesystem::Nothing, initialization_eqs::Vector{Equation}, schedule::Nothing, connector_type::Nothing, preface::Nothing, continuous_events::Nothing, discrete_events::Nothing, parameter_dependencies::Vector{Equation}, checks::Bool, metadata::Nothing, gui_metadata::Nothing)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/UXr3S/src/systems/diffeqs/odesystem.jl:269
[6] ODESystem(eqs::Vector{Equation}, iv::Vector{Float64}; kwargs::@Kwargs{name::Symbol})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/UXr3S/src/systems/diffeqs/odesystem.jl:343
[7] controller(; name::Symbol)
@ Main.Notebook ~/Documents/vyuka/hybrid/www/classes_reset.qmd:184
[8] top-level scope
@ ~/.julia/packages/ModelingToolkit/UXr3S/src/systems/abstractsystem.jl:1949
ERROR: Internal julia server error
Stack trace:
at writeJuliaCommand (file:///Applications/quarto/bin/quarto.js:42026:19)
at eventLoopTick (ext:core/01_core.js:153:7)
at async executeJulia (file:///Applications/quarto/bin/quarto.js:41920:22)
at async Object.execute (file:///Applications/quarto/bin/quarto.js:41657:20)
at async renderExecute (file:///Applications/quarto/bin/quarto.js:78509:27)
at async renderFileInternal (file:///Applications/quarto/bin/quarto.js:78677:43)
at async renderFiles (file:///Applications/quarto/bin/quarto.js:78545:17)
at async renderProject (file:///Applications/quarto/bin/quarto.js:78955:25)
at async serveProject (file:///Applications/quarto/bin/quarto.js:100603:24)
at async Command.actionHandler (file:///Applications/quarto/bin/quarto.js:101298:9)
Any idea?