Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
SpikingGroup.h
Go to the documentation of this file.
1 /*
2 * Copyright 2014-2018 Friedemann Zenke
3 *
4 * This file is part of Auryn, a simulation package for plastic
5 * spiking neural networks.
6 *
7 * Auryn is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Auryn is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Auryn. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * If you are using Auryn or parts of it for your work please cite:
21 * Zenke, F. and Gerstner, W., 2014. Limits to high-speed simulations
22 * of spiking neural networks using general-purpose computers.
23 * Front Neuroinform 8, 76. doi: 10.3389/fninf.2014.00076
24 */
25 
26 #ifndef SPIKINGGROUP_H_
27 #define SPIKINGGROUP_H_
28 
29 #include "auryn_definitions.h"
30 #include "AurynVector.h"
31 #include "SpikeDelay.h"
32 #include "Trace.h"
33 #include "EulerTrace.h"
34 
35 #include <vector>
36 #include <map>
37 
38 #include <boost/serialization/vector.hpp>
39 #include <boost/serialization/map.hpp>
40 
41 #include <boost/archive/text_oarchive.hpp>
42 #include <boost/archive/text_iarchive.hpp>
43 #include <boost/archive/binary_oarchive.hpp>
44 #include <boost/archive/binary_iarchive.hpp>
45 
46 
47 namespace auryn {
48 
51  AUTO,
55 };
56 
57 
68 {
69 private:
70  /* Functions necesssary for serialization */
72  template<class Archive>
73  void serialize(Archive & ar, const unsigned int version)
74  {
75  virtual_serialize(ar, version);
76  }
77 
79  NeuronID unique_id;
80 
81  unsigned int mpi_rank;
82  unsigned int mpi_size;
83 
85  static NeuronID unique_id_count;
86 
88  void init( NeuronID size, NodeDistributionMode mode );
89 
90  void lock_range( double rank_fraction );
92  unsigned int locked_rank;
94  unsigned int locked_range;
96  static int last_locked_rank;
97 
98  bool evolve_locally_bool;
99 
101  int axonaldelay;
102 
103 protected:
105  std::vector<Trace *> pretraces;
106 
108  std::vector<Trace *> posttraces;
109 
111  std::vector<Trace *> post_state_traces;
112  std::vector<AurynFloat> post_state_traces_spike_biases;
113  std::vector<AurynStateVector *> post_state_traces_states;
114 
117 
125 
128 
129  /* Functions related to loading and storing the state from files */
130  virtual void load_input_line(NeuronID i, const char * buf);
131 
133 
135  virtual void virtual_serialize(boost::archive::binary_oarchive & ar, const unsigned int version );
136 
138  virtual void virtual_serialize(boost::archive::binary_iarchive & ar, const unsigned int version );
139 
141  void free();
142 
143 public:
145 
149  bool active;
150 
151 
153  std::map<std::string,AurynStateVector *> state_vectors;
154 
156  std::map<std::string,AurynState> state_variables;
157 
158 
160  void add_state_vector( std::string key, AurynStateVector * state_vector );
161 
165  void remove_state_vector( std::string key );
166 
174 
186 
195 
206 
209 
211  void randomize_state_vector_gauss(std::string state_vector_name, AurynState mean, AurynState sigma, int seed=12239);
212 
215 
217  virtual ~SpikingGroup();
218 
220  virtual void evolve_traces();
221 
223  void set_name(std::string s);
224 
227 
230 
233 
240  void inc_num_spike_attributes(int x);
242 
249  virtual void evolve() = 0;
250 
257  void conditional_evolve();
258 
260  unsigned int get_locked_rank();
261 
263  unsigned int get_locked_range();
264 
269 
272 
275 
278 
280  NeuronID get_size();
281 
286 
288  NeuronID calculate_rank_size(int rank = -1);
289 
292 
297 
298  void set_clock_ptr(AurynTime * clock);
299 
301  bool evolve_locally();
302 
303 
307  NeuronID get_uid();
308 
317 
324  void add_pre_trace( Trace * tr );
325 
334 
339  void add_post_trace( Trace * tr );
340 
348  void push_spike(NeuronID spike);
349 
355  void push_attribute(AurynFloat attrib);
356 
358  void clear_spikes();
359 
360 
372  Trace * get_post_state_trace( std::string state_name="mem", AurynFloat tau=10e-3, AurynFloat b=0.0 );
373 
384  Trace * get_post_state_trace( AurynStateVector * state, AurynFloat tau=10e-3, AurynFloat b=0.0 );
385 
389  void set_delay( int d );
390 
392  virtual bool write_to_file(const char * filename);
393 
395  virtual bool load_from_file(const char * filename);
396 
398  NeuronID ranksize();
399 
408 
419 
424  bool localrank(NeuronID i);
425 
428 
429 #ifdef CODE_GATHER_STATS_WAITALL_TIME
430 
431  boost::timer waitall_timer;
432  static double waitall_time;
433  static double waitall_time2;
434 #endif
435 };
436 
437 BOOST_SERIALIZATION_ASSUME_ABSTRACT(SpikingGroup)
438 
439 // extern System * sys;
440 extern Logger * logger;
441 #ifdef AURYN_CODE_USE_MPI
442  extern mpi::communicator * mpicommunicator;
443 #endif // AURYN_CODE_USE_MPI
444 
445 
447  return i/locked_range;
448 }
449 
451 {
452  return rank_size;
453 }
454 
455 } // closing namespace brackets
456 
457 #endif /*SPIKINGGROUP_H_*/
NeuronID get_rank_size()
Returns the size on this rank.
Definition: SpikingGroup.h:450
Locks to single rank (this is a special case of BLOCKLOCK.
Definition: SpikingGroup.h:54
virtual std::string get_output_line(NeuronID i)
Definition: SpikingGroup.cpp:809
AurynStateVector * get_existing_state_vector(std::string key)
Returns an existing state with the supplied name.
Definition: SpikingGroup.cpp:760
void conditional_evolve()
Conditional evolve functino which is called by System.
Definition: SpikingGroup.cpp:234
void set_delay(int d)
Sets axonal delay for this SpikingGroup.
Definition: SpikingGroup.cpp:345
AurynStateVector * create_state_vector(std::string key)
Creates a new state vector and throws an exception if a vector with the same name exists...
Definition: SpikingGroup.cpp:764
Tries to make a smart choice.
Definition: SpikingGroup.h:51
virtual bool load_from_file(const char *filename)
Reads current states of SpikingGroup to human-readible textfile if implemented in derived class...
Definition: SpikingGroup.cpp:585
std::string get_file_name()
Extracts the class name of the connection from the file name.
Definition: SpikingGroup.cpp:517
std::vector< AurynFloat > post_state_traces_spike_biases
Definition: SpikingGroup.h:112
bool localrank(NeuronID i)
Checks if the global NeuronID i is integrated on this MPI rank.
Definition: SpikingGroup.cpp:531
std::vector< Trace * > posttraces
Posttraces.
Definition: SpikingGroup.h:108
NeuronID global2rank(NeuronID i)
Converts global NeuronID within the SpikingGroup to the local NeuronID on this rank.
Definition: SpikingGroup.h:446
std::vector< NeuronID > SpikeContainer
Spike container type. Used for storing spikes.
Definition: auryn_definitions.h:161
NeuronID ranksize()
Returns size (num of neurons) on the current rank.
Definition: SpikingGroup.cpp:300
std::string group_name
Identifying name for object.
Definition: SpikingGroup.h:116
friend class boost::serialization::access
Definition: SpikingGroup.h:71
virtual void evolve_traces()
Evolves traces.
Definition: SpikingGroup.cpp:463
Default mode of distribution.
Definition: SpikingGroup.h:52
Abstract base class of all objects producing spikes.
Definition: SpikingGroup.h:67
NeuronID get_uid()
Get the unique ID of the class.
Definition: SpikingGroup.cpp:265
std::vector< float > AttributeContainer
Attribute container type. Used for storing spike attributes that are needed for efficient STP impleme...
Definition: auryn_definitions.h:162
SpikeContainer * get_spikes()
Returns pointer to a spike container that contains spikes which arrive in this timestep from all neur...
Definition: SpikingGroup.cpp:245
SpikingGroup(NeuronID size, NodeDistributionMode mode=AUTO)
Default constructor.
Definition: SpikingGroup.cpp:38
std::vector< Trace * > pretraces
Pretraces.
Definition: SpikingGroup.h:105
std::vector< AurynStateVector * > post_state_traces_states
Definition: SpikingGroup.h:113
AurynStateVector * get_state_vector(std::string key)
Creates a new or returns an existing state vector by name.
Definition: SpikingGroup.cpp:781
NeuronID rank_size
Stores the size of the group on this rank.
Definition: SpikingGroup.h:121
Abstract base class of synaptic traces.
Definition: Trace.h:36
Delay object for spikes which is synchronized between nodes using the SyncBuffer formalism implemente...
Definition: SpikeDelay.h:47
virtual void load_input_line(NeuronID i, const char *buf)
Definition: SpikingGroup.cpp:840
mpi::communicator * mpicommunicator
Global pointer to instance of mpi::mpicommunicator which needs to be initialized in every simulation ...
Definition: auryn_global.cpp:32
virtual void virtual_serialize(boost::archive::binary_oarchive &ar, const unsigned int version)
Implementatinon of serialize function for writing.
Definition: SpikingGroup.cpp:632
Trace * get_post_state_trace(std::string state_name="mem", AurynFloat tau=10e-3, AurynFloat b=0.0)
Returns a post trace of a neuronal state variable e.g. the membrane potential with time constant tau...
Definition: SpikingGroup.cpp:457
AurynStateVector * find_state_vector(std::string key)
Returns existing state vector by name or NULL if it does not exist.
Definition: SpikingGroup.cpp:748
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
bool active
Toggles group active.
Definition: SpikingGroup.h:149
std::map< std::string, AurynStateVector * > state_vectors
Definition: SpikingGroup.h:153
Definition: ABSConnection.h:38
A generic logger class that logs to screen and a log-file.
Definition: Logger.h:48
void remove_state_vector(std::string key)
Removes a state vector passed as an argument to the dictinary.
Definition: SpikingGroup.cpp:743
Trace * get_pre_trace(AurynFloat x)
Returns a pre trace with time constant x.
Definition: SpikingGroup.cpp:359
void set_clock_ptr(AurynTime *clock)
Definition: SpikingGroup.cpp:228
AurynFloat AurynState
Type for Auryn state variables (default single precision since it needs to be compatible with auryn_v...
Definition: auryn_definitions.h:160
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: SpikingGroup.cpp:523
Tries to implement block lock.
Definition: SpikingGroup.h:53
SpikeContainer * spikes
SpikeContainers to store spikes produced during one step of evolve.
Definition: SpikingGroup.h:123
void add_state_vector(std::string key, AurynStateVector *state_vector)
Adds a state vector passed as an argument to the dictinary.
Definition: SpikingGroup.cpp:729
void add_post_trace(Trace *tr)
Adds trace to posttrace stack of a connection.
Definition: SpikingGroup.cpp:408
NeuronID get_vector_size()
Rank size but rounded up to multiples of 4 (or potentially some other and larger number in future ver...
Definition: SpikingGroup.cpp:901
float AurynFloat
Low precision floating point datatype.
Definition: auryn_definitions.h:157
virtual ~SpikingGroup()
Default destructor.
Definition: SpikingGroup.cpp:43
NeuronID calculate_rank_size(int rank=-1)
Determines rank size and stores it in local variable.
Definition: SpikingGroup.cpp:281
NeuronID rank2global(NeuronID i)
Converts local NeuronID from the local rank to a global NeuronID.
Definition: SpikingGroup.cpp:319
void push_spike(NeuronID spike)
Pushes a local NeuronID as spike into the axonal SpikeDelay buffer.
Definition: SpikingGroup.cpp:270
void free()
Frees potentially allocated memory.
Definition: SpikingGroup.cpp:182
unsigned int get_locked_range()
Returns locked range of ranks for SpikingGroups which are not distributed across all ranks...
Definition: SpikingGroup.cpp:334
void add_pre_trace(Trace *tr)
Adds trace to pretrace stack of a connection.
Definition: SpikingGroup.cpp:376
Trace * get_post_trace(AurynFloat x)
Returns a post trace with time constant x.
Definition: SpikingGroup.cpp:390
void clear_spikes()
Clears all spikes stored in the delays which is useful to reset a network during runtime.
Definition: SpikingGroup.cpp:339
NeuronID get_size()
Returns the size of the group.
Definition: SpikingGroup.cpp:304
AttributeContainer * attribs
Definition: SpikingGroup.h:124
NeuronID size
Stores the size of the group.
Definition: SpikingGroup.h:119
SpikeDelay * delay
Definition: SpikingGroup.h:144
SpikeContainer * get_spikes_immediate()
Returns pointer to SpikeContainer of spikes generated during the last evolve() step.
Definition: SpikingGroup.cpp:250
NeuronID get_post_size()
Returns the size on this rank.
Definition: SpikingGroup.cpp:314
Default AurynVectorFloat class for performance computation.
Definition: AurynVector.h:796
void set_name(std::string s)
Set connection name.
Definition: SpikingGroup.cpp:507
static AurynTime * clock_ptr
Definition: SpikingGroup.h:127
NeuronID AurynTime
Defines Auryns discrete time unit of the System clock. Change to AurynLong if 120h of simtime are not...
Definition: auryn_definitions.h:155
std::map< std::string, AurynState > state_variables
Definition: SpikingGroup.h:156
virtual bool write_to_file(const char *filename)
Writes current states of SpikingGroup to human-readible textfile if implemented in derived class...
Definition: SpikingGroup.cpp:549
void push_attribute(AurynFloat attrib)
Pushes a spike attribute into the axonal SpikeDelay buffer.
Definition: SpikingGroup.cpp:275
int get_num_spike_attributes()
Definition: SpikingGroup.cpp:915
AttributeContainer * get_attributes_immediate()
Returns pointer to Attributecontainer of spikes generated during the last evolve() step...
Definition: SpikingGroup.cpp:260
AurynState * get_state_variable(std::string key)
Creates a new group-wide state variable or returns an existing group-wide variable by name then retur...
Definition: SpikingGroup.cpp:921
void randomize_state_vector_gauss(std::string state_vector_name, AurynState mean, AurynState sigma, int seed=12239)
Randomizes the content of a state vector with Gaussian random numbers. Seeding is MPI save...
Definition: SpikingGroup.cpp:792
std::vector< Trace * > post_state_traces
Post state traces.
Definition: SpikingGroup.h:111
void inc_num_spike_attributes(int x)
Instructs SpikingGroup to increase the number of spike attributes by x.
Definition: SpikingGroup.cpp:906
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
std::string get_name()
Retrieves the groups name.
Definition: SpikingGroup.cpp:512
unsigned int get_locked_rank()
Returns locked rank for SpikingGroups which are not distributed across all ranks. ...
Definition: SpikingGroup.cpp:329
virtual void evolve()=0
Virtual pure evolve function which needs to be implemented by derived classes.
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
AttributeContainer * get_attributes()
Returns pointer to Attributecontainer for usage in propagating Connection objects. Same as get_spikes_immediate(), however might be overwritten to contain Spikes that have been delayed.
Definition: SpikingGroup.cpp:255
NodeDistributionMode
Specifies howto distribute different neurons across ranks when simulation is run in parallel...
Definition: SpikingGroup.h:50
NeuronID get_pre_size()
Returns the size of the group.
Definition: SpikingGroup.cpp:309