-
-
Notifications
You must be signed in to change notification settings - Fork 217
DelayParentScope
variables aren't properly handled
#3539
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No 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? No Sign in to your account
Comments
Marking this as v10 because the change is probably breaking. |
I'm also more than happy to axe |
I sincerely doubt this feature is used by any Catalyst user. Dropping it in v10 sounds fine to me. |
I would think @avinashresearch1 is likely the only one with code that uses it? I think it was just added for some odd thing in the HVAC models.
those two comments in a tutorial are literally its only documentation. A search of all public github code reveals only two cases:
That last one I think is the same use case as the HVAC model, which is for parameter propagation. Since we now have parameter equations, I think that is a much better way to handle it than this delayed scoping which is inherently hard to reason about. So yes, I'd say it's fine to just deprecate and remove it in v10 and recommend people using it, almost certainly for shared parameters, uses parameter equations instead. |
Great. So I'll do something relatively reasonable to make tests pass here and in Catalyst with #3528 and add a depwarn. |
So
DelayParentScope
is a weird case and is giving me a headache. I will be selfish and share this with everyone. When writingcollect_scoped_vars!
I thought it meantParentScope
nestedN
times. Looking at the PR that added it,DelayParentScope
instead means "behave likeLocalScope
forN
levels, then behave likeParentScope
". #3528 fixes this to some extent. However, the fix makes us unable to properly accessDelayParentScope
d variables viagetproperty
. Considering this has been very broken for very long (currentlygetproperty
returns an incorrect name forDelayParentScope
d variables), I don't think this is a huge deal since we would have had an issue for it long ago. However, it's definitely something to fix.renamespace
and namespacing in general would need a non-trivial change to make this happen.The problem is that our current namespacing behavior relies on identifying which system in the hierarchy a variable "belongs" to.
LocalScope
means it belongs to the system it is used in.ParentScope
means it belongs to the parent of the system it is used in. A system only stores inunknowns
orps
the variables that belong to it.DelayParentScope(LocalScope(), N)
technically means it belongs to the systemN+1
levels above the system it is used in. However, it is namespaced by the bottomN
levels in that hierarchy. To do the latter ingetproperty
, we need to put the variable in the bottom-most system. This is a whole new can of worms, because we don't know what the "bottom-most" system is given just a variable withDelayParentScope(LocalScope(), K)
. It could be one several levels below this. As a result, when asked the question "does thisDelayParentScope
belong to the current system, our answer always has to be "yes". For example:This is in our test suite. Hierarchical systems currently work by inspecting the unnamespaced equations of all subsystems, checking if any of the variables belong to the top-level system and then namespacing all the variables of the subsystems. So
sys2
looks atD(x4) ~ p4
and asks "doesx4
belong to me" - the answer of which is always "yes". So nowx4
is an unknown ofsys2
. Then,sys2
looks at the unknowns ofsys1
and namespaces all of them, and getssys1₊x4
as an unknown. This duplication continuous the higher we go.My proposal is the following:
unknowns
field of a system including only the variables that belong to it, it includes all variables used in the equations of the system (and subsystems).SymScope
metadata to determine "belongingness".renamespace
. There is no need to search through the equations again. Since the unknowns have theSymScope
metadata, they will be namespaced appropriately.getproperty
(getvar
) the variables accessible from a system are ones withLocalScope
orGlobalScope
metadata, or (DelayParentScope
metadata and noNAMESPACE_SEPARATOR
in their name).In the above example,
sys1
has all ofx1...x5
in itsunknowns
field. Onlyx1
,x4
andx5
are accessible viagetproperty
. Forsys2
, it hassys1.x1
,x2
,x3
,sys1.x4
andx5
in theunknowns
field. Onlysys1.x1
,x2
andx5
are accessible viagetproperty
.The problem now is what to return when the user calls
unknowns
(andunknowns_toplevel
). My suggestion is to use the above rules forunknowns_toplevel
and relax theNAMESPACE_SEPARATOR
requirement forunknowns
(thereby includingDelayParentScope
d variables from subsystems).CC @TorkelE @isaacsas @hersle
The text was updated successfully, but these errors were encountered: