# Compare Manual Euler with Brian2 Code

**URL:** <https://brian.discourse.group/t/compare-manual-euler-with-brian2-code/1399>\
**Category:** Science, Projects, and Showcases\
**Tags:** synapses, equations, units\
**Created:** [18 February 2025 09:23 UTC](https://brian.discourse.group/t/compare-manual-euler-with-brian2-code/1399 "2025-02-18T09:23:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elnaz91](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/elnaz91/32/703_2.png) [@elnaz91](https://brian.discourse.group/u/elnaz91)\
**Post date:** [18 February 2025 09:23 UTC](https://brian.discourse.group/t/compare-manual-euler-with-brian2-code/1399/1 "2025-02-18T09:23:40Z")

</div>

Hi everyone,  
I have a Jupyter Notebook with Python code at the following link:  
[https://github.com/nematiftm/Brian2-Testing/blob/d29614b28602fc394158974c17a7db9621682b9a/LIF\_Euler.ipynb](https://github.com/nematiftm/Brian2-Testing/blob/main/LIF_Euler.ipynb)

I’m trying to replicate manual Euler method using brian2. However, when I change the time step (`dt`), I notice that the synaptic currents should have a slight delay so that the membrane potential

Could anyone help me identify where in my synapse implementation I need to make adjustments to ensure the results match exactly?

Thanks!

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [18 February 2025 16:43 UTC](https://brian.discourse.group/t/compare-manual-euler-with-brian2-code/1399/2 "2025-02-18T16:43:15Z")

</div>

Hi @elnaz91. I only had a cursory look at your notebook, but I think the reason has to do with the scheduling of events within a single time step, see [Running a simulation — Brian 2 2.8.0.4 documentation](https://brian2.readthedocs.io/en/stable/user/running.html#scheduling)

E.g. if you have equations for the membrane potential and the synaptic currents, you have to decide whether you apply the update from the equations before or after you increase the synaptic current for an incoming spike (I think your code does it after, but Brian by default does it before). Also, what you measure with a `StateMonitor` depends on whether you measure at the beginning or at the end (or at another time) during the time step. You might be interested in these two related blog posts (and potentially their screencast videos):

> **[Getting the timing right (scheduling 1)](https://briansimulator.org/posts/2020/video-scheduling-1/)**
>
> This article is written as a Jupyter notebook which you can execute and modify interactively.
> You can either download it via the "Source" link on the top right, or run it directly in the browser o

> **[Getting the timing right (scheduling 2)](https://briansimulator.org/posts/2020/video-scheduling-2/)**
>
> This article is written as a Jupyter notebook which you can execute and modify interactively.
> You can either download it via the "Source" link on the top right, or run it directly in the browser o

Hope that helps!

---

<div class="post-metadata">

**Author:** ![elnaz91](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/elnaz91/32/703_2.png) [@elnaz91](https://brian.discourse.group/u/elnaz91)\
**Post date:** [20 February 2025 00:42 UTC](https://brian.discourse.group/t/compare-manual-euler-with-brian2-code/1399/3 "2025-02-20T00:42:20Z")

</div>

Hi Marcel, Thanks for your reply! That actually helps. When I changed the monitor to **before\_threshold** , they matched again. Thanks!
