SciML / ModelingToolkit.jl

An acausal modeling framework for automatically parallelized scientific machine learning (SciML) in Julia. A computer algebra system for integrated symbolics for physics-informed machine learning and automated transformations of differential equations
https://mtk.sciml.ai/dev/
Other
1.43k stars 209 forks source link

`substitute` should take fully qualified substitutions #3023

Open BenChung opened 2 months ago

BenChung commented 2 months ago

The overload for Symbolics.substitute takes a dict mapping symbols to be replaced to the values to replace them with. However, the symbols must be written in the local scope of whatever model you're substituting into:

@parameters y, w
function ExampleMod(;name) 
    @variables begin 
        x(t)=0
        u(t)
    end
    eqs = [ 
        D(x) ~ u
        u ~ y*sin(t)
    ]
    return ODESystem(eqs, t; name=name)
end
@named mdl = ExampleMod()
equations(substitute(mdl, Dict(mdl.y => w))) # still has y in it
equations(substitute(mdl, Dict(y => w))) # replaces y with w

It should be possible to substitute into a system using fully qualified names.

ChrisRackauckas commented 2 months ago

You can, that's the semantics of a completed system. This is the reason for system completion.