-
-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “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? Sign in to your account
Update StaticArray tests for eltype requirements #2087
Conversation
u0 = [fill(2, SVector{2, Float64}), ones(SVector{2, Float64})] | ||
u0 = VectorOfArray([fill(2, SVector{2, Float64}), ones(SVector{2, Float64})]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that plain Array
s of SVector
s will not be supported anymore and we have to switch to VectorOfArray
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See SciML/SciMLBase.jl#561. Basically I am trying to get things to a well-defined interface. This little bit sticks out as sore area of DiffEq where we don't throw any errors about arrays of arrays since 10 out of like 300 methods supports arrays of arrays. But we should be able to support such types of targets more broadly without overhead by just using a small wrapper that makes everything conform to the interface. If this is allowed, then we can throw informative errors as to what's going on and we can vastly clean up a lot of the code to not require hacks for specific methods to avoid assumptions about the lack of Number eltype. Since it's an undocumented bit only used downstream by you and @Datseris, it's a small discussion to be had with many good consequences to most users, and would make things like transitioning a code to implicit methods more readily available since the Vector of Vector form will likely never be able to support linear algebra appropriately.
As you can see from the PR, there is a keyword argument being made to bypass the interface erroring, but I hope that is only used during development and is not a crutch that is actually relied on for these kinds of tasks given that there should be zero overhead to using a more structured and interface-compliant form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use arrays of SVector
s at least for some solvers in Trixi.jl with explicit Runge-Kutta methods. If OrdinaryDiffEq.jl transitions to another interface requirement, it would be great to get a breaking release describing this change.
We would also need more interfaces such as resize!
and pointer
for VectorOfArray
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see from the PR, there is a keyword argument being made to bypass the interface erroring, but I hope that is only used during development and is not a crutch that is actually relied on for these kinds of tasks given that there should be zero overhead to using a more structured and interface-compliant form.
Which PR do you refer to? I could only see changes to the tests here and new docs at SciML/SciMLBase.jl#561
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure undocumented side pieces really constitute breaking. We are trying to impose such interfaces so that there is a strong sense of what is actually breaking.
We would also need more interfaces such as resize! and pointer for VectorOfArray.
Add suggestions in the interface PR and I'll happily accept that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In BVDiffEq we were using a AbstractArray{<:AbstractArray}
for specifying the initial guess on a mesh. We can upperbound SciMLBase there and cut a breaking release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is bounding SciMLBase compat enough to address the impact of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not SciMLBase my bad. DiffEqBase needs a upperbound. See SciML/BoundaryValueDiffEq.jl#152
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In BVDiffEq we were using a AbstractArray{<:AbstractArray} for specifying the initial guess on a mess. We can upperbound SciMLBase there and cut a breaking release.
BVDiffEq we need to specialize there because that's a legitimate use case, that's quite different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you plan to do that? We may use it as inspiration for us in Trixi.jl.
Restricting SciMLBase.jl to 2.11.0 to address the changes in SciML/OrdinaryDiffEq.jl#2087 (see also SciML/OrdinaryDiffEq.jl#2087 (comment)). Note to self: check compat update for https://github.com/SciML/BoundaryValueDiffEq.jl in a few days, they seem to have the same issue.
@AayushSabharwal success!!!!!!!!!!!!!!!!!!! 🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉 As a clarification to everyone, there's a few related things going on here. The first is the SymbolicIndexingInterface v0.3 and RecursiveArrayTools v3 releases. While this nominally was done in order to make But with that, a casualty is precisely this test set right now for arrays of static arrays. Now in OrdinaryDiffEq.jl, I've wanted since 2016 to try to support arrays of arrays in multiple ways because it's a nice abstraction for many use cases. However, this change of not relying on the I think the straw that really broke the camel's back was that I was running a workshop and people got hung up on this due to a bad error message, and then I saw the same thing on Discourse (https://discourse.julialang.org/t/solving-a-system-of-matrix-differential-equations-using-differentialequations-jl/107663/4). So this piece that doesn't really work was holding up any possibility of allowing most people to have the good experience of a clear error message. And, I'm having trouble fixing this side channel for the RecursiveArrayTools v3 release because it's essentially relying on some assumptions that break what's common in the interfaces (for example, that the element type of the array is supposed to give a number). So I was left with a few choices:
I don't think I could feasibly do (3) because that would take a lot more time than I have, and we as an organization have been seeking to plug up all of our interface holes in order to make things more robust and documented anyways. So those two factors together said, it's time to rip off the band-aid and do (2). And to be real, it's been a long time coming, and it's best for the vast majority of users. (4) has many potential issues since it wouldn't dispatch as the user thinks, so I didn't want to open that can of worms. But yes, there are these two codes that do use this side channel, I don't think it would be anyone else because it would be fairly difficult to even find out that these algorithms were exceptions for these specific cases 😅. It's not documented but you could argue it's public API, but I'd rather do a much more targeted check here. Again, we could do a trait system to opt specific algorithms out here https://github.com/SciML/DiffEqBase.jl/blob/master/src/solve.jl#L591, but I'm not convinced that's even a good idea in the long term anyways. In the long term, now that VectorOfArray does everything that is needed here, I think the solution is just, if you want to do Vector of Vectors just slap a VectorOfArray on it, and if you don't we throw an informative error message telling you the easy solution. And with that, now everything is optimized, everyone gets a clear error message, and everything conforms to a vastly simpler interface. I'm definitely open for opinions though |
In https://github.com/SciML/DiffEqBase.jl/blob/master/src/solve.jl#L591 we should add a check that it's not a BoundaryValueProblem. @avik-pal can you follow up with that?
I'm not so sure how that's applicable @ranocha . The issue is that for a BVP |
Well, our ODE is a spatial semidiscretization of a system of PDEs. From the semidiscretization's point of view, an array of vectors (for each point in space) is a natural approach. Minor clarification: It's not only a handful of SSPRK methods - all explicit RK methods not doing anything special (like ROCK methods) have been supporting arrays of static arrays for years. Everything required for explicit RK methods is a basic implementation of a vector space interface. |
Are you sure about that? Because broadcast doesn't work well on arrays of arrays.
Does VectorOfArray wrapping not work for you case? It's covered everything that we've tried so far at least. |
It did indeed work and was tested with |
But were there AD tests on it? I am going back through the AD testing and don't see any of those cases checked, nor do I see how they would've worked in general with reverse mode. I get the very basic "it can solve" was checked, but I don't see any other interface compatibility checks on this case beyond that, and from what I could tell those mostly failed. What exactly do you need? I still don't quite understand why VectorOfArray would add any complexity or performance issues. |
We just needed the basic "it can solve" capability, so we never tested AD etc. We need for example the option to use (jl_YFxZqo) pkg> add StaticArrays StructArrays RecursiveArrayTools
(jl_YFxZqo) pkg> add StaticArrays StructArrays RecursiveArrayTools
...
[731186ca] + RecursiveArrayTools v3.4.2
[90137ffa] + StaticArrays v1.9.0
[09ab397b] + StructArrays v0.6.16
...
julia> using StaticArrays, StructArrays, RecursiveArrayTools
julia> u = VectorOfArray(StructArray(randn(SVector{2, Float64}, 10)))
VectorOfArray{Float64,2}:
10-element StructArray(::Vector{Float64}, ::Vector{Float64}) with eltype SVector{2, Float64}:
[-0.7640292999038704, 0.6553189479381939]
[0.8378337172716237, 0.07143533596999121]
[-0.5413059411379175, 1.545169798144512]
[-0.1140800570149823, 2.0271290114354232]
[-0.09736760972644991, 0.9762634582911948]
[-0.9241989885704037, -0.7643537491391698]
[-0.3234905544876145, 0.035062794764888564]
[0.6533985389766392, 1.0330990755657259]
[-1.7927415052914886, -0.8398035991158214]
[-0.5444953510216021, 0.28585092256556105]
julia> parent(u)
ERROR: MethodError: no method matching parent(::VectorOfArray{Float64, 2, StructVector{SVector{2, Float64}, Tuple{Vector{Float64}, Vector{Float64}}, Int64}})
Closest candidates are:
parent(::SizedArray)
@ StaticArrays ~/.julia/packages/StaticArrays/PLKkM/src/SizedArray.jl:95
parent(::StructArrays.GroupPerm)
@ StructArrays ~/.julia/packages/StructArrays/0h2SD/src/sort.jl:14
parent(::PermutedDimsArray)
@ Base permuteddimsarray.jl:48
...
Stacktrace:
[1] top-level scope
@ REPL[5]:1 It looks like we could use julia> u.u
10-element StructArray(::Vector{Float64}, ::Vector{Float64}) with eltype SVector{2, Float64}:
[-0.7640292999038704, 0.6553189479381939]
[0.8378337172716237, 0.07143533596999121]
[-0.5413059411379175, 1.545169798144512]
[-0.1140800570149823, 2.0271290114354232]
[-0.09736760972644991, 0.9762634582911948]
[-0.9241989885704037, -0.7643537491391698]
[-0.3234905544876145, 0.035062794764888564]
[0.6533985389766392, 1.0330990755657259]
[-1.7927415052914886, -0.8398035991158214]
[-0.5444953510216021, 0.28585092256556105] but I couldn't find it in the docs. |
I just took a look at implementing |
I'll second this; my unknowns are |
Does https://github.com/JuliaArrays/ArraysOfArrays.jl work for this? |
Some broadcast operations (like adding constants to an array) work with I tried extending |
The RecursiveArrayTools.jl one? Yeah it sounds fine to generalize that. I'd take a PR if you have code for it. |
Great, will add when I'm back |
No description provided.