-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Use Difference operator for discrete system #1119
Use Difference operator for discrete system #1119
Conversation
Current state of discrete function generator: User side: @parameters t σ ρ β
D = Difference(t; dt=0.01)
@variables x(t) y(t) z(t)
eqs = [D(x) ~ σ*(y-x),
D(y) ~ x*(ρ-z)-y,
D(z) ~ x*y - β*z]
de = DiscreteSystem(eqs,t,[x,y,z],[σ,ρ,β]) Function produced: function (ˍ₋out, ˍ₋arg1, ˍ₋arg2, t)
let var"x(t)" = @inbounds(ˍ₋arg1[1]),
var"y(t)" = @inbounds(ˍ₋arg1[2]),
var"z(t)" = @inbounds(ˍ₋arg1[3]),
σ = @inbounds(ˍ₋arg2[1]),
ρ = @inbounds(ˍ₋arg2[2]),
β = @inbounds(ˍ₋arg2[3])
@inbounds begin
ˍ₋out[1] = (+)(var"x(t)", (*)(σ, (+)(var"y(t)", (*)(-1, var"x(t)"))))
ˍ₋out[2] = (*)(var"x(t)", (+)(ρ, (*)(-1, var"z(t)")))
ˍ₋out[3] = (+)(var"z(t)", (*)(var"x(t)", var"y(t)"), (*)(-1, β, var"z(t)"))
nothing
end
end
end |
@ChrisRackauckas @YingboMa The simple SIR test now works fine with |
Also, I think currently FunctionMap defaults to |
One other thing we are assuming right now is that we have a common difference operator on all states with equal timesteps. Do we intend to support multi-timestep processes? |
Yes. |
f_gen = build_function(rhss, dvs, ps, t; expression=Val{eval_expression}, expression_module=eval_module) | ||
f_oop,f_iip = (@RuntimeGeneratedFunction(eval_module, ex) for ex in f_gen) | ||
f_gen = generate_function(sys; expression=Val{eval_expression}, expression_module=eval_module) | ||
f_oop, _ = (@RuntimeGeneratedFunction(eval_module, ex) for ex in f_gen) | ||
f(u,p,t) = f_oop(u,p,t) |
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.
Shouldn't there also be an in-place version as well?
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.
Yes. It does get generated. But not sure if we have any use for it in discrete systems as even solvers like FunctionMap
uses the not-in-place function (not sure what it is 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.
The code copy-pasting seems easily avoidable.
Yup. I will try and refactor the code. |
@YingboMa @ChrisRackauckas Does the ODESystem assume some kind of ordering of the equations in the differential system? It looks like the (This problem is also propagating to DiscreteSystems with/without Difference operator.) |
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.
LGTM
Oh, remember to also generalize the |
Discrete system doesn't require it. Will add it in the difference operator in ODE system PR on which I have started a discussion here? |
Yes, handling |
#1088 (comment)
TODO: