|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# test_multiplicity.py |
| 4 | +# |
| 5 | +# This file is part of NEST. |
| 6 | +# |
| 7 | +# Copyright (C) 2004 The NEST Initiative |
| 8 | +# |
| 9 | +# NEST is free software: you can redistribute it and/or modify |
| 10 | +# it under the terms of the GNU General Public License as published by |
| 11 | +# the Free Software Foundation, either version 2 of the License, or |
| 12 | +# (at your option) any later version. |
| 13 | +# |
| 14 | +# NEST is distributed in the hope that it will be useful, |
| 15 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +# GNU General Public License for more details. |
| 18 | +# |
| 19 | +# You should have received a copy of the GNU General Public License |
| 20 | +# along with NEST. If not, see <http://www.gnu.org/licenses/>. |
| 21 | + |
| 22 | +import numpy as np |
| 23 | +import pytest |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.skipif_missing_threads |
| 27 | +def test_multiplicity(): |
| 28 | + """ |
| 29 | + Confirm that spike multiplicity is handled correctly. |
| 30 | +
|
| 31 | + Creates two parrot neurons and connects the first one to the second one. The |
| 32 | + first parrot neuron receives one spike with multiplicity two from a spike |
| 33 | + generator, which should be communicated as two spikes to the second parrot |
| 34 | + neuron. Each parrot neuron is connected to a spike recorder, which should |
| 35 | + record two spikes. |
| 36 | + """ |
| 37 | + |
| 38 | + import nest |
| 39 | + |
| 40 | + nest.total_num_virtual_procs = 2 |
| 41 | + |
| 42 | + sg = nest.Create("spike_generator", params={"spike_times": [1.0], "spike_multiplicities": [2]}) |
| 43 | + p_source, p_target = nest.Create("parrot_neuron", 2) |
| 44 | + sr_source, sr_target = nest.Create("spike_recorder", 2) |
| 45 | + |
| 46 | + nest.Connect(sg, p_source) |
| 47 | + nest.Connect(p_source, p_target) |
| 48 | + nest.Connect(p_source, sr_source) |
| 49 | + nest.Connect(p_target, sr_target) |
| 50 | + |
| 51 | + nest.Simulate(10) |
| 52 | + |
| 53 | + # When running this on two MPI ranks, we need to make sure we check for spike times |
| 54 | + # only on the rank responsible for the neuron recorded by the recorder. |
| 55 | + assert not p_source.local or np.array_equal(sr_source.events["times"], [2, 2]) |
| 56 | + assert not p_target.local or np.array_equal(sr_target.events["times"], [3, 3]) |
0 commit comments