-
Notifications
You must be signed in to change notification settings - Fork 116
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
Simplify printing #610
Simplify printing #610
Conversation
With the changes downstream, this makes `var"mysymbol.x"` just print as `mysymbol.x`, which makes all of the use cases look so much nicer and gets rid of unicode. ```julia julia> rc_model Model rc_model with 1 equations Unknowns (1): capacitor.v Parameters (3): resistor.R [defaults to 2.0] capacitor.C [defaults to 1.0] ⋮ Incidence matrix:1×2 SparseArrays.SparseMatrixCSC{Num, Int64} with 2 stored entries: × × julia> equations(rc_model) 1-element Vector{Equation}: Differential(t)(capacitor.v) ~ capacitor.i / capacitor.C julia> unknowns(rc_model) 1-element Vector{SymbolicUtils.BasicSymbolic{Real}}: capacitor.v julia> parameters(rc_model) 3-element Vector{SymbolicUtils.BasicSymbolic{Real}}: resistor.R capacitor.C source.V julia> observed(rc_model) 19-element Vector{Equation}: source.v ~ source.V capacitor.p.v ~ capacitor.v capacitor.n.v ~ -0.0 ground.g.v ~ 0.0 ⋮ source.p.i ~ source.i capacitor.p.i ~ -capacitor.n.i source.n.i ~ -source.p.i ```
Benchmark Results
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
This will break model text serialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Printing with quotation is deliberate to support text-based model serialization.
This would make copy-paste work, which would mean directly writing to a file would reconstruct the same expressions. I presume you must mean something different by text serialization? |
|
I meant something like julia> rc_model
Model rc_model with 14 (22) equations
Unknowns (22):
resistor₊v(t) [defaults to 0.0]
resistor₊i(t) [defaults to 0.0]
resistor₊p₊v(t)
resistor₊p₊i(t)
resistor₊n₊v(t)
resistor₊n₊i(t)
capacitor₊v(t) [defaults to 0.0]
capacitor₊i(t) [defaults to 0.0]
capacitor₊p₊v(t)
capacitor₊p₊i(t)
capacitor₊n₊v(t)
capacitor₊n₊i(t)
input₊output₊u(t): Inner variable in RealOutput output
⋮
Parameters (7):
resistor₊R [defaults to 1.0]: Resistance
capacitor₊C [defaults to 1.0]: Capacitance
input₊offset [defaults to 1]
input₊start_time [defaults to 1]
input₊amplitude [defaults to 1]
input₊frequency [defaults to 1]
input₊phase [defaults to 1]
julia> toexpr(rc_model)
:(let
begin
var"##iv#14121" = (#= /Users/schemescheme/src/julia/ModelingToolkit/src/systems/abstractsystem.jl:1250 =# @variables(t))[1]
var"##sts#14122" = (collect)(@variables(resistor₊v(t), resistor₊i(t), resistor₊p₊v(t), resistor₊p₊i(t), resistor₊n₊v(t), resistor₊n₊i(t), capacitor₊v(t), capacitor₊i(t), capacitor₊p₊v(t), capacitor₊p₊i(t), capacitor₊n₊v(t), capacitor₊n₊i(t), input₊output₊u(t), source₊v(t), source₊i(t), source₊p₊v(t), source₊p₊i(t), source₊n₊v(t), source₊n₊i(t), source₊V₊u(t), ground₊g₊v(t), ground₊g₊i(t)))
var"##ps#14123" = (collect)(@parameters(resistor₊R, capacitor₊C, input₊offset, input₊start_time, input₊amplitude, input₊frequency, input₊phase))
var"##eqs#14125" = [(Symbolics.connect)(input.output, source.V); (Symbolics.connect)(source.p, resistor.p); (Symbolics.connect)(resistor.n, capacitor.p); (Symbolics.connect)(capacitor.n, source.n, ground.g); (~)(resistor₊v, (+)((*)(-1, resistor₊n₊v), resistor₊p₊v)); (~)(0, (+)(resistor₊p₊i, resistor₊n₊i)); (~)(resistor₊i, resistor₊p₊i); (~)(resistor₊v, (*)(resistor₊R, resistor₊i)); (~)(capacitor₊v, (+)(capacitor₊p₊v, (*)(-1, capacitor₊n₊v))); (~)(0, (+)(capacitor₊p₊i, capacitor₊n₊i)); (~)(capacitor₊i, capacitor₊p₊i); (~)((Differential(t))(capacitor₊v), (/)(capacitor₊i, capacitor₊C)); (~)(input₊output₊u, (+)(input₊offset, (ifelse)((<)(t, input₊start_time), 0, (*)(input₊amplitude, (sin)((+)(input₊phase, (*)(6.283185307179586, input₊frequency, (+)((*)(-1, input₊start_time), t)))))))); (~)(source₊v, (+)((*)(-1, source₊n₊v), source₊p₊v)); (~)(0, (+)(source₊p₊i, source₊n₊i)); (~)(source₊i, source₊p₊i); (~)(source₊v, source₊V₊u); (~)(ground₊g₊v, 0)]
var"##defs#14126" = (Dict)((Pair)(resistor₊v, 0.0), (Pair)(input₊frequency, 1), (Pair)(input₊offset, 1), (Pair)(capacitor₊i, 0.0), (Pair)(resistor₊i, 0.0), (Pair)(input₊start_time, 1), (Pair)(resistor₊R, 1.0), (Pair)(source₊v, 0.0), (Pair)(input₊phase, 1), (Pair)(capacitor₊v, 0.0), (Pair)(input₊amplitude, 1), (Pair)(source₊i, 0.0), (Pair)(capacitor₊C, 1.0))
var"##eqs#14127" = [;]
var"##iv#14128" = (#= /Users/schemescheme/src/julia/ModelingToolkit/src/systems/abstractsystem.jl:1276 =# @variables(t))[1]
(ODESystem)(var"##eqs#14125", var"##iv#14128", var"##sts#14122", var"##ps#14123"; defaults = var"##defs#14126", observed = var"##eqs#14127", name = :rc_model, checks = false)
end
end) |
I see, so we should specialize the display of systems and equations specifically? |
Yeah, I think we should decouple display of models further. We can add a |
With the changes downstream, this makes
var"mysymbol.x"
just print asmysymbol.x
, which makes all of the use cases look so much nicer and gets rid of unicode.