1/*
2 *  nest-init.sli
3 *
4 *  This file is part of NEST.
5 *
6 *  Copyright (C) 2004 The NEST Initiative
7 *
8 *  NEST is free software: you can redistribute it and/or modify
9 *  it under the terms of the GNU General Public License as published by
10 *  the Free Software Foundation, either version 2 of the License, or
11 *  (at your option) any later version.
12 *
13 *  NEST is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *  GNU General Public License for more details.
17 *
18 *  You should have received a copy of the GNU General Public License
19 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24%% NEST Kernel 2 initialisation
25%%
26%% (C) 2000-2006 The NEST Initiative
27%%
28%%  Authors Marc-Oliver Gewaltig <marc-oliver.gewaltig@honda-ri.de>
29%%          Markus Diesmann <diesmann@fz-juelich.de>
30%%          Jochen Martin Eppler <eppler@fz-juelich.de>
31%%
32
33M_DEBUG (nest-init.sli) (Initializing SLI support for NEST Kernel.) message
34% see nestmodule.cpp
35
36% Add NEST example directory to search-path
37statusdict /prgdocdir get (/examples)                  join addpath
38statusdict /prgdocdir get (/examples/FacetsBenchmarks) join addpath
39
40/test {
41  statusdict/prgdatadir :: (/testsuite/do_tests.sh ) join
42  statusdict/prefix :: (/bin/nest) join
43  join system ; ;
44} def
45
46%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
48% add new functions to trie if it exists, else create new
49/SetStatus dup lookup not
50{
51  trie
52} if
53[/integertype /dictionarytype] /SetStatus_id load addtotrie
54[/connectiontype /dictionarytype] /SetStatus_CD load addtotrie
55def
56
57% add new functions to trie if it exists, else create new
58/GetStatus dup lookup not
59{
60  trie
61} if
62[/integertype] /GetStatus_i load addtotrie
63[/connectiontype] /GetStatus_C load addtotrie
64[/arraytype] /GetStatus_a load addtotrie
65def
66
67
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69
70% These variants of get access network elements represented by
71% a node_id like dictionaries. In particular, if a node_id returns a dictionary,
72% get can be used to access the contents of the nested objects.
73% 071108, Diesmann
74%
75/get [/integertype /literaltype] {exch GetStatus exch get} def
76/get [/integertype /arraytype] {exch GetStatus exch get_d_a} def
77
78% Same as above for connections
79% 100922, Diesmann
80/get [/connectiontype /literaltype] {exch GetStatus exch get} def
81/get [/connectiontype /arraytype] {exch GetStatus exch get_d_a} def
82
83% The following version allows extraction of a node ID from a NodeCollection
84/get [/nodecollectiontype /integertype] { get_g_i } def
85
86% This version gets all values from all nodes. The same as GetStatus, but
87% concatenates into a single dictionary.
88/get [/nodecollectiontype]
89{
90  GetStatus
91  /status_dict << >> def
92
93  size 1 neq
94  { % If not a single value NodeCollection. We have a list of dictionaries.
95
96    % The first thing we do is set the keys in the dictionary based on the
97    % first node ID in the NodeCollection, and set the corresponding value in an
98    % array.
99    dup First {status_dict rollu 1 arraystore put_d} forall
100
101    status_dict keys /ks Set
102
103    % Then, we put the values for the rest of the NodeCollection in the right
104    % place in the dictionary.
105    /counter 1 def
106    Rest
107    {
108      dup
109      {
110        /v Set
111        /k Set
112        % Check if we have a composite NodeCollection by checking if k is part
113        % of dict keys.
114        ks k MemberQ
115        {
116          % If primitive, add value to dictionary array
117          status_dict k get [v] join /val_array Set
118        }
119        {
120          % If composite, set values for previous node IDs to None, and add value.
121          [counter] /None LayoutArray [v] join /val_array Set
122          ks [k] join /ks Set
123        } ifelse
124
125        % Add value array to status dictionary.
126        status_dict k val_array put_d
127      } forall
128
129      % If we have a composite nc and there have been values for previous node IDs
130      % that is not part of this particular dictionary, we must set a None
131      % value for this value.
132      keys /dict_keys Set
133      ks
134      {
135        /k Set
136        dict_keys k MemberQ not
137        {
138          status_dict k get [/None] join /val_array Set
139          status_dict k val_array put_d
140        } if
141      } forall
142
143      counter 1 add /counter Set
144    } forall
145
146    status_dict
147  }
148  {
149    0 get
150  } ifelse
151} def
152
153% Get parameter value of all node IDs in NodeCollection
154/get [/nodecollectiontype /literaltype]
155{
156  /value Set
157  /nodecollection Set
158
159  nodecollection size 1 eq
160  { % if size == 1
161    nodecollection GetStatus 0 get value get
162  }
163  { % if size > 1
164    nodecollection GetStatus { value get } Map
165  } ifelse
166} def
167
168% Get parameter values of NodeCollection from an array of parameters
169/get [/nodecollectiontype /arraytype]
170{
171  exch
172  dup size 1 eq not{ /get /InvalidNodeCollectionError raiseerror }if
173  0 get_g_i GetStatus exch get_d_a
174} def
175
176% Get metadata values of NodeCollection
177/GetMetadata [/nodecollectiontype]
178  /GetMetadata_g load
179def
180
181%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182
183% Slicing of NodeCollections with Take
184% Since n Take means take first n elements, while [n] Take means return
185%      n-th element, we need to be a bit careful, handling the letter case
186%      here at the SLI level and mapping the former to the two-element case
187% Note that Take indexes from 1, with -1 the last element
188/Take [/nodecollectiontype /integertype]
189 {
190   << >> begin
191     /n Set
192     /c Set
193     n 0 geq
194     {
195       [ 1 n ]
196     }
197     {
198       n neg c size gt { c n /Take /RangeError raiseerror } if
199
200       c size dup n add 1 add exch
201       2 arraystore
202     }
203     ifelse
204     c
205     exch
206     Take
207   end
208}
209def
210
211/Take [/nodecollectiontype /arraytype]
212{
213  << >> begin
214  /slice Set
215  /coll Set
216  slice length 1 eq
217  {
218    slice 0 get dup 1 3 arraystore coll exch Take_g_a
219  }
220  {
221    % assume that we have two or three elements now
222    slice dup
223    length 2 eq { 1 append } if
224    coll exch
225    Take_g_a
226  }
227  ifelse
228  end
229
230} def
231
232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233
234/* BeginDocumentation
235   Name: LocalOnly - Get only local elements of a NodeCollection.
236
237   Synopsis:
238   nodecollection    LocalOnly --> local_nodecollection
239
240   Parameters:
241   nodecollection          - NodeCollection in which to find local elements
242   local_nodecollection    - NodeCollection with only local elements
243
244   Description:
245   This function gets only the local elements in a NodeCollection.
246   The resulting elements are returned in a new NodeCollection. If
247   there are no local elements, an empty NodeCollection is returned.
248
249   Author: Håkon Mørk
250   FirstVersion: November 2017
251*/
252/LocalOnly [/nodecollectiontype]
253{
254   << >> begin
255     /nc Set
256     Rank nc 0 get NumProcesses mod sub NumProcesses add NumProcesses mod 1 add
257     dup nc size leq
258     {
259       nc size NumProcesses 3 arraystore nc exch Take
260     }
261     {
262       pop
263       [] cvnodecollection
264     } ifelse
265   end
266} def
267
268%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269
270% Return array containing only those node IDs for which procedure returns true
271%
272% Note:
273% Returns array so that we can return an empty array if no node matches.
274/Select [/nodecollectiontype /proceduretype]
275{
276  /predicate Set
277  mark exch
278  {
279    dup
280    predicate not
281    {
282      pop
283    }
284    if
285  }
286  forall
287  counttomark
288  arraystore
289  exch pop
290  currentdict /predicate undef
291} bind def
292
293%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294
295% Min and Max for NodeCollections
296%
297
298/Min trie
299[/nodecollectiontype] { 0 get } addtotrie
300[/anytype] /Min load addtotrie
301def
302
303/Max trie
304[/nodecollectiontype] { dup size 1 sub get } addtotrie
305[/anytype] /Max load addtotrie
306def
307
308
309%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310
311% Parameterization
312
313
314/mul [/parametertype /parametertype]
315  /mul_P_P load
316def
317
318/div [/parametertype /parametertype]
319  /div_P_P load
320def
321
322/add [/parametertype /parametertype]
323  /add_P_P load
324def
325
326/sub [/parametertype /parametertype]
327  /sub_P_P load
328def
329
330/compare [/parametertype /parametertype /dictionarytype]
331  /compare_P_P_D load
332def
333
334/conditional [/parametertype /parametertype /parametertype]
335  /conditional_P_P_P load
336def
337
338/min [/parametertype /doubletype]
339  /min_P_d load
340def
341
342/max [/parametertype /doubletype]
343  /max_P_d load
344def
345
346/redraw [/parametertype /doubletype /doubletype]
347  /redraw_P_d_d load
348def
349
350/exp [/parametertype]
351  /exp_P load
352def
353
354/sin [/parametertype]
355  /sin_P load
356def
357
358/cos [/parametertype]
359  /cos_P load
360def
361
362/pow [/parametertype /doubletype]
363  /pow_P_d load
364def
365
366/dimension2d [/parametertype /parametertype]
367  /dimension2d_P_P load
368def
369
370/dimension3d [/parametertype /parametertype /parametertype]
371  /dimension3d_P_P_P load
372def
373
374/CreateParameter trie
375[/dictionarytype] /CreateParameter_D load addtotrie
376[/doubletype] /CreateParameter_D load addtotrie
377def
378
379/GetValue [/parametertype]
380  /GetValue_P load
381def
382
383/ParameterIsSpatial [/parametertype]
384  /IsSpatial_P load
385def
386
387/Apply [/parametertype /dictionarytype]
388  /Apply_P_D load
389def
390
391/Apply [/parametertype /nodecollectiontype]
392  /Apply_P_g load
393def
394
395%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396
397/Simulate trie
398[/integertype] {cvd Simulate} addtotrie
399[/doubletype]  /Simulate_d load addtotrie
400def
401
402/Run trie
403[/integertype] {cvd Run} addtotrie
404[/doubletype]  /Run_d load addtotrie
405def
406
407%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408
409
410% oosupport.sli already defines conversions for dict
411/cvdict [/connectiontype]
412 /cvdict_C load
413def
414
415%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416
417/** @BeginDocumentation
418   Name: cvnodecollection - Create a container of node IDs.
419
420   Synopsis:
421   list_of_node_ids          cvnodecollection -> nodecollection
422   first_node_id    last_node_id cvnodecollection -> nodecollection
423
424   Parameters:
425   list_of_node_ids    - an array or intvector of node IDs, or a nodecollection
426   first_node_id       - an integer definig the first node ID of the range
427   last_node_id        - an integer definig the last node ID of the range
428
429   Description:
430   This function creates a nodecollection object, which is a unified
431   representation for multiple node IDs of neurons or devices. To
432   save memory in the case of contiguous ranges of node IDs, it is
433   possible to just use the first and last index of the range to
434   initialize the nodecollection.
435
436   Author: Jochen Martin Eppler
437   FirstVersion: April 2014
438
439   SeeAlso: cv_iv, Connect
440*/
441
442/cvnodecollection trie
443  [/integertype /integertype] /cvnodecollection_i_i load addtotrie
444  [/arraytype]                /cvnodecollection_ia  load addtotrie
445  [/intvectortype]            /cvnodecollection_iv  load addtotrie
446  [/nodecollectiontype]        {}                        addtotrie
447def
448
449%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450
451% add conversion from NodeCollection
452/cva [/nodecollectiontype]
453  /cva_g load
454def
455
456%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
457
458/NodeCollectionQ trie
459  [/nodecollectiontype] true addtotrie
460  [/anytype] false addtotrie
461def
462
463%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
464
465% convert to list of node_id-modelid pairs
466/cva_node_id_mid trie def
467/cva_node_id_mid [/nodecollectiontype]
468{
469 << >> begin
470  dup
471  :beginiterator_g /iter Set
472  :enditerator_g /enditer Set
473
474  mark
475  {
476    iter :getnodeidmodelid_q
477    iter :next_q
478    enditer :lt_q_q not { exit } if
479  }
480  loop
481  counttomark
482  arraystore
483  exch pop
484
485  end
486}
487def
488
489%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
490
491% join for NodeCollections
492/join [/nodecollectiontype /nodecollectiontype]
493  /join_g_g load
494def
495
496%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497
498% forall, forallindexed and Map for node collections --- brutal implementations
499
500/forall [/nodecollectiontype /proceduretype]
501{
502  /func Set
503  dup
504  :beginiterator_g /iter Set
505  :enditerator_g /enditer Set
506
507  {
508    iter :getnodeid_q
509    func
510    iter :next_q
511    enditer :lt_q_q not { exit } if
512  }
513  loop
514
515  % Delete local variables; we do not use a local dictionary
516  % here in case func should change variables.
517  currentdict /func undef
518  currentdict /iter undef
519  currentdict /enditer undef
520
521} bind def
522
523/forallindexed [/nodecollectiontype /proceduretype]
524{
525  /func Set
526  dup
527  :beginiterator_g /iter Set
528  :enditerator_g /enditer Set
529
530  /:n 0 def
531  {
532    iter :getnodeid_q
533    :n
534    func
535    iter :next_q
536    /:n :n 1 add def
537    enditer :lt_q_q not { exit } if
538  }
539  loop
540
541  % Delete local variables; we do not use a local dictionary
542  % here in case func should change variables.
543  currentdict /func undef
544  currentdict /iter undef
545  currentdict /enditer undef
546  currentdict /:n undef
547
548} bind def
549
550/Map [/nodecollectiontype /proceduretype]
551{
552  << >> begin
553  /func Set
554  dup
555  :beginiterator_g /iter Set
556  :enditerator_g /enditer Set
557
558  mark
559  {
560    iter :getnodeid_q
561    func
562    iter :next_q
563    enditer :lt_q_q not { exit } if
564  }
565  loop
566  counttomark
567  arraystore
568  exch pop
569
570  end
571} bind def
572
573%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
574
575% NodeCollection membership
576
577/InCollection [/nodecollectiontype /integertype]
578  /MemberQ_g_i load
579def
580
581/Find [/nodecollectiontype /integertype]
582  /Find_g_i load
583def
584
585/eq [/nodecollectiontype /nodecollectiontype] /eq_g load def
586
587%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
588
589% typeinit.sli already defines size functions for other types
590/size [/nodecollectiontype]
591  /size_g load
592def
593
594%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
595
596% GetStatus / SetStatus for NodeCollection
597
598/GetStatus [/nodecollectiontype]
599  /GetStatus_g load
600def
601
602/SetStatus [/nodecollectiontype /dictionarytype]
603{
604  1 pick ValidQ_g not { /SetStatus /InvalidNodeCollectionError raiseerror } if
605  exch { 1 pick SetStatus_id } forall
606  pop % dictionary
607}
608def
609
610/SetStatus [/nodecollectiontype /arraytype]
611{
612  1 pick ValidQ_g not { /SetStatus /InvalidNodeCollectionError raiseerror } if
613  << >> begin
614  /params Set
615  /nc Set
616
617  params length nc size neq
618  {
619    nc params /SetStatus /IncompatibleLengths raiseerror
620  }
621  if
622
623  nc :beginiterator_g /iter Set
624  nc :enditerator_g /enditer Set
625
626  params
627  {
628    iter :getnodeid_q exch
629    SetStatus_id
630    iter :next_q pop
631  }
632  forall
633
634  end
635}
636def
637
638%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
639
640/GetResolution {
641    GetKernelStatus /resolution get
642} def
643
644%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
645
646/** @BeginDocumentation
647   Name: GetNodes - Return IDs of all nodes that fulfill the conditions given in
648                    the dictionary, or all nodes if no dictionary given. Returns
649                    only mpi local nodes if local_bool is true.
650   Synopsis:
651     <<dict>> local_bool GetNodes -> NodeCollection
652   Parameters:
653     <<dict>>   - Dictionary of selection properties
654     local_bool - Bool indicating whether or not we want only local nodes.
655   Returns:
656     NodeCollection  - NodeCollection with the node IDs of all nodes or all mpi
657                      local nodes if local_bool is true.
658   Description:
659   This function recursively traverses all nodes and returns the global
660   ids of all nodes in increasing order of node_id if local_bool is false, if not, it
661   returns local nodes. If a dictionary is provided, only those nodes which fulfill
662   the given criteria are returned.
663*/
664
665/GetNodes trie
666  [/dictionarytype /booltype] { GetNodes_D_b } bind addtotrie
667def
668
669%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670%
671%     Create and variants
672%
673%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
674
675/Create_l
676{
677  1 Create_l_i
678} def
679
680/Create_l_D
681{
682  1 exch Create_l_i_D
683} def
684
685/Create_l_i_D
686{
687  << >> begin
688
689    /params Set
690    /n Set
691    /model Set
692
693    model GetDefaults /element_type get /recorder neq
694    {
695      % For stimulators and neurons, we store the old parameters that
696      % are given in params, then set params as model defaults, create
697      % the nodes and restore the old parameters.
698
699      model GetDefaults /oldparams Set
700      /tmp << >> def
701
702      % get implicitly checks if params contains 'illegal' keys
703      params keys { /key Set tmp key oldparams key get put } forall
704      tmp /oldparams Set
705
706      model params SetDefaults
707      model n Create_l_i
708      model oldparams SetDefaults
709    }
710    {
711      % For recorders, we can't use the more efficient method
712      % above. The reason for this is that recording backend
713      % properties might differ between backends and the backend might
714      % be changed away from the default during the call to Create,
715      % resulting in lookup errors.
716
717      model n Create_l_i
718      dup params SetStatus
719    } ifelse
720
721  end % local namespace
722} def
723
724
725/Create trie
726  [/literaltype                             ] /Create_l     load addtotrie
727  [/literaltype /integertype                ] /Create_l_i   load addtotrie
728  [/literaltype              /dictionarytype] /Create_l_D   load addtotrie
729  [/literaltype /integertype /dictionarytype] /Create_l_i_D load addtotrie
730def
731
732%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
733%
734%     Model handling
735%
736%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
737
738/CopyModel_l_l
739{
740  << >> CopyModel_l_l_D
741} bind def
742
743/CopyModel trie
744  [/literaltype /literaltype                ] /CopyModel_l_l   load addtotrie
745  [/literaltype /literaltype /dictionarytype] /CopyModel_l_l_D load addtotrie
746def
747
748/SetDefaults
749  [/literaltype /dictionarytype] /SetDefaults_l_D load
750def
751
752/GetDefaults
753  [/literaltype] /GetDefaults_l load
754def
755
756%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757
758/** @BeginDocumentation
759   Name: ShowDefaults - Show the default parameters of a model.
760
761   Synopsis:
762   /modelname ShowDefaults -> -
763
764   Description:
765   ShowDefaults retrieves the dictionary of default values from the
766   specified model and displays it, using info. ShowDefaults is
767   equivalent to the sequence "GetDefaults info"
768
769   SeeAlso: GetDefaults, info
770*/
771
772/ShowDefaults
773{
774  GetDefaults info
775} def
776
777%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
778%
779%     Connect and its variants
780%
781%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782
783
784/** @BeginDocumentation
785   Name: Connect - Establish a connection between two nodes or lists of nodes.
786
787   Synopsis:
788   sources targets                        Connect
789   sources targets weight delay           Connect
790   sources targets weight delay syn_model Connect
791   sources targets conn_rule              Connect
792   sources targets conn_spec              Connect
793   sources targets conn_rule syn_model    Connect
794   sources targets conn_spec syn_model    Connect
795   sources targets conn_rule syn_spec     Connect
796   sources targets conn_spec syn_spec     Connect
797
798   Parameters:
799   sources    nodecollection  - the node IDs of the sources
800   targets    nodecollection  - the node IDs of the targets
801   weight     double         - the weight of the connection
802   delay      double         - the delay of the connection
803   conn_rule  literal        - the name of the connection rule, see connruledict
804   conn_spec  dict           - dictionary with connectivity specification (see Options)
805   syn_model  literal        - the name of the synapse model, see synapsedict
806   syn_spec   dict           - dictionary with synapse model specification (see Options)
807
808   Options:
809   /conn_spec - dictionary with connectivity specification, must at least contain /rule
810
811                The following options may be given for all connection rules;
812                not all rules support all options and many rules add rule-specific options.
813
814                allow_autapses  bool  - allow self-connections (default: true)
815                allow_multapses bool  - allow multiple connections between pairs
816                                        of neurons (default: true)
817                symmetric       bool  - also create connection in opposite direction to
818                                      obtain symmetric connections (default: false)
819
820   /syn_spec  - dictionary with synapse specification, must at least contain /model
821
822   Description:
823   Connects sources to targets according to the given connectivity
824   specification conn_spec. Some connection rules impose requirements.
825   E.g. /one_to_one requires that sources and targets have the same
826   number of elements. Others may have additional parameters,
827   e.g. connection probability /p for /pairwise_binomial.
828
829   The variants with only literal arguments /conn_rule or /syn_model
830   are shorthand for the corresponding calls with connectivity or
831   synapse specification dictionaries as explained in the Options
832   section.  The literals are expanded to << /rule /conn_rule >> and
833   << /synapse_model /syn_model >>, respectively.
834
835   Parameters for connectivity rules must have fixed values.
836
837   Parameters for synapses may be fixed single values, arrays or random deviate
838   specifications.
839
840   SeeAlso: synapsedict, connruledict, cvnodecollection, GetOptions
841
842   Author: Hannah Bos, Hans Ekkehard Plesser, Jochen Martin Eppler
843
844   FirstVersion: January 2014
845*/
846
847%%% Options for Connect
848
849/Connect <<
850  /conn_spec << /rule /all_to_all >>
851  /syn_spec << /synapse_model /static_synapse >>
852>> Options
853
854
855%%% Helper functions for Connect
856
857% Expects a synapse or connection specification dictionary on the
858% stack and extends it by the defaults from Connect's Options for
859% all keys from the given spec in the Options for Connect that are
860% missing in the given dictionary.
861% Usage: dict /lit, where lit is the name of the spec in the Options
862/:Connect_complete_dict {
863    << >> begin
864    /optname Set
865    /Connect optname GetOption keys {
866    	dup /key Set
867	exch dup 3 2 roll known not {
868	  dup key /Connect optname GetOption key get put
869        } if
870    } forall
871    end
872} def
873
874
875%%% Variants of Connect
876
877/Connect trie
878
879  % We create the type trie for the different variants using a loop
880  [/arraytype /intvectortype /nodecollectiontype] {
881      /node_idlisttype Set
882
883      % Variant: sources targets Connect
884      % Connect nodes from two sets of node IDs using the default rule and
885      % synapse model
886      [node_idlisttype node_idlisttype] {
887          cvnodecollection exch  % convert targets to nodecollection
888          cvnodecollection exch  % convert sources to nodecollection
889          /Connect /conn_spec GetOption  % use default conn_spec
890          /Connect /syn_spec GetOption   % use default syn_spec
891          Connect_g_g_D_D
892      } bind addtotrie
893
894      % Variant: sources targets weight delay Connect
895      % Connect nodes from two sets of node IDs using the default rule and
896      % synapse model but with the given weight and delay
897      [node_idlisttype node_idlisttype /doubletype /doubletype] {
898          mark 3 1 roll         % put a mark before weight and delay
899          /weight 3 1 roll      % add a label for the weight
900          /delay 2 1 roll       % add a label for the delay
901          >>                    % create the syn_spec dictionary
902          /syn_spec :Connect_complete_dict    % fill in missing defaults
903          /Connect /conn_spec GetOption exch  % use default conn_spec
904          4 2 roll              % bring sources and targets to top
905          cvnodecollection exch  % convert targets to nodecollection
906          cvnodecollection exch  % convert sources to nodecollection
907          4 2 roll              % bring sources and targets to bottom
908          Connect_g_g_D_D
909      } bind addtotrie
910
911
912      % Variant: sources targets weight delay syn_model Connect
913      % Connect nodes from two sets of node IDs using the default rule and
914      % the given weight, delay and synapse model
915	[node_idlisttype node_idlisttype /doubletype /doubletype /literaltype] {
916          mark 4 1 roll         % put a mark before weight and delay
917          /weight 4 1 roll      % add a label for the weight
918          /delay 3 1 roll       % add a label for the delay
919        /synapse_model 2 1 roll  % add a label for the synapse model
920          >>                    % create the syn_spec dictionary
921          /syn_spec :Connect_complete_dict    % fill in missing defaults
922          /Connect /conn_spec GetOption exch  % use default conn_spec
923          4 2 roll              % bring sources and targets to top
924          cvnodecollection exch  % convert targets to nodecollection
925          cvnodecollection exch  % convert sources to nodecollection
926          4 2 roll              % bring sources and targets to bottom
927          Connect_g_g_D_D
928      } bind addtotrie
929
930      % Variant: sources targets conn_rule Connect
931      % Connect nodes from two sets of node IDs using the given rule and
932      % default synapse model
933      [node_idlisttype node_idlisttype /literaltype] {
934	  mark exch /rule exch >>  % create the conn_spec dictionary
935	  /conn_spec :Connect_complete_dict  % fill in missing defaults
936	  3 1 roll                 % bring sources and targets to top
937	  cvnodecollection exch     % convert targets to nodecollection
938	  cvnodecollection exch     % convert sources to nodecollection
939	  3 2 roll                 % bring sources and targets to bottom
940	  /Connect /syn_spec GetOption  % use default syn_spec
941	  Connect_g_g_D_D
942      } bind addtotrie
943
944      % Variant: sources targets conn_spec Connect
945      % Connect nodes from two sets of node IDs using the given connectivity
946      % specification and default synapse model
947      [node_idlisttype node_idlisttype /dictionarytype] {
948	  /conn_spec :Connect_complete_dict  % fill in missing defaults
949	  3 1 roll              % bring sources and targets to top
950	  cvnodecollection exch  % convert targets to nodecollection
951	  cvnodecollection exch  % convert sources to nodecollection
952	  3 2 roll              % bring sources and targets to bottom
953	  /Connect /syn_spec GetOption  % use default syn_spec
954	  Connect_g_g_D_D
955      } bind addtotrie
956
957      % Variant: sources targets conn_rule syn_model Connect
958      % Connect nodes from two sets of node IDs using the given rule and
959      % synapse model
960      [node_idlisttype node_idlisttype /literaltype /literaltype] {
961    	  mark exch /synapse_model exch >>  % create the syn_spec dictionary
962	  /syn_spec :Connect_complete_dict   % fill in missing defaults
963	  exch                      % exchange syn_spec and conn_spec
964	  mark exch /rule exch >>   % create the conn_spec dictionary
965	  /conn_spec :Connect_complete_dict  % fill in missing defaults
966	  exch                      % exchange syn_spec and conn_spec
967	  4 2 roll                  % bring sources and targets to top
968	  cvnodecollection exch      % convert targets to nodecollection
969	  cvnodecollection exch      % convert sources to nodecollection
970	  4 2 roll                  % bring sources and targets to bottom
971	  Connect_g_g_D_D
972      } bind addtotrie
973
974      % Variant: sources targets conn_spec syn_model Connect
975      % Connect nodes from two sets of node IDs using the given rule and
976      % synapse specification
977      [node_idlisttype node_idlisttype /literaltype /dictionarytype] {
978	  /syn_spec :Connect_complete_dict   % fill in missing defaults
979	  exch                     % exchange syn_spec and conn_spec
980	  mark exch /rule exch >>  % create the conn_spec dictionary
981	  /conn_spec :Connect_complete_dict  % fill in missing defaults
982	  exch                     % exchange syn_spec and conn_spec
983	  4 2 roll                 % bring sources and targets to top
984	  cvnodecollection exch     % convert targets to nodecollection
985	  cvnodecollection exch     % convert sources to nodecollection
986	  4 2 roll                 % bring sources and targets to bottom
987	  Connect_g_g_D_D
988      } bind addtotrie
989
990      % Variant: sources targets conn_rule syn_spec Connect
991      % Connect nodes from two sets of node IDs using the given connectivity
992      % specification and synapse model
993      [node_idlisttype node_idlisttype /dictionarytype /literaltype] {
994    	  mark exch /synapse_model exch >>  % create the syn_spec dictionary
995	  /syn_spec :Connect_complete_dict   % fill in missing defaults
996	  exch                      % exchange syn_spec and conn_spec
997	  /conn_spec :Connect_complete_dict  % fill in missing defaults
998	  exch                      % exchange syn_spec and conn_spec
999	  4 2 roll                  % bring sources and targets to top
1000	  cvnodecollection exch      % convert targets to nodecollection
1001	  cvnodecollection exch      % convert sources to nodecollection
1002	  4 2 roll                  % bring sources and targets to bottom
1003	  Connect_g_g_D_D
1004      } bind addtotrie
1005
1006      % Variant: sources targets conn_spec syn_spec Connect
1007      % Connect nodes from two sets of node IDs using the given connectivity
1008      % and synapse specifications
1009      [node_idlisttype node_idlisttype /dictionarytype /dictionarytype] {
1010        /syn_spec :Connect_complete_dict   % fill in missing defaults
1011        exch                   % exchange syn_spec and conn_spec
1012        /conn_spec :Connect_complete_dict  % fill in missing defaults
1013        exch                   % exchange syn_spec and conn_spec
1014        4 2 roll               % bring sources and targets to top
1015        cvnodecollection exch  % convert targets to nodecollection
1016        cvnodecollection exch  % convert sources to nodecollection
1017        4 2 roll               % bring sources and targets to bottom
1018        Connect_g_g_D_D
1019      } bind addtotrie
1020
1021      % Variant: sources targets conn_spec syn_vector Connect
1022      % Connect nodes from two sets of NodeCollections using the given connectivity specification
1023      % and a list of synapse specifications
1024      [node_idlisttype node_idlisttype /dictionarytype /arraytype] {
1025        /test_syn_specs Set
1026        test_syn_specs
1027        {
1028          /syn_spec :Connect_complete_dict
1029          pop
1030        } forall
1031        test_syn_specs
1032        Connect_g_g_D_a
1033      } bind addtotrie
1034
1035  } forall
1036
1037def
1038
1039%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1040
1041
1042/** @BeginDocumentation
1043   Name: GetConnections - Retrieve connections between nodes
1044
1045   Synopsis:
1046   << /source [snode_id1 snode_id2 ...]
1047      /target [tnode_id1 tnode_id2 ...]
1048      /synapse_model /smodel
1049      /synapse_label label      >> GetConnections -> [ conn1 conn2 ... ]
1050
1051   Parameters:
1052   A dictionary that may contain the following fields (all are optional):
1053   /source  - array with node IDs of presynaptic nodes whose connections are sought.
1054              If not given, all neurons are searched as sources.
1055   /target  - array with node IDs of postsynaptic nodes whose connections are sought.
1056              If not given, all neurons are searched as targets.
1057   /synapse_model - literal specifying synapse model
1058                    If not given, connections of all synapse models are returned.
1059   /synapse_label - integer specifying synapse label
1060                    If not given, connections of all synapse labels are returned.
1061
1062   Description:
1063   1. If called with an empty dictionary, GetConnections returns all connections of the
1064      network, as a list of arrays (IntVectorDatum), one array per connection.
1065   2. Each array (connection object) has the following elements:
1066      [source-node_id target-node_id target-thread synapse-model-id port]
1067   3. The optional dictionary elements /source and /target can be used to filter
1068      for specific pre- and postsynaptic neurons, respectively.
1069   4. The optional parameter /synapse_model can be used to filter for a specific synapse model.
1070   5. The optional parameter /synapse_label can be used to filter for a specific synapse label.
1071   6. In a parallel simulation, GetConnections only returns connections with *targets*
1072      on the MPI process executing the function.
1073
1074   Remarks:
1075   1. See synapsedict for the synapse-model-id's for all synapse models.
1076   2. The /synapse_label property can only be assigned to synapse models with names ending
1077      with '_lbl'. All other synapses have the default synapse_label UNLABELED_CONNECTION (-1).
1078   3. The "port" enumerates connections per source, thread and synapse model. It is
1079      mainly important for NEST internally.
1080   4. In OpenMP mode, GetConnections works thread-parallel for better performance.
1081   5. Connection objects can be converted to SLI lists with cva.
1082   6. Connection objects can be passed to SetStatus, and GetStatus
1083
1084   SeeAlso: synapsedict
1085*/
1086/GetConnections [/dictionarytype]
1087{
1088  /pdict Set
1089  [ /source /target ]
1090  {
1091    /key Set
1092    pdict key known
1093    {
1094      pdict key get
1095      NodeCollectionQ exch ; not
1096      {
1097	      key cvs ( argument must be NodeCollection) join M_ERROR message
1098	      /GetConnections /ArgumentError raiseerror
1099      }
1100      if
1101    }
1102    if
1103  }
1104  forall
1105  pdict GetConnections_D
1106}
1107def
1108
1109
1110%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1111
1112/** @BeginDocumentation
1113   Name: elementstates - dictionary with symbolic element state tag
1114
1115   Description:
1116   Each element has a state which can be accessed via it's status dictionary.
1117   The state is defined as a superposition of the following values:
1118   /valid       1
1119   /busy        2
1120   /updated     4
1121   /suspended   8
1122   /frozen     16
1123   /buffers_initialized 32
1124   /err        64
1125   valid      - the default state of an element.
1126   busy       - indicates that this element needs more than one cycle to
1127                update and is not yet fully updated.
1128   updated    - indicates, that the element was updated in the current cycle.
1129                once the update cycle is completed, all updated flags are
1130		changed to valid.
1131		This flag shoulds only be set if the update cycle was
1132		interrupted or suspended.
1133   suspended  - indicates, that the update of this element was suspended. The
1134                next call to simulate will continue with this element.
1135   frozen     - if this state is set, the update cycle skips this element. In
1136                effect, the element keeps its state intact as if it was "frozen".
1137		This is the only state which can directly be set by the user.
1138   buffers_initialized - the buffers of the node have been initialized
1139   err        - some unspecified error condition has occured.
1140
1141   Examples: elementstates info
1142
1143   Availability: NEST
1144*/
1145
1146/elementstates
1147<<
1148  /valid       1
1149  /busy        2
1150  /updated     4
1151  /suspended   8
1152  /frozen     16
1153  /buffers_initialized 32
1154  /err        64
1155>> def
1156
1157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1158
1159/** @BeginDocumentation
1160   Name: unit_conversion - Conversion factors for SI units.
1161
1162   Description:
1163   Some SLI functions and tools expect numerical arguments which carry SI units.
1164   function/tool        expected unit
1165   ----------------------------------
1166   Simulate             ms
1167   current generators   pA
1168   voltmeters           mV
1169   ac_generator         Hz
1170
1171   As SLI does not know any unit conversion scheme, numerical values
1172   need to be specified in the appropriate units. However, it improves
1173   readability, if a hint to the unit is specified in the program code,
1174   such as "333 pA", instead of just "333".
1175   Furthermore, it may be convenient to have other units converted to the
1176   ones expected by the routines. (For example, "ms" converts from milliseconds
1177   to timesteps, taking into account the current network resolution, see
1178   example below.)
1179
1180   The following conversion factors are known (developers: please add others in
1181   nest-init.sli as required):
1182   ms, pA, mV, Hz, spikes
1183
1184   Examples:
1185   The following call always simulates 1000 ms of network time,
1186
1187   1000 ms Simulate
1188
1189   Author: (unknown), documented by Ruediger Kupper, 18-jul-2003
1190
1191   Availability: This is just a description. unit_conversion is no SLI command.
1192   SeeAlso: Hz, ms, pA, mV, spikes, cvd, cvi
1193*/
1194
1195%% Some auxiliary definitions, just for readibility
1196
1197/** @BeginDocumentation
1198   Name: ms - Specification in ms (for readability)
1199   SeeAlso: unit_conversion, ms2hms
1200*/
1201/ms /cvd load def
1202
1203/** @BeginDocumentation
1204   Name: s - Specification in s (for readability)
1205   SeeAlso: unit_conversion, ms2hms
1206*/
1207/s {1000.0 mul} bind def
1208
1209/** @BeginDocumentation
1210   Name: pA - Specification in pA (for readability)
1211   SeeAlso: unit_conversion
1212*/
1213/pA /cvd load def
1214
1215/** @BeginDocumentation
1216   Name: nS - Specification in nS (for readability)
1217   SeeAlso: unit_conversion
1218*/
1219/nS /cvd load def
1220/** @BeginDocumentation
1221   Name: pF - Specification in pF (for readability)
1222   SeeAlso: unit_conversion
1223*/
1224/pF /cvd load def
1225
1226/** @BeginDocumentation
1227   Name: mV - Specification in mV (for readability)
1228   SeeAlso: unit_conversion
1229*/
1230/mV /cvd load def
1231
1232/** @BeginDocumentation
1233   Name: Hz - Specification in Hz (for readability)
1234   SeeAlso: unit_conversion
1235*/
1236/Hz /cvd load def
1237
1238/** @BeginDocumentation
1239   Name: spikes - Specification in spikes (for readability)
1240   SeeAlso: unit_conversion
1241*/
1242/spikes /cvi load def
1243
1244/double /cvd load def
1245
1246/int    /cvi load def
1247
1248
1249/** @BeginDocumentation
1250   Name: SubsetQ - Test if one dictionary is a subset of another
1251
1252   Synopsis:
1253   dict1 dict2 SubsetQ -> bool
1254
1255   Parameters:
1256   dict1 - dictionary
1257   dict2 - dictionary
1258
1259   Description:
1260   The functions returns true, if all entries of dict2 are present in dict1
1261   with the same values.
1262
1263   Examples:
1264   << /a 1 /b 2 /c 2 >> << /c 2 >> SubsetQ -> true
1265*/
1266/SubsetQ
1267[/dictionarytype /dictionarytype]
1268{
1269  << >> begin
1270  cva 2 Partition
1271  /properties Set
1272  /object Set
1273
1274  true
1275  properties
1276  {
1277    arrayload ;
1278    /val Set
1279    cvlit /key Set
1280    object dup key known
1281    {
1282      key get
1283      val eq and
1284    }
1285    {
1286     pop pop false exit
1287    } ifelse
1288  } forall
1289  end
1290} bind def
1291
1292%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1293
1294/** @BeginDocumentation
1295   Name: ShowStatus - Show the status dictionary of a network node.
1296
1297   Synopsis:
1298   node_id ShowStatus -> -
1299
1300   Description:
1301   ShowStatus retrieves the status dictionary of the specified node
1302   and displays it, using info.
1303   ShowStatus is equivalent to the sequence "GetStatus info"
1304
1305   SeeAlso: GetStatus, info
1306*/
1307
1308/ShowStatus
1309{
1310  GetStatus info
1311} def
1312
1313%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1314/** @BeginDocumentation
1315   Name: TimeCommunication - returns average time taken for MPI_Allgather over n calls with m bytes
1316   Synopsis:
1317   n m [bool] TimeCommunication -> time
1318   Availability: NEST 2.0
1319   Author: Abigail Morrison
1320   FirstVersion: August 2009
1321   Description:
1322   The function allows a user to test how much time a call the Allgather costs
1323   If boolean third argument is passed and true, time offgrid spike communication.
1324   SeeAlso: TimeCommunicationOffgrid
1325 */
1326/TimeCommunication trie
1327[/integertype /integertype /booltype] /TimeCommunication_i_i_b load addtotrie
1328[/integertype /integertype] { false TimeCommunication_i_i_b } bind addtotrie
1329def
1330
1331/TimeCommunicationv trie
1332[/integertype /integertype] /TimeCommunicationv_i_i load addtotrie
1333def
1334
1335  /** @BeginDocumentation
1336     Name: TimeCommunicationOffgrid - returns average time taken for MPI_Allgather over n calls with m bytes when communication offgrid spikes
1337     Synopsis:
1338     n m [bool] TimeCommunication -> time
1339     Availability: NEST 2.0
1340     Author: Abigail Morrison
1341     FirstVersion: August 2009
1342     Description:
1343     The function allows a user to test how much time a call the Allgather costs
1344     SeeAlso: TimeCommunication
1345   */
1346/TimeCommunicationOffgrid trie
1347[/integertype /integertype] { true TimeCommunication_i_i_b } bind addtotrie
1348
1349def
1350  /** @BeginDocumentation
1351     Name: TimeCommunicationAlltoall - returns average time taken for MPI_Alltoall over n calls with m bytes
1352     Synopsis:
1353     n m TimeCommunicationAlltoall -> time
1354     Availability: 10kproject (>r11254)
1355     Author: Jakob Jordan (modified TimeCommunication)
1356     FirstVersion: June 2014
1357     Description:
1358     The function allows a user to test how much time a call to MPI_Alltoall costs
1359     SeeAlso: TimeCommunication
1360   */
1361/TimeCommunicationAlltoall trie
1362[/integertype /integertype] /TimeCommunicationAlltoall_i_i load addtotrie
1363def
1364
1365  /** @BeginDocumentation
1366     Name: TimeCommunicationAlltoallv - returns average time taken for MPI_Alltoallv over n calls with m bytes
1367     Synopsis:
1368     n m TimeCommunicationAlltoallv -> time
1369     Availability: 10kproject (>r11300)
1370     Author: Jakob Jordan (modified TimeCommunication)
1371     FirstVersion: July 2014
1372     Description:
1373     The function allows a user to test how much time a call to MPI_Alltoallv costs
1374     SeeAlso: TimeCommunication
1375   */
1376/TimeCommunicationAlltoallv trie
1377[/integertype /integertype] /TimeCommunicationAlltoallv_i_i load addtotrie
1378def
1379
1380% can only be defined here because on bg processes.sli is not included
1381statusdict /platform get dup (bg/p) eq exch (bg/q) eq or
1382{
1383 /memory_thisjob { :memory_thisjob_bg } def
1384} if
1385
1386
1387/** @BeginDocumentation
1388Name: SaveModels - Retrieve the state of all models.
1389Description:
1390*/
1391
1392/SaveModels
1393{
1394  << >> begin
1395  modeldict cva 2 Partition size /n_models Set
1396  n_models 1 add % proxy model is not in modeldict
1397  array /models Set
1398  {
1399    models exch
1400    arrayload ; exch
1401    put /models Set
1402 } forall
1403
1404 [
1405 models
1406 {
1407   dup type /literaltype eq
1408   { GetDefaults } { pop } ifelse
1409 } forall
1410 ]
1411 end
1412} def
1413
1414/** @BeginDocumentation
1415Name: RestoreModels - Restore saved models from an array of status dictionaries.
1416Description:
1417*/
1418/RestoreModels
1419[/arraytype]
1420{
1421 << >> begin
1422  /models Set
1423  GetKernelStatus /dict_miss_is_error get /dict_err Set
1424  << /dict_miss_is_error false >> SetKernelStatus
1425  /old_verbosity verbosity def
1426  M_ERROR setverbosity
1427  /restoremodel
1428  {
1429    begin
1430    model type_id neq
1431    {
1432      type_id model currentdict CopyModel
1433    }
1434    {
1435      type_id /a2eif_cond_exp_HW neq        % these models
1436      type_id /topology_layer_3d neq and    % these models
1437      type_id /topology_layer_free neq and  % break when
1438      type_id /topology_layer_grid neq and  % their status is changed
1439      {  model currentdict SetDefaults } if
1440    } ifelse
1441    end
1442  } def
1443  models
1444  {
1445    restoremodel
1446  } forall
1447  old_verbosity setverbosity
1448  << /dict_miss_is_error dict_err >> SetKernelStatus
1449  end
1450} def
1451
1452/cva [/connectiontype] /cva_C load def
1453
1454
1455/abort
1456{
1457  statusdict /exitcodes get /userabort get
1458  statusdict /is_mpi get { MPI_Abort }{ quit_i } ifelse
1459} bind def
1460
1461
1462%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1463%
1464%     Functions relating to spatial positions
1465%
1466%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1467
1468/ConnectLayers [/nodecollectiontype /nodecollectiontype /dictionarytype]
1469  /ConnectLayers_g_g_D load
1470def
1471
1472/CreateLayerParams [/dictionarytype /dictionarytype]
1473  /CreateLayer_D_D load
1474def
1475
1476/CreateLayer [/dictionarytype]
1477{
1478  << >> CreateLayerParams
1479} def
1480
1481/GetPosition [/nodecollectiontype]
1482  /GetPosition_g load
1483def
1484
1485% nc_from, nc_to
1486/Displacement [/nodecollectiontype /nodecollectiontype]
1487  /Displacement_g_g load
1488def
1489
1490/Displacement [/arraytype /nodecollectiontype]
1491  /Displacement_a_g load
1492def
1493
1494% nc_from, nc_to
1495/Distance [/nodecollectiontype /nodecollectiontype]
1496  /Distance_g_g load
1497def
1498
1499/Distance [/arraytype /nodecollectiontype]
1500    /Distance_a_g load
1501def
1502
1503/Distance [/arraytype]
1504    /Distance_a load
1505def
1506
1507/GetLayerStatus [/nodecollectiontype]
1508    /GetLayerStatus_g load
1509def
1510
1511/DumpLayerNodes [/ostreamtype /nodecollectiontype]
1512  { DumpLayerNodes_os_g } bind
1513def
1514
1515/DumpLayerConnections [/ostreamtype /nodecollectiontype /nodecollectiontype /literaltype]
1516  /DumpLayerConnections_os_g_g_l load
1517def
1518
1519/CreateMask [/dictionarytype]
1520  /CreateMask_D load
1521def
1522
1523/Inside [/arraytype /masktype]
1524  /Inside_a_M load
1525def
1526
1527/Inside [/arraytype /dictionarytype]
1528  { CreateMask Inside_M_a } bind
1529def
1530
1531/and [/masktype /masktype]
1532  /and_M_M load
1533def
1534
1535/or [/masktype /masktype]
1536  /or_M_M load
1537def
1538
1539/sub [/masktype /masktype]
1540  /sub_M_M load
1541def
1542
1543/cvdict [/masktype]
1544  /cvdict_M load
1545def
1546
1547/get [/masktype /literaltype] {exch cvdict_M exch get} def
1548/get [/masktype /arraytype] {exch cvdict_M exch get} def
1549
1550/SelectNodesByMask [/nodecollectiontype /arraytype /masktype]
1551  /SelectNodesByMask_g_a_M load
1552def
1553
1554
1555% Install modules in environment variable NEST_MODULES. Modules have
1556% to be separated by colon.
1557(NEST_MODULES) getenv { (:) breakup { Install } forall } if
1558