# Can a callback be triggered at the initial time point (at t=0)

**URL:** https://discourse.julialang.org/t/can-a-callback-be-triggered-at-the-initial-time-point-at-t-0/114376
**Category:** General Usage
**Tags:** catalyst, diffeqcallbacks
**Created:** [May 16, 2024, 8:36pm UTC](https://discourse.julialang.org/t/can-a-callback-be-triggered-at-the-initial-time-point-at-t-0/114376 "2024-05-16T20:36:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![valerdam](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@valerdam](https://discourse.julialang.org/u/valerdam)
#### Post date: [May 16, 2024, 8:36pm UTC](https://discourse.julialang.org/t/can-a-callback-be-triggered-at-the-initial-time-point-at-t-0/114376/1 "2024-05-16T20:36:04Z")

</div>

I am using the code from [advanced\_simulations](https://docs.sciml.ai/Catalyst/stable/catalyst_applications/advanced_simulations/#advanced_simulations) - (the one using CallbackSets) and just modified the time to include t=0.0.

```julia
ps_cb_1 = PresetTimeCallback([3.0, 7.0], integ -> integ[:X1] += 5.0)

```

and added a time zero

```julia
ps_cb_1 = PresetTimeCallback([0.0, 3.0, 7.0], integ -> integ[:X1] += 5.0)

```

but it does not get triggered at t=0, however adding t=1e-14 works fine.

```julia
ps_cb_1 = PresetTimeCallback([1e-14, 3.0, 7.0], integ -> integ[:X1] += 5.0)

```

Is this the expected behavior ?

I guess at the first time step of the integrator t\>0 therefore it would miss t=0.

If so is there an elegant way to trigger the callback at t=0. Of course one can modify the defaults but it is not very pretty.

Many thanks for your input.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [May 16, 2024, 8:58pm UTC](https://discourse.julialang.org/t/can-a-callback-be-triggered-at-the-initial-time-point-at-t-0/114376/2 "2024-05-16T20:58:16Z")

</div>

I think it might work if you set `ps_cb_1 = PresetTimeCallback([0.0, 3.0, 7.0], integ -> integ[:X1] += 5.0, filter_tstops=false)`

---

<div class="post-metadata">

### Author: ![valerdam](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@valerdam](https://discourse.julialang.org/u/valerdam)
#### Post date: [May 16, 2024, 9:10pm UTC](https://discourse.julialang.org/t/can-a-callback-be-triggered-at-the-initial-time-point-at-t-0/114376/3 "2024-05-16T21:10:46Z")

</div>

> [@Oscar\_Smith](#):
>
> filter\_tstops=false

Thanks for the input - made me look for the docs on [PresetTimeCallback](https://docs.sciml.ai/DiffEqCallbacks/stable/timed_callbacks/).

Unfortunately the callback still does not get triggered at t-0.

From the docs the flag controls whether to filter out tstops beyond _the end_  
of the integration timespan and what I need in the very beginning.

---

<div class="post-metadata">

### Author: ![nilsbecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilsbecker/32/12157_2.png) [@nilsbecker](https://discourse.julialang.org/u/nilsbecker)
#### Post date: [December 16, 2025, 10:54am UTC](https://discourse.julialang.org/t/can-a-callback-be-triggered-at-the-initial-time-point-at-t-0/114376/4 "2025-12-16T10:54:09Z")

</div>

Resurrecting this thread for posterity:

I prodded around and found that setting the `initialize` keyword to a no-op similar to this:

```julia
PresetTimeCallback([0., 3.], integ-> integ[:X1] += 5., initialize=(_cb, _u, _p, _t) -> nothing)

```

makes the solver do the modification at the initial time. You have to make sure to handle `save_positions` with care. I had it set to `(true,true)` and then got two `tstops` at the initial time, so that the very first `u` value still does not have the callback effect, but the next `u` value, still at the initial time, has it.
