/*
 *  test_iaf_ring.sli
 *
 *  This file is part of NEST.
 *
 *  Copyright (C) 2004 The NEST Initiative
 *
 *  NEST is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  NEST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


/* BeginDocumentation
Name: testsuite::test_iaf_ring - sli script for test of iaf_neuron spike interaction
across multiple machines.

Synopsis: nest_indirect test_iaf_ring  --> success

Description:

 test_iaf_ring checks if spikes can travel along a chain of neurons
 and whether the result is independent of the number of machines 
 involved in the computation.

 The unittest function distributed_assert_or_die can only handle the
 output of a single machine. Therefore the script collects the spikes
 of all neurons using a parrot neuron. The script does not check the 
 id of the sender, only the spike timing. A more strict test could be 
 carried out with a unittest function which merges the output of all 
 machines.

 The correct sequence of spikes including their ids is documented at
 the end of this file. Note that due to the use of an intermediate
 parrot neuron the reported spike times have an offset of 1ms (10
 steps) with respect to the documented values. The offset corresponds
 to the default delay of 1ms.

Author: Joche Martin Eppler, Markus Diesmann, Marc-Oliver Gewaltig
FirstVersion: January 2006
SeeAlso: testsuite::test_iaf_i0, testsuite::test_getrng_neuron
*/

(unittest) run
/unittest using


/delay         2.0 def        % delay between neurons
/h             0.1 def        % time resolution
/simtime      35.0 def        % simulation time
/recend    simtime def        % end of recording
/n               4 def
/neurons  [n] Range def

[1 2 4]
{
 ResetKernel

 0 << /resolution h  >> SetStatus

 /iaf_neuron n Create ;
 1 << /I_e 1450.0 >>  SetStatus

 neurons 2 1 Partition
   { arrayload pop 1000.0 delay Connect } forall

 /spike_detector  << /withtime true /time_in_steps true >> Create /sd Set

 /parrot_neuron Create /pn Set

 neurons [pn] Connect
 [pn] [sd] Connect

 simtime Simulate

 pn /local get                                 
 { 
  sd [/events/times] get cva
 } if                                          

}
distributed_invariant_assert_or_die


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%
% Expected output of this script. 
% An intermediate parrot neuron introduces an offset of 10 in the 
% spike times corresponding to the default delay of 1ms.
%  
% gid     spiketime
% 1       30
% 1       80
% 2       111
% 1       130
% 2       174
% 1       180
% 3       205
% 1       230
% 2       234
% 1       280
% 3       280
% 2       294
% 4       313
% 1       330
