# \#diffeqcallbacks

**URL:** https://discourse.julialang.org/tag/diffeqcallbacks/838.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Spiking Neural Model](https://discourse.julialang.org/t/spiking-neural-model/135029)

<div class="topic-metadata">

**Author:** [@tbzcn](https://discourse.julialang.org/u/tbzcn)\
**Replies:** 1\
**Last updated:** [January 21, 2026, 5:01am UTC](https://discourse.julialang.org/t/spiking-neural-model/135029 "2026-01-21T05:01:49Z")

</div>

Hi, I am new to Julia and my aim is to create a network of spiking neurons. I use simple leaky integrate and fire (LIF) model for now with ODEProblem solver. Whenever the neuron (u) reaches a threshold value, it should …

---

## [Can a callback be triggered at the initial time point (at t=0)](https://discourse.julialang.org/t/can-a-callback-be-triggered-at-the-initial-time-point-at-t-0/114376)

<div class="topic-metadata">

**Author:** [@valerdam](https://discourse.julialang.org/u/valerdam)\
**Replies:** 3\
**Last updated:** [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 "2025-12-16T10:54:09Z")

</div>

I am using the code from advanced\_simulations - (the one using CallbackSets) and just modified the time to include t=0.0. ps\_cb\_1 = PresetTimeCallback(\[3.0, 7.0\], integ -\> integ\[:X1\] += 5.0) and added a time zero ps\_c…

---

## [Large allocations with MTK event](https://discourse.julialang.org/t/large-allocations-with-mtk-event/133680)

<div class="topic-metadata">

**Author:** [@klinders](https://discourse.julialang.org/u/klinders)\
**Replies:** 1\
**Last updated:** [November 5, 2025, 11:35pm UTC](https://discourse.julialang.org/t/large-allocations-with-mtk-event/133680 "2025-11-05T23:35:22Z")

</div>

Dear all, Recently, you helped me get events working in MTK. Thank you for all the help! Continuing on the topic, I ran into a performance issue with events. I have the following code to measure the time and allocation…

---

## [Inconsistency with SavingCallback](https://discourse.julialang.org/t/inconsistency-with-savingcallback/132321)

<div class="topic-metadata">

**Author:** [@dnldlg](https://discourse.julialang.org/u/dnldlg)\
**Replies:** 1\
**Last updated:** [September 19, 2025, 12:09am UTC](https://discourse.julialang.org/t/inconsistency-with-savingcallback/132321 "2025-09-19T00:09:46Z")

</div>

I try to track the behavior of the parameters throughout an integration with DifferentialEquations.jl while using Callbacks. To do this I used SavingCallback, but noticed the following inconsistency with the argument sa…

---

## [PresetTimeCallback with array in affect function](https://discourse.julialang.org/t/presettimecallback-with-array-in-affect-function/131806)

<div class="topic-metadata">

**Author:** [@Marco\_Masi](https://discourse.julialang.org/u/Marco_Masi)\
**Replies:** 1\
**Last updated:** [August 24, 2025, 11:57am UTC](https://discourse.julialang.org/t/presettimecallback-with-array-in-affect-function/131806 "2025-08-24T11:57:08Z")

</div>

I’m trying to understand how to use the PresetTimeCallback(tstops,affect!) where tstops is an array of time steps and the affect function should also affect the integration each time with different values. For example, …

---

## [Discrete callback is triggered twice each time](https://discourse.julialang.org/t/discrete-callback-is-triggered-twice-each-time/127059)

<div class="topic-metadata">

**Author:** [@amynang](https://discourse.julialang.org/u/amynang)\
**Replies:** 15\
**Last updated:** [April 3, 2025, 1:26pm UTC](https://discourse.julialang.org/t/discrete-callback-is-triggered-twice-each-time/127059 "2025-04-03T13:26:35Z")

</div>

I am working on a Lotka-Volterra type competition system. I am trying to specify a rule such that at pre-specified time-points the (one) species with the lowest abundance at that time-step is eliminated. I am using a dis…

---

## [Gradual parameter changes via callbacks](https://discourse.julialang.org/t/gradual-parameter-changes-via-callbacks/127156)

<div class="topic-metadata">

**Author:** [@vh94](https://discourse.julialang.org/u/vh94)\
**Replies:** 3\
**Last updated:** [March 21, 2025, 5:58am UTC](https://discourse.julialang.org/t/gradual-parameter-changes-via-callbacks/127156 "2025-03-21T05:58:16Z")

</div>

Problem I’m trying to change the parameter of a dynamical system gradually. In the documentation for the DifferentialEquations library there is an emphasis on abrupt / instantaneous change - when explaining callbacks ; …

---

## [DifferentialEquations.jl: Exception thrown in callback of solve command that is handled by a try-catch block inside another solve command causes the outer solve command to fail](https://discourse.julialang.org/t/differentialequations-jl-exception-thrown-in-callback-of-solve-command-that-is-handled-by-a-try-catch-block-inside-another-solve-command-causes-the-outer-solve-command-to-fail/126466)

<div class="topic-metadata">

**Author:** [@novalex98](https://discourse.julialang.org/u/novalex98)\
**Replies:** 8\
**Last updated:** [March 3, 2025, 6:26am UTC](https://discourse.julialang.org/t/differentialequations-jl-exception-thrown-in-callback-of-solve-command-that-is-handled-by-a-try-catch-block-inside-another-solve-command-causes-the-outer-solve-command-to-fail/126466 "2025-03-03T06:26:39Z")

</div>

I observed this with the latest version of julia, Running on a Windows 11 PC. tl dr: I have an exception being thrown in a callback for a solve command that’s inside another solve command. I have a try-catch block to ha…

---

## [Storing only rolling mean and variance when solving SDEProblems](https://discourse.julialang.org/t/storing-only-rolling-mean-and-variance-when-solving-sdeproblems/125900)

<div class="topic-metadata">

**Author:** [@johannesnauta](https://discourse.julialang.org/u/johannesnauta)\
**Replies:** 5\
**Last updated:** [February 17, 2025, 1:51pm UTC](https://discourse.julialang.org/t/storing-only-rolling-mean-and-variance-when-solving-sdeproblems/125900 "2025-02-17T13:51:29Z")

</div>

Hi all, I have been trying to reduce memory overhead as I found that in my systems of interest there were a lot of unnecessary reads/writes as the state was saved at each (specified) interval dt. In fact, for my purpose…

---

## [Count of diff eq callbacks](https://discourse.julialang.org/t/count-of-diff-eq-callbacks/121546)

<div class="topic-metadata">

**Author:** [@Egwene\_al\_Vere](https://discourse.julialang.org/u/Egwene_al_Vere)\
**Replies:** 0\
**Last updated:** [October 21, 2024, 5:39pm UTC](https://discourse.julialang.org/t/count-of-diff-eq-callbacks/121546 "2024-10-21T17:39:18Z")

</div>

using DiscreteCallback, is there a built-in way to know the number of times the affect! function is called both inside the affect! function and after solve/step! call is completed? current;y, i’m using a ref value in the…

---

## [Saving only after discrete callback](https://discourse.julialang.org/t/saving-only-after-discrete-callback/120790)

<div class="topic-metadata">

**Author:** [@pulk\_jain](https://discourse.julialang.org/u/pulk_jain)\
**Replies:** 4\
**Last updated:** [October 21, 2024, 12:05pm UTC](https://discourse.julialang.org/t/saving-only-after-discrete-callback/120790 "2024-10-21T12:05:26Z")

</div>

Discrete callback is saving both before and after the callback even when save\_positions = (false,true). For example: function dynamics(u,p,t) du = \[2.0,3.0,1.0\] return du end prob = ODEProblem(dynamics, \[0.0,…

---

## [Hybrid ODE with ContinuousCallback for models of changing sizes?](https://discourse.julialang.org/t/hybrid-ode-with-continuouscallback-for-models-of-changing-sizes/115198)

<div class="topic-metadata">

**Author:** [@natalieisenberg](https://discourse.julialang.org/u/natalieisenberg)\
**Replies:** 25\
**Last updated:** [June 17, 2024, 3:39pm UTC](https://discourse.julialang.org/t/hybrid-ode-with-continuouscallback-for-models-of-changing-sizes/115198 "2024-06-17T15:39:24Z")

</div>

I am solving a system of ODEs with a ContinuousCallback where once a condition!() is met, certain members of the state vector are removed (i.e., elements disappear during simulation). I would like to solve this system us…

---

## [Callback function modifying model parameter](https://discourse.julialang.org/t/callback-function-modifying-model-parameter/114478)

<div class="topic-metadata">

**Author:** [@valerdam](https://discourse.julialang.org/u/valerdam)\
**Replies:** 15\
**Last updated:** [May 22, 2024, 12:17pm UTC](https://discourse.julialang.org/t/callback-function-modifying-model-parameter/114478 "2024-05-22T12:17:19Z")

</div>

I need to modify a parameter in an ODE problem in a callback. I found an example that does exactly what I want in here. (on the page search for PresetTimeCallback and it is the code including the first occurrence). Copie…

---

## [DiscreteCallback takes a break: discrete callback shows counterintuitive behaviour in DifferentialEquations.jl](https://discourse.julialang.org/t/discretecallback-takes-a-break-discrete-callback-shows-counterintuitive-behaviour-in-differentialequations-jl/112768)

<div class="topic-metadata">

**Author:** [@flmuk](https://discourse.julialang.org/u/flmuk)\
**Replies:** 2\
**Last updated:** [April 11, 2024, 3:36pm UTC](https://discourse.julialang.org/t/discretecallback-takes-a-break-discrete-callback-shows-counterintuitive-behaviour-in-differentialequations-jl/112768 "2024-04-11T15:36:34Z")

</div>

Hello, I have a question about the behaviour of callbacks using DifferentialEquations.jl, because I find the behaviour of DiscreteCallbacks counterintuitive. Consider the following code, i.e. an adaptation of this: us…

---

## [DiffEqCallback and quadrature calculation with IntegratingCallback](https://discourse.julialang.org/t/diffeqcallback-and-quadrature-calculation-with-integratingcallback/110836)

<div class="topic-metadata">

**Author:** [@a6a3uh](https://discourse.julialang.org/u/a6a3uh)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 9:36am UTC](https://discourse.julialang.org/t/diffeqcallback-and-quadrature-calculation-with-integratingcallback/110836 "2024-02-27T09:36:58Z")

</div>

Hi! I’m trying to calculate some integral along the IVP for some ODE. In particular I’m calculating a running cost for my control system simulation (or value of some functional). It looks like IntegratingCallback and In…

---

## [Handling callbacks](https://discourse.julialang.org/t/handling-callbacks/110096)

<div class="topic-metadata">

**Author:** [@Gabriel\_Carita](https://discourse.julialang.org/u/Gabriel_Carita)\
**Replies:** 2\
**Last updated:** [February 13, 2024, 8:38am UTC](https://discourse.julialang.org/t/handling-callbacks/110096 "2024-02-13T08:38:04Z")

</div>

Hi there, I need to verify collisions between two rotating ellipses. At the moment, I’m using continuous callbacks; however, I’m not sure if this is the most efficient way or how to do it. I need the collisions to be ch…

---

## [Continuously tracking callback with boolean condition](https://discourse.julialang.org/t/continuously-tracking-callback-with-boolean-condition/106937)

<div class="topic-metadata">

**Author:** [@flmuk](https://discourse.julialang.org/u/flmuk)\
**Replies:** 1\
**Last updated:** [November 30, 2023, 9:50am UTC](https://discourse.julialang.org/t/continuously-tracking-callback-with-boolean-condition/106937 "2023-11-30T09:50:07Z")

</div>

Hello, I have the following system of equations: using DifferentialEquations using Plots u\_rest = -50. t\_ref = 2. u\_reset = -75. u\_thr = -55. J = 1. last\_spikes = \[1., 1.\] .\* (- t\_ref + eps()) function decay(du, u, p…

---

## [Adding and updating a scalar to the Integerator Cache in DifferentialEquations.jl](https://discourse.julialang.org/t/adding-and-updating-a-scalar-to-the-integerator-cache-in-differentialequations-jl/103805)

<div class="topic-metadata">

**Author:** [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Replies:** 12\
**Last updated:** [September 14, 2023, 3:28pm UTC](https://discourse.julialang.org/t/adding-and-updating-a-scalar-to-the-integerator-cache-in-differentialequations-jl/103805 "2023-09-14T15:28:02Z")

</div>

Background. I have a nice stochastic jump-piecewise-ODE behaving as it should. Thanks @ChrisRackauckas and team! Basically this would have been completely impossible in any other language/package! Now I want to calculat…

---

## [Memory allocation when solving ODE with Vern7 and ContinuousCallback](https://discourse.julialang.org/t/memory-allocation-when-solving-ode-with-vern7-and-continuouscallback/101087)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 2\
**Last updated:** [August 29, 2023, 5:27am UTC](https://discourse.julialang.org/t/memory-allocation-when-solving-ode-with-vern7-and-continuouscallback/101087 "2023-08-29T05:27:39Z")

</div>

Hello, I went through a memory allocation problem in a ODE system, when using Vern7() algorithm and ContinuousCallback. The minimal working example is the following: using LinearAlgebra using SparseArrays using Ordinar…

---

## [Callbacks within CallbackSet interfering with each other](https://discourse.julialang.org/t/callbacks-within-callbackset-interfering-with-each-other/102452)

<div class="topic-metadata">

**Author:** [@cmdenis](https://discourse.julialang.org/u/cmdenis)\
**Replies:** 2\
**Last updated:** [August 7, 2023, 4:57pm UTC](https://discourse.julialang.org/t/callbacks-within-callbackset-interfering-with-each-other/102452 "2023-08-07T16:57:31Z")

</div>

Hi there, I’m trying to use callbacks to create pulses to two identical systems ran through the same set of differential equations. It seems like putting the two Callbacks together results in the Callbacks somehow inter…

---

## [Callback Function Example in DifferentialEquations.jl](https://discourse.julialang.org/t/callback-function-example-in-differentialequations-jl/102371)

<div class="topic-metadata">

**Author:** [@yoshi](https://discourse.julialang.org/u/yoshi)\
**Replies:** 2\
**Last updated:** [August 1, 2023, 9:45pm UTC](https://discourse.julialang.org/t/callback-function-example-in-differentialequations-jl/102371 "2023-08-01T21:45:54Z")

</div>

I’m trying to understand how to use callback functions with Julia’s solve package. I’m using the code example pasted below and obtaining an error. I’m struggling to understand what I need to fix. Any ideas? using Differ…

---

## [Using callback functions when solving pde's with MethodOfLines](https://discourse.julialang.org/t/using-callback-functions-when-solving-pdes-with-methodoflines/101379)

<div class="topic-metadata">

**Author:** [@mkretzschmar](https://discourse.julialang.org/u/mkretzschmar)\
**Replies:** 1\
**Last updated:** [July 9, 2023, 10:38am UTC](https://discourse.julialang.org/t/using-callback-functions-when-solving-pdes-with-methodoflines/101379 "2023-07-09T10:38:22Z")

</div>

I am using the MethodOfLines package for solving a system of first order pde’s. Now I want to introduce callback functions to handle discrete events. It is unclear to me how to call the integrator, because the pde system…

---

## [Extra allocations performing dot product in ODE callback](https://discourse.julialang.org/t/extra-allocations-performing-dot-product-in-ode-callback/100683)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 3\
**Last updated:** [June 23, 2023, 3:10pm UTC](https://discourse.julialang.org/t/extra-allocations-performing-dot-product-in-ode-callback/100683 "2023-06-23T15:10:35Z")

</div>

Hello, I’m experiencing some extra memory allocations when calculating the dot product inside a ODE callback. Here I write a minimal example A = sprand(ComplexF64, 100, 100, 0.05) u0 = rand(ComplexF64, 100) y = rand(Co…

---

## [Selecting a specific cycle to perform operation during a callback](https://discourse.julialang.org/t/selecting-a-specific-cycle-to-perform-operation-during-a-callback/94804)

<div class="topic-metadata">

**Author:** [@xztt](https://discourse.julialang.org/u/xztt)\
**Replies:** 1\
**Last updated:** [February 25, 2023, 3:33pm UTC](https://discourse.julialang.org/t/selecting-a-specific-cycle-to-perform-operation-during-a-callback/94804 "2023-02-25T15:33:03Z")

</div>

Hi all, Below is a simple example of me performing a Kalman filtration on 3 periodic cycles of a model. We generate data for all 3 cycles and perform a Kalman filtration forcing the time step and utilising the integrato…

---

## [SavingCallback influences result of ODE problem](https://discourse.julialang.org/t/savingcallback-influences-result-of-ode-problem/91731)

<div class="topic-metadata">

**Author:** [@Pitaevskii](https://discourse.julialang.org/u/Pitaevskii)\
**Replies:** 9\
**Last updated:** [January 3, 2023, 1:27pm UTC](https://discourse.julialang.org/t/savingcallback-influences-result-of-ode-problem/91731 "2023-01-03T13:27:30Z")

</div>

Hello I have some code for simulating complex differential equations of a certain model that used to work fine, but fails after going from Julia 1.7 to 1.8 and updating all the packages. using DifferentialEquations, Di…

---

## [Zombies in biological ODE : why is my solver not sticking to zero?](https://discourse.julialang.org/t/zombies-in-biological-ode-why-is-my-solver-not-sticking-to-zero/90409)

<div class="topic-metadata">

**Author:** [@iago-lito](https://discourse.julialang.org/u/iago-lito)\
**Replies:** 25\
**Last updated:** [November 21, 2022, 9:00am UTC](https://discourse.julialang.org/t/zombies-in-biological-ode-why-is-my-solver-not-sticking-to-zero/90409 "2022-11-21T09:00:32Z")

</div>

Hi numerical ODE solvers enthusiasts, we’ve got a problem here that we think necessitates your kind input :slight\_smile: Here are two related questions: The following ODE system represents biological species biomasses B…

---

## [AD in DiffEqFlux using DiscreteCallback](https://discourse.julialang.org/t/ad-in-diffeqflux-using-discretecallback/89748)

<div class="topic-metadata">

**Author:** [@facusapienza](https://discourse.julialang.org/u/facusapienza)\
**Replies:** 1\
**Last updated:** [November 9, 2022, 12:07am UTC](https://discourse.julialang.org/t/ad-in-diffeqflux-using-discretecallback/89748 "2022-11-09T00:07:10Z")

</div>

I am trying to implement a callback term in my ODE solver and using Zygote to differentiate with respect to the model parameters. The action that callback uses is very simple and not very different to the one used in Eve…

---

## [ODE terms dependent on time of events](https://discourse.julialang.org/t/ode-terms-dependent-on-time-of-events/88962)

<div class="topic-metadata">

**Author:** [@KalelR](https://discourse.julialang.org/u/KalelR)\
**Replies:** 5\
**Last updated:** [October 27, 2022, 10:13am UTC](https://discourse.julialang.org/t/ode-terms-dependent-on-time-of-events/88962 "2022-10-27T10:13:26Z")

</div>

Hey there I would like some advice for implementing efficient code for a spiking neuron network with coupling that depends on spike times. When a neuron in the model spikes (one of its variables, the membrane potential,…

---

## [Multiple Condition for DifferentialEquations callback](https://discourse.julialang.org/t/multiple-condition-for-differentialequations-callback/89308)

<div class="topic-metadata">

**Author:** [@pimler73](https://discourse.julialang.org/u/pimler73)\
**Replies:** 1\
**Last updated:** [October 26, 2022, 5:11pm UTC](https://discourse.julialang.org/t/multiple-condition-for-differentialequations-callback/89308 "2022-10-26T17:11:46Z")

</div>

I am solving an IVP with the DifferentialEquations package and I am looking to find n events with a specific condition. The issue rises from the fact that my events require 2 conditions to be satisfied. I am using Contin…

---

## [Error when trying to dynamically change \`tstops\` during \`solve\`](https://discourse.julialang.org/t/error-when-trying-to-dynamically-change-tstops-during-solve/81999)

<div class="topic-metadata">

**Author:** [@InPhyT](https://discourse.julialang.org/u/InPhyT)\
**Replies:** 2\
**Last updated:** [May 31, 2022, 3:46pm UTC](https://discourse.julialang.org/t/error-when-trying-to-dynamically-change-tstops-during-solve/81999 "2022-05-31T15:46:22Z")

</div>

Hello, I’m modeling a simple integrate and fire neuron that takes spike width into account by suspending the integration (and thus ignoring the input current) for a few milliseconds after a spike has been elicited. Let’…

[Next page](https://discourse.julialang.org/tag/diffeqcallbacks/838.md?match_all_tags=true&page=1&tags%5B%5D=diffeqcallbacks)
