Skip to content

Commit

Permalink
Merge d6dcffd into 1cce57a
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Oct 25, 2021
2 parents 1cce57a + d6dcffd commit 97b1b08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion brian2/core/base.py
Expand Up @@ -132,7 +132,8 @@ def __init__(self, dt=None, clock=None, when='start', order=0,

# Make sure that keys in the namespace are valid
if namespace is None:
namespace = {}
# Do not overwrite namespace if already set (e.g. in StateMonitor)
namespace = getattr(self, 'namespace', {})
for key in namespace:
if key.startswith('_'):
raise ValueError("Names starting with underscores are "
Expand Down
9 changes: 9 additions & 0 deletions brian2/tests/test_monitor.py
Expand Up @@ -432,6 +432,15 @@ def test_state_monitor_resize():
# variable that is visible to the user
assert mon.variables['v'].size == (10, 2)

@pytest.mark.codegen_independent
def test_statemonitor_namespace():
# Make sure that StateMonitor is correctly inheriting its source's namespace
G = NeuronGroup(2, 'x = i + y : integer', namespace={'y': 3})
mon = StateMonitor(G, 'x', record=True)
run(defaultclock.dt, namespace={})
assert_array_equal(mon.x, [[3], [4]])


@pytest.mark.standalone_compatible
def test_rate_monitor_1():
G = NeuronGroup(5, 'v : 1', threshold='v>1') # no reset
Expand Down

0 comments on commit 97b1b08

Please sign in to comment.