nest / nest-simulator

The NEST simulator
http://www.nest-simulator.org
GNU General Public License v2.0
544 stars 370 forks source link

NEST behaves incorrectly and potentially segfaults if number of threads changed after parameters are created #3228

Open heplesser opened 5 months ago

heplesser commented 5 months ago

The test below will fail if run as is. If the number of threads is changed before p = nest.random.normal(mean=0, std=1) all works well. Otherwise, there is also a risk of a seg.fault. This applies at present to normal and lognormal parameters only and is due to the fact that these two parameter types maintain per-thread objects internally (https://github.com/nest/nest-simulator/blob/c6aacad4bb5a0685bdf8414e0bf366ed16a88a9b/nestkernel/parameter.cpp#L95, https://github.com/nest/nest-simulator/blob/c6aacad4bb5a0685bdf8414e0bf366ed16a88a9b/nestkernel/parameter.cpp#L121).

We currently have no way of detecting the existence of parameter objects. Since there objects live outside the kernel (at the Python level), they also are not subject to ResetKernel. Fixing this will thus require some careful thought.

Until we have a proper fix, we should add a clear warning on https://nest-simulator.readthedocs.io/en/stable/neurons/parametrization.html.

import nest

p = nest.random.normal(mean=0, std=1)
nest.local_num_threads = 2

n = nest.Create('iaf_psc_exp')

num_rounds = 10
v = []
for _ in range(num_rounds):
    n.set(V_m=p)
    v.append(n.V_m)

assert len(set(v)) == num_rounds  # all v must differ
heplesser commented 5 months ago

3229 adds a warning to documentation, but does not provide a fix.

github-actions[bot] commented 3 months ago

Issue automatically marked stale!