Skip to content

ode_order_lowering equation ordering #782

@agerlach

Description

@agerlach

I used ode_order_lowering for the first time and was caught a little off guard by the resulting equation order, i.e. descending order instead of ascending. I was essentially doing the following. Which works just fine.

using ModelingToolkit

@variables t x(t)
D = Differential(t)
eqs = [(DD)(x) ~ -1]
sys = ode_order_lowering(ODESystem(eqs))

tspan = (0.0, 1.0)
u0 = [x => 100.0, D(x) =>0.0]
prob = ODEProblem(sys,u0,tspan,jac=true)

However, I then went to update prob via remake(prob, u0=[x_value, dx_value]) which is incorrect. It needs to be u0=[dx_value, x_value].

A couple thoughts:

  1. The order seems unnatural. I don't know if I've ever seen an ODE lowered in that order in a textbook. Obviously, the order doesn't matter in principle, but it does impact the interface for updating the resulting numerical problem. At a minimum this should be documented.
  2. Possibly add a "sort order" kwarg to ode_order_lowering. However, I think below is a better option
  3. Treat u0 = [x => 100.0, D(x) =>0.0] as a template for the interface, e.g. reorder the equations based on the order in the array. However, I can see situations where the order of the equations impacts performance and using a symbolic transformation to put it in a favorable form would conflict w/ this, e.g. grouping uncertain states for expectation() to prevent cache miss.

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