@@ -209,7 +209,21 @@ function get_callbacks(nw::Network)
209
209
elseif length (cbbs) == 1
210
210
return to_callback (only (cbbs))
211
211
else
212
- CallbackSet (to_callback .(cbbs)... )
212
+ # we split in discrete and continous manually, otherwise the CallbackSet
213
+ # construction can take forever
214
+ discrete_cb = []
215
+ continous_cb = []
216
+ for batch in cbbs
217
+ cb = to_callback (batch)
218
+ if cb isa SciMLBase. AbstractContinuousCallback
219
+ push! (continous_cb, cb)
220
+ elseif cb isa SciMLBase. AbstractDiscreteCallback
221
+ push! (discrete_cb, cb)
222
+ else
223
+ error (" Unknown callback type, should never be reached. Please report this issue." )
224
+ end
225
+ end
226
+ CallbackSet (Tuple (continous_cb), Tuple (discrete_cb));
213
227
end
214
228
end
215
229
@@ -443,15 +457,15 @@ end
443
457
# ###
444
458
# ### wrapping of discrete callbacks
445
459
# ###
446
- struct DiscreteCallbackWrapper{N, ST,T} <: CallbackWrapper
447
- nw:: N
460
+ struct DiscreteCallbackWrapper{ST,T} <: CallbackWrapper
461
+ nw:: Network
448
462
component:: ST
449
463
callback:: T
450
464
function DiscreteCallbackWrapper (nw, component, callback)
451
465
@assert nw isa Network
452
466
@assert component isa SymbolicIndex
453
467
@assert callback isa Union{DiscreteComponentCallback, PresetTimeComponentCallback}
454
- new {typeof(nw),typeof( component),typeof(callback)} (nw, component, callback)
468
+ new {typeof(component),typeof(callback)} (nw, component, callback)
455
469
end
456
470
end
457
471
@@ -463,7 +477,7 @@ function to_callback(dcw::DiscreteCallbackWrapper)
463
477
DiscreteCallback (cond, affect; kwargs... )
464
478
end
465
479
# generate a PresetTimeCallback from a DiscreteCallbackWrapper
466
- function to_callback (dcw:: DiscreteCallbackWrapper{<:Any,<:Any,<: PresetTimeComponentCallback} )
480
+ function to_callback (dcw:: DiscreteCallbackWrapper{<:Any,<:PresetTimeComponentCallback} )
467
481
kwargs = dcw. callback. kwargs
468
482
affect = _batch_affect (dcw)
469
483
ts = dcw. callback. ts
0 commit comments