ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

PresetTimeCallback with symbolic times and function of times

Open ArnoStrouwen opened this issue 1 year ago • 10 comments

It would be nice if MTK also offered PresetTimeCallback, such that we do not need to add tstops to the solve manually.

ArnoStrouwen avatar Nov 08 '24 19:11 ArnoStrouwen

Towards that end, my most common events are discrete events where the event times are given by parameters. It would be nice to have tstops automatically calculated and setup from them instead of having to remember to pass them separately.

isaacsas avatar Apr 24 '25 23:04 isaacsas

That is a very reasonable ask. Definitely should get implemented. Should probably wait for the overhaul of the symbolic event interface in v10 for ImplicitDiscreteSystem https://github.com/SciML/ModelingToolkit.jl/pull/3452 and be implemented in that form, but yes we should definitely add that.

ChrisRackauckas avatar Apr 25 '25 10:04 ChrisRackauckas

@ChrisRackauckas, if there is someone that knows the new event system that would have time to look at it can we tag this as something to have ready for v10?

isaacsas avatar May 26 '25 16:05 isaacsas

It's not breaking to add it, so I don't see why v10 would be delayed for it.

ChrisRackauckas avatar May 26 '25 19:05 ChrisRackauckas

@AayushSabharwal I assume this would be quick, just different condition matching the setup in https://github.com/SciML/DiffEqCallbacks.jl/blob/master/src/preset_time.jl but with the symbolic-defined affect!.

ChrisRackauckas avatar May 30 '25 20:05 ChrisRackauckas

Actually this is already done https://docs.sciml.ai/ModelingToolkit/stable/basics/Events/#Periodic-and-preset-time-events

ChrisRackauckas avatar Jun 04 '25 19:06 ChrisRackauckas

But that does not support symbolic parameters as the event time, or requires one to use a more general symbolic discrete callback and have to then manually pass the tstop value to solve.

isaacsas avatar Jun 04 '25 19:06 isaacsas

I see, you want parameters in time. We can make that work, but that wasn't mentioned 😅

ChrisRackauckas avatar Jun 04 '25 19:06 ChrisRackauckas

Yeah a way to just give a list of symbolic parameters representing preset times or representing periodic times, along with the symbolic affects, and then just have everything work via the values given in the parameter map. So avoiding any need to pass a tstop or hardcode a numerical value in the symbolic callback.

isaacsas avatar Jun 04 '25 19:06 isaacsas

Yup that's a reasonable ask.

ChrisRackauckas avatar Jun 04 '25 19:06 ChrisRackauckas