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.42k stars 206 forks source link

Specify variable scope #1648

Open ValentinKaisermayer opened 2 years ago

ValentinKaisermayer commented 2 years ago

Would it be possible to specify the variable scope in the @variables macro?

Like: @variables p [scope = ParentScope]

shashi commented 2 years ago

What is your use case? We have thought about this a bit, because it becomes useful if you want to have lambda expressions that one can pattern match, but still wondering if it's worth the increase in complexity of implementation.

ValentinKaisermayer commented 2 years ago

In Modelica there is the notion of a medium. Which is propagated to the components of the model. Simscape has this too. My idea is to specify the properties of the medium via a component and lift the corresponding parameters in all other components into the parent scope.

The macro would just be for a nicer syntax.

See this PR for an implementieren of the idea: https://github.com/SciML/ModelingToolkitStandardLibrary.jl/pull/78/files#diff-eb1be027e9de472ab7ab428be392b14eeb634c9cad7df9309ebcc0025e6e175fR37-R50

baggepinnen commented 2 years ago

I have an old branch that performs "clock inference", i.e., determines what clock partition a variable or equations belongs to. Clock partitions become relevant when you have both continuous and discrete systems, and potentially many different clocks for different discrete systems. This is quite similar in the sense that the clock partition for a variable is automatically inferred based on surrounding variables. The logic is quite complicated, so if the two problems are sufficiently similar, it'd be nice to have a good way of doing these kinds of things