Skip to content

Commit

Permalink
Fix on_event with pathway names
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Jun 20, 2024
1 parent d89ff59 commit 74df8a8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion brian2/synapses/synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ def __init__(
prepost,
objname=key,
delay=pathway_delay,
event=self.events.get(prepost, self.default_event),
event=self.events.get(key, self.default_event),
)

# Check whether any delays were specified for pathways that don't exist
Expand Down
31 changes: 31 additions & 0 deletions brian2/tests/test_synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,37 @@ def test_transmission_custom_event():
assert_allclose(mon[1].v[mon.t >= 1 * ms], 1.0)


@pytest.mark.standalone_compatible
def test_transmission_custom_event_complex():
# This was broken with release 2.6, entries in on_event where checked against pre/post
# instead of the pathway name
group = NeuronGroup(3, "v:1", threshold="v>1 and v<2", events={"over_2": "v>2"})
group.v = [0, 1.5, 2.5]

s = Synapses(
group,
group,
model="""a:integer
b:integer
c:integer
d:integer""",
on_event={
"path_a": "spike",
"path_b": "over_2",
"path_c": "spike",
"path_d": "over_2",
},
on_pre={"path_a": "a+=1", "path_b": "b+=1"},
on_post={"path_c": "c+=1", "path_d": "d+=1"},
)
s.connect()
run(defaultclock.dt)
assert all(s.a[:] == [0, 0, 0, 1, 1, 1, 0, 0, 0])
assert all(s.b[:] == [0, 0, 0, 0, 0, 0, 1, 1, 1])
assert all(s.c[:] == [0, 1, 0, 0, 1, 0, 0, 1, 0])
assert all(s.d[:] == [0, 0, 1, 0, 0, 1, 0, 0, 1])


@pytest.mark.codegen_independent
def test_invalid_custom_event():
group1 = NeuronGroup(
Expand Down
17 changes: 17 additions & 0 deletions docs_sphinx/introduction/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
Release notes
=============
Next release
------------

Selected improvements and bug fixes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Fix a bug in interpreting the ```on_event`` argument of `Synapses` for custom events and non-default pathways (a regression introduced with Brian 2.6). Thanks to forum users
``mreynes`` and ``mmiekus`` for making us aware of this issue.

Contributions
~~~~~~~~~~~~~

Other contributions outside of GitHub (ordered alphabetically, apologies to
anyone we forgot...):

- `mmiekus <https://brian.discourse.group/u/mmiekus/summary>`_
- `mreynes <https://brian.discourse.group/u/mreynes/summary>`_

Brian 2.7.0
-----------
This release contains a number of bug fixes and improvements. Notably, it is fully compatible with the upcoming numpy 2.0 release and can be installed
Expand Down

0 comments on commit 74df8a8

Please sign in to comment.