Open baggepinnen opened 1 month ago
Actually, parsing has gotten better; ()
aren't needed anymore.
This works:
@mtkmodel Fixed begin
@parameters begin
r[1:2] = [0, 0], [description = "Fixed absolute xy-position, resolved in planarWorld frame"]
phi = 0, [description = "Fixed angle"]
end
...
oki that's good, but breaking what was previously working (and required!) is not good
The ()
was actually incorrect... it's kind of surprising that parsing actually worked 😅 . It was definitely not intended and not documented.
It used to error without it but not with it
Also, yingbo closed the issue complaining about this problem by showing to use parenthesis instead https://github.com/SciML/ModelingToolkit.jl/issues/2298#issuecomment-1752431938 I thus consider this breaking
Can you show where it's documented?
I can not, but are you saying that following the advice of a core developer should lead to your code breaking in a patch release? Especially when the issue complaining about this exact problem was closed with this very advice? We must stop breaking people's code like this if we want people to look at MTK as a reliable tool.
The 2024-2025 push is to make MTK match the rest of the reliability in SciML by strictly defining its interfaces, documentation, and better erroring on the breaks. A core developer shared an undocumented, untested, and unpromoted script that was a hacky temporary workaround. This is the exact opposite of the kind of code you're asking for and is exactly the kind of thing that anyone who wants reliability will crack down. Yes, prior unchecked interfaces in this package had traditionally let things slip through. When we turn on checks of interfaces and make things match how they are documented to work, you will get errors if you break the interface. I suggest not relying on hacks around the documented interface, helping with the documentation clarity of the interfaces, and erroring on things to better define the boundary. Hopefully there aren't many left as we have chopped out most of them with the parsing changes and the move to a documented SymbolicIndexingInterface.
@ChrisRackauckas it would be nice as part of this push to also have an API for people developing on top of MTK who may need access to some of the internals (i.e. to declare some of the currently internal symbolic handling code, system code, and macro parsing code public).
(That is another source of things breaking in non-breaking MTK releases we see quite frequently in Catalyst, which is our fault for using such functions, but really the only option in many cases short of copying the code from MTK into Catalyst.)
Most of the internal symbolic handling code was made public API when Symbolics.jl was section out. If there's anything missing from that it should get an issue. At this point I think almost all of it is documented Symbolics.jl or SymbolicUtils.jl actions?
For the system code, yeah there's still a few things we need to document and make API. Some of the query functions in particular are nice to use and likely should get tested, like some of the stuff around metadata.
Macro parsing code 😅 , I'm not sure about how public API that should really be... unless it's sectioned off to some macro parsing utils package or something. That's quite internal stuff.
Why shouldn't
(r[1:2] = [0, 0]), [description = "Fixed absolute xy-position, resolved in planarWorld frame"]
be supported? Also, by Julia syntax,
begin
r = [0, 0], [description = "Fixed absolute xy-position, resolved in planarWorld frame"]
a
end
means
begin
r = ([0, 0], [description = "Fixed absolute xy-position, resolved in planarWorld frame"])
a
end
so
(r[1:2] = [0, 0]), [description = "Fixed absolute xy-position, resolved in planarWorld frame"]
is always the correct syntax anyway.
Proof:
julia> ex = :(begin
r = [0, 0], [description = "Fixed absolute xy-position, resolved in planarWorld frame"]
a
end)
quote
#= REPL[14]:2 =#
r = ([0, 0], [description = "Fixed absolute xy-position, resolved in planarWorld frame"])
#= REPL[14]:3 =#
a
end
The revert PR https://github.com/SciML/ModelingToolkit.jl/pull/3092 fixes this issue.
Note that, the
r[1:2] = [0, 0], [description = "Fixed absolute xy-position, resolved in planarWorld frame"]
syntax was picked for mtkmodel and internally parser handled was set to correctly assign default and metadata values (and we had unit tests for this). This was to avoid the ()
that would be necessary with vanilla-@variables
.
That's why (r[1:2] = [0, 0]), [...]
wasn't part of the test suite and when updated this error was not caught.
However, there was nothing (code or docs) that explicitly disallowed that method either, resulting in confusion.
Now, with: #3107
The updated parser works with both syntaxes and has dedicated tests for both Also, I've added a dedicated section in docs describing all the different ways to define arrays in mtkmodel.
If this is going to be added to the DSL why not add to the standalone macros too? Seems likely to be confusing to people otherwise.
https://github.com/SciML/ModelingToolkit.jl/pull/3107 fixes this issue (and includes related unit tests)
The following definition used to be fine, but is now broken on latest master
The issue is the default value for
r
, if I remove it things work.the error is