Skip to content

Commit

Permalink
Merge edea575 into a669f65
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Oct 8, 2021
2 parents a669f65 + edea575 commit 64e8734
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion brian2/synapses/synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def create_code_objects(self, run_namespace):

def initialise_queue(self):
self.eventspace = self.source.variables[self.eventspace_name].get_value()
if not self.synapses._connect_called:
n_synapses = len(self.synapses)
if n_synapses == 0 and not self.synapses._connect_called:
raise TypeError(("Synapses object '%s' does not do anything, since "
"it has not created synapses with 'connect'. "
"Set its active attribute to False if you "
Expand Down
37 changes: 35 additions & 2 deletions brian2/tests/test_network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import weakref
import copy
import logging
Expand All @@ -7,7 +6,7 @@
import uuid

import numpy as np
from numpy.testing import assert_equal
from numpy.testing import assert_equal, assert_array_equal
import pytest

from brian2 import (Clock, Network, ms, us, second, BrianObject, defaultclock,
Expand Down Expand Up @@ -1271,6 +1270,39 @@ def test_restore_with_random_state():
assert_equal(old_v, group.v)


@pytest.mark.codegen_independent
def test_store_restore_restore_synapses():
group = NeuronGroup(10, 'x : 1', threshold='False', reset='', name='group')
synapses = Synapses(group, group, on_pre='x += 1', name='synapses')
synapses.connect(i=[1, 3, 5], j=[6, 4, 2])
net = Network(group, synapses)

tmp_file = tempfile.mktemp()
net.store(filename=tmp_file)

# clear up
del net
del synapses
del group

# Recreate the network without connecting the synapses
group = NeuronGroup(10, 'x: 1', threshold='False', reset='', name='group')
synapses = Synapses(group, group, '', on_pre='x += 1', name='synapses')
net = Network(group, synapses)
try:
net.restore(filename=tmp_file)

assert len(synapses) == 3
assert_array_equal(synapses.i, [1, 3, 5])
assert_array_equal(synapses.j, [6, 4, 2])

# Tunning the network should not raise an error, despite the lack
# of Synapses.connect
net.run(0*ms)
finally:
os.remove(tmp_file)


@pytest.mark.codegen_independent
def test_defaultclock_dt_changes():
BrianLogger.suppress_name('resolution_conflict')
Expand Down Expand Up @@ -1587,6 +1619,7 @@ def test_multiple_runs_function_change():
test_store_restore_magic,
test_store_restore_magic_to_file,
test_store_restore_spikequeue,
test_store_restore_restore_synapses,
test_defaultclock_dt_changes,
test_dt_changes_between_runs,
test_dt_restore,
Expand Down

0 comments on commit 64e8734

Please sign in to comment.