Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
System.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 SYSTEM_H_
27 #define SYSTEM_H_
28 
29 #include "auryn_definitions.h"
30 #include "AurynVector.h"
31 #include "Device.h"
32 #include "SpikingGroup.h"
33 #include "Connection.h"
34 #include "Checker.h"
35 #include "AurynVersion.h"
36 
37 
38 #ifdef AURYN_CODE_USE_MPI
39 #include <boost/mpi.hpp>
40 #include "SyncBuffer.h"
41 #endif //AURYN_CODE_USE_MPI
42 
43 #include <ctime>
44 #include <vector>
45 
46 #include <boost/progress.hpp>
47 #include <boost/random/mersenne_twister.hpp>
48 #include <boost/random/variate_generator.hpp>
49 #include <boost/random/uniform_int.hpp>
50 #include <boost/random/uniform_int_distribution.hpp>
51 
52 #define PROGRESSBAR_DEFAULT_UPDATE_INTERVAL 1000
53 #define LOGGER_MARK_INTERVAL (10000*1000) // 1000s
54 
55 namespace auryn {
56 
57 // class SpikingGroup; // forward declaration
58 // class Connection; // forward declaration
59 
70  class System
71  {
72 
73  private:
74  AurynTime clock;
75 #ifdef AURYN_CODE_USE_MPI
76  mpi::communicator * mpicom;
77  SyncBuffer * syncbuffer;
78 #endif // AURYN_CODE_USE_MPI
79 
80  unsigned int mpi_size_;
81  unsigned int mpi_rank_;
82 
83  std::string simulation_name;
84 
85  std::vector<SpikingGroup *> spiking_groups;
86  std::vector<Connection *> connections;
87  std::vector<Device *> devices;
88  std::vector<Checker *> checkers;
89 
90  string outputdir;
91 
92  boost::mt19937 seed_gen;
93  boost::random::uniform_int_distribution<> * seed_dist;
94  boost::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<> > * seed_die;
95 
96  double simulation_time_realtime_ratio;
97 
99  double last_elapsed_time;
100 
102  time_t t_sys_start;
103 
104  int online_rate_monitor_id;
105  SpikingGroup * online_rate_monitor_target;
106  double online_rate_monitor_tau;
107  double online_rate_monitor_mul;
108  double online_rate_monitor_state;
109 
111  void evolve_online_rate_monitor();
112 
114  std::string get_nice_time ( AurynTime clk );
115 
117  void progressbar ( double fraction, AurynTime clk );
118 
123  bool run(AurynTime starttime, AurynTime stoptime, AurynFloat total_time, bool checking=true);
124 
126  void sync();
127 
129  void evolve();
130 
132  void propagate();
133 
134 
139  void evolve_connections();
140 
142  void execute_devices();
143 
145  bool execute_checkers();
146 
148  void step();
149 
151  void sync_prepare();
152 
153  void init();
154  void free();
155 
156  public:
158  bool quiet;
159 
162 
165 
166 #ifdef AURYN_CODE_USE_MPI
167 
168  System(mpi::communicator * communicator);
169 #else
170 
171  System();
172 #endif // AURYN_CODE_USE_MPI
173 
175  void set_simulation_name(std::string name);
176 
179 
181  void set_output_dir(std::string path);
182 
183  virtual ~System();
184 
185 
187  void set_online_rate_monitor_target( SpikingGroup * group = NULL );
188 
198  void set_online_rate_monitor_id( unsigned int id=0 );
199 
201  void set_online_rate_monitor_tau( AurynDouble tau=100e-3 );
202 
204  double get_last_elapsed_time();
205 
207  double get_total_elapsed_time();
208 
223  void save_network_state(std::string basename);
224 
229  void load_network_state(std::string basename);
230 
241  void save_network_state_text(std::string basename);
242 
243 
247  void flush_devices();
248 
249 
253  void register_spiking_group(SpikingGroup * spiking_group);
254 
258  void register_connection(Connection * connection);
259 
263  void register_device(Device * device);
264 
269  void register_checker(Checker * checker);
270 
271 
279  bool run(AurynFloat simulation_time, bool checking=true);
280 
289  bool run_chunk(AurynFloat chunk_time, AurynFloat interval_start, AurynFloat interval_end, bool checking=true);
290 
293 
296 
299 
302 
305 
308 
316  string fn(std::string extension);
317 
318 
325  string fn(std::string name, std::string extension);
326 
333  string fn(std::string name, NeuronID index, std::string extension);
334 
335 
337 #ifdef AURYN_CODE_USE_MPI
338  mpi::communicator * get_com();
339 #endif // AURYN_CODE_USE_MPI
340 
345  unsigned int mpi_size();
346 
351  unsigned int mpi_rank();
352 
359  void set_master_seed( unsigned int seed = 123);
360 
364  unsigned int get_seed();
365 
370  unsigned int get_synced_seed();
371 
372 #ifdef CODE_COLLECT_SYNC_TIMING_STATS
373  AurynDouble deltaT;
374  AurynDouble measurement_start;
375  AurynDouble get_relative_sync_time();
376  AurynDouble get_sync_time();
377  AurynDouble get_elapsed_wall_time();
378  void reset_sync_time();
379 #endif
380 
381  };
382 } // end of namespace brackets
383 
384 #endif /*SYSTEM_H_*/
AurynDouble get_total_effective_load()
Get total effective load.
void set_output_dir(std::string path)
Set output dir for fn function.
Definition: System.cpp:664
bool run_chunk(AurynFloat chunk_time, AurynFloat interval_start, AurynFloat interval_end, bool checking=true)
Runs simulation for a given amount of time.
Definition: System.cpp:634
unsigned int get_seed()
Returns a random seed which is different on each rank.
Definition: System.cpp:1030
unsigned int progressbar_update_interval
The progressbar update interval in timesteps of auryn_timestep.
Definition: System.h:164
The abstract base class for all Connection objects in Auryn.
Definition: Connection.h:53
double get_total_elapsed_time()
Returns total elapsed time in seconds.
Definition: System.cpp:961
mpi::communicator * get_com()
Returns global mpi communicator.
Definition: System.cpp:648
std::string get_simulation_name()
Returns the simulation name.
Definition: System.cpp:659
Class that implements system wide variables and methods to manage and run simulations.
Definition: System.h:70
unsigned int mpi_rank()
Returns current rank.
Definition: System.cpp:1009
unsigned int mpi_size()
Returns number of ranks.
Definition: System.cpp:1004
Container class providing Auryn version number.
Definition: AurynVersion.h:37
void load_network_state(std::string basename)
Loads network state from a netstate file.
Definition: System.cpp:812
void set_online_rate_monitor_target(SpikingGroup *group=NULL)
Sets the target group for online rate estimate.
Definition: System.cpp:950
double get_last_elapsed_time()
Returns last elapsed time in seconds.
Definition: System.cpp:956
Abstract base class of all objects producing spikes.
Definition: SpikingGroup.h:67
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
AurynLong get_total_synapses()
Get total number of registered synapses.
Definition: System.cpp:251
AurynTime * get_clock_ptr()
Gets a pointer to the current clock.
Definition: System.cpp:236
void register_checker(Checker *checker)
Registers an instance of Checker to the checkers vector.
Definition: System.cpp:277
void set_simulation_name(std::string name)
Sets the simulation name.
Definition: System.cpp:654
AurynVersion build
Version info.
Definition: System.h:161
Definition: ABSConnection.h:38
bool quiet
Switch to turn output to quiet mode (no progress bar).
Definition: System.h:158
void flush_devices()
Flush devices.
Definition: System.cpp:969
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
void set_online_rate_monitor_tau(AurynDouble tau=100e-3)
Sets the timeconstant to compute the online rate average for the status bar.
Definition: System.cpp:925
void register_device(Device *device)
Registers an instance of Device to the devices vector.
Definition: System.cpp:272
float AurynFloat
Low precision floating point datatype.
Definition: auryn_definitions.h:157
The abstract base class for all checkers.
Definition: Checker.h:47
void save_network_state_text(std::string basename)
Saves the network state to human readable text files.
Definition: System.cpp:784
void set_master_seed(unsigned int seed=123)
Set master seed.
Definition: System.cpp:1014
virtual ~System()
Definition: System.cpp:171
AurynDouble get_time()
Gets the current system time in [s].
Definition: System.cpp:226
void set_online_rate_monitor_id(unsigned int id=0)
Sets the SpikingGroup used to display the rate estimate in the progressbar.
Definition: System.cpp:939
Buffer object to capsulate native MPI_Allgather for SpikingGroups.
Definition: SyncBuffer.h:57
void register_spiking_group(SpikingGroup *spiking_group)
Registers an instance of SpikingGroup to the spiking_groups vector.
Definition: System.cpp:261
unsigned int get_synced_seed()
Returns a random seed which is the same on each rank.
Definition: System.cpp:1035
System(mpi::communicator *communicator)
Default constructor for MPI enabled.
Definition: System.cpp:139
void register_connection(Connection *connection)
Registers an instance of Connection to the connections vector.
Definition: System.cpp:267
AurynTime get_clock()
Gets the current clock value in AurynTime.
Definition: System.cpp:231
AurynLong get_total_neurons()
Get total number of registered neurons.
Definition: System.cpp:241
string fn(std::string extension)
Format output file name.
Definition: System.cpp:689
void save_network_state(std::string basename)
Saves network state to a netstate file.
Definition: System.cpp:694
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
Abstract base class for all Device, Stimulator, etc objects.
Definition: Device.h:47
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151