-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
feat!: use SciMLStructures and add new MTKParameters
#2447
feat!: use SciMLStructures and add new MTKParameters
#2447
Conversation
eac46bb
to
802d441
Compare
1b8933e
to
4a49486
Compare
MTKParameters
MTKParameters
Also worth noting that this still scalarizes vector parameters. Not doing that won't be breaking, so it's not blocking the release. |
You mean that parameters that are length-1 vectors become scalars? If so, would it be possible to not do that and let the user decide? I have a case which heavily depends on parameters that are length-1 vectors. |
test/runtests.jl
Outdated
@safetestset "Input Output Test" include("input_output_handling.jl") | ||
@safetestset "Clock Test" include("clock.jl") | ||
@safetestset "DiscreteSystem Test" include("discretesystem.jl") | ||
@safetestset "Linearization Tests" include("linearize.jl") # ! |
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 probably should remove the # !
s.
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.
Fixed in b20236e.
@@ -60,22 +61,22 @@ for f in [ | |||
# iip | |||
du = zeros(3) | |||
u = collect(1:3) | |||
p = collect(4:6) | |||
p = ModelingToolkit.MTKParameters(de, [σ, ρ, β] .=> 4.0:6.0) |
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.
Should we keep the original p
to test the fallback case?
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.
If the system has an IndexCache
it will always use that for indexing, and expect that the parameter buffer is an MTKParameters
. As such, collect(4:6)
will be turned into MTKParameters(de, parameters(de) .=> collect(4:6))
ext/MTKBifurcationKitExt.jl
Outdated
# Creates F and J functions. | ||
ofun = NonlinearFunction(nsys; jac = jac) | ||
F = ofun.f | ||
J = jac ? ofun.jac : nothing | ||
F(u, p) = ofun.f(u, ModelingToolkit.MTKParameters(nsys, parameters(nsys) .=> p)) |
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 this really the best way to do this? Doesn’t this mean every call is reallocating a vector of pairs? BifurcationKit will call this function many many times.
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.
No, this is not a good way to do this. We need to do the interface a bit differently here, but I don't want that to block the v9. It should build the problem and use the generated functions from 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.
I haven't reviewed these changes, but I hope that condition/affect functions that are generated will have similar performance to the current MTK and don't have such allocations (which would be really bad for jump models).
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.
(given how often those functions are called)
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.
There are no allocations, and the split form is type stable so it should be faster for cases that have heterogeneous parameters.
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.
Awesome!
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 haven't reviewed these changes, but I hope that condition/affect functions that are generated will have similar performance to the current MTK and don't have such allocations (which would be really bad for jump models).
This is a BifurcationKit-only hack, which I'm removing in favor of just not using MTKParameters
here. Everywhere else in the codebase, this sort of thing does not happen. MTKParameters
is only created once for a problem, and all of the codegen leverages it.
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.
0151988
to
6398aa3
Compare
No, this only means that parameter values need to be specified as julia> @parameters p[1:1]
julia> @variables x(t)
julia> @mtkbuild sys = ODESystem([D(x) ~ sum(p) * t], t)
julia> prob = ODEProblem(sys, [x => 1.0], (0.0, 1.0), [p[1] => 1.0])
julia> prob.ps[p]
1-element Vector{Float64}:
1.0 This is something that will be changed, to make specifying |
Open an issue on that. |
That makes sense, thanks |
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Add any other context about the problem here.