Skip to content

Suggestion: Make plot plot unknowns AND observables by default (not just unknowns) #3555

Open
@TorkelE

Description

@TorkelE

When splitting what variables become unknowns and what are observables, I feel like it makes sense to lump them together in the plot (i.e. plotting all by default). I.e. here:

using OrdinaryDiffEqDefault, ModelingToolkit, Plots
using ModelingToolkit: t_nounits as t, D_nounits as D

# Create model.
@variables X(t) Y(t)
@parameters p d k1 k2 = 0.5
eqs = [
    D(X) ~ p - d*X,
    k1 + Y ~ k2*X
]
@mtkbuild osys = ODESystem(eqs, t)

# Create `ODEProblem`.
u0 = [X => 2.0]
pvals = [p => 1.0, d => 0.1, k1 => 0.5]
oprob = ODEProblem(osys, u0, (0.0, 10.0), pvals)

# Solve and plot it.
sol = solve(oprob)
plot(sol)

only X is plotted (unless one specify Y explicitly). Now from a user perspective there is no real difference here, they don't know why X is plotted and not Y. I think this is one of (if not the only?) cases where structural_simplify have a direct impact on workflows.

Furthermore, changing this would:

  • Mean that we can be a lot more liberal with updating the internal algorithms of structural_simplify. I.e. there could be minor updates to its algorithm that suddenly changes so that X is eliminated and Y is not (probably not in the example above, but in more complicated ones). If the observables are ploted, the user will never notice or case.
  • The case of eqs = [D(X) ~ -p] is one that can be solved directly, i.e. the only unknown of the system becomes an observable. Here, if you do plot(solve(prob)) you will just get an empty plot plane, which seems really confusing.

I think the other alternative is to just enforcethe use of idxs = in plot. That makes sense for larger models. However, for small models this will be annoying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions