Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
auryn::BinaryStateMonitor Class Reference

Records from an arbitray state vector of one unit from the source SpikingGroup to a binary file. More...

#include <BinaryStateMonitor.h>

Inheritance diagram for auryn::BinaryStateMonitor:
Inheritance graph
[legend]
Collaboration diagram for auryn::BinaryStateMonitor:
Collaboration graph
[legend]

Public Member Functions

 BinaryStateMonitor (SpikingGroup *source, NeuronID id, string statename, std::string filename="", AurynDouble sampling_interval=auryn_timestep)
 Standard constructor. More...
 
 BinaryStateMonitor (auryn_vector_float *state, NeuronID id, std::string filename="", AurynDouble sampling_interval=auryn_timestep)
 Alternative constructor. More...
 
 BinaryStateMonitor (Trace *trace, NeuronID id, std::string filename="", AurynDouble sampling_interval=auryn_timestep)
 Trace constructor. More...
 
void record_for (AurynDouble time=10.0)
 Sets relative time at which to stop recording. More...
 
void set_stop_time (AurynDouble time=10.0)
 Set an absolute time when to stop recording. More...
 
virtual ~BinaryStateMonitor ()
 
void execute ()
 
- Public Member Functions inherited from auryn::Monitor
virtual void flush ()
 Flush to file. More...
 
 Monitor (std::string filename, std::string default_extension="dat")
 Standard constructor with file name. More...
 
 Monitor ()
 Constructor which does not open a text file for output. More...
 
std::string generate_filename (std::string name_hint="")
 Generates a default filename from the device ID. More...
 
virtual ~Monitor ()
 Standard destructor. More...
 
- Public Member Functions inherited from auryn::Device
 Device ()
 Standard constructor. More...
 
void set_name (std::string s)
 Set device name. More...
 
std::string get_name ()
 Get device name. More...
 
int get_id ()
 Get numeric device id. More...
 
virtual ~Device ()
 Standard destructor. More...
 
virtual void evolve ()
 

Public Attributes

bool enable_compression
 Switch to enable/disable output compression. More...
 
- Public Attributes inherited from auryn::Monitor
bool active
 Standard active switch. More...
 
- Public Attributes inherited from auryn::Device
bool active
 Standard active switch. More...
 

Protected Member Functions

void init (string filename, AurynDouble stepsize)
 Standard initialization. More...
 
- Protected Member Functions inherited from auryn::Monitor
virtual void virtual_serialize (boost::archive::binary_oarchive &ar, const unsigned int version)
 
virtual void virtual_serialize (boost::archive::binary_iarchive &ar, const unsigned int version)
 
- Protected Member Functions inherited from auryn::Device
void init ()
 Standard initializer to be called by the constructor. More...
 

Protected Attributes

SpikingGroupsrc
 The source SpikingGroup to record from. More...
 
AurynStatetarget_variable
 Target variable. More...
 
AurynState lastval
 Last value (used for compression) More...
 
AurynState lastder
 
NeuronID nid
 The source neuron id to record from. More...
 
AurynTime ssize
 The step size (sampling interval) in units of auryn_timestep. More...
 
AurynTime t_stop
 Defines the maximum recording time in AurynTime to save space. More...
 
- Protected Attributes inherited from auryn::Monitor
std::ofstream outfile
 
std::string fname
 
std::string default_file_extension
 
- Protected Attributes inherited from auryn::Device
std::string device_name
 Identifying name for device. More...
 

Detailed Description

Records from an arbitray state vector of one unit from the source SpikingGroup to a binary file.

Binary state files need to be read with the command line tool aubs or with custom code.

Constructor & Destructor Documentation

◆ BinaryStateMonitor() [1/3]

BinaryStateMonitor::BinaryStateMonitor ( SpikingGroup source,
NeuronID  id,
std::string  statename,
std::string  filename = "",
AurynDouble  sampling_interval = auryn_timestep 
)

Standard constructor.

Parameters
sourceThe neuron group to record from
idThe neuron id in the group to record from
statenameThe name of the StateVector to record from
filenameThe filename of the file to dump the output to
sampling_intervalThe sampling interval in seconds
32  : Monitor(filename, default_extension)
33 {
34 
35  if ( !source->localrank(id) ) return; // do not register if neuron is not on the local rank
36 
37  init(filename, sampling_interval);
39  src = source;
40  nid = src->global2rank(id);
41 
42  if ( nid >= src->get_rank_size() ) {
43  auryn::logger->msg("Error: BinaryStateMonitor trying to read from non-existing neuron.",ERROR);
45  }
46 
47  // TODO test if state exists -- use find_state_vector instead ..
48  if ( source->evolve_locally() ) {
50  } else {
51  nid = src->get_rank_size() + 1;
52  }
53 }
NeuronID get_rank_size()
Returns the size on this rank.
Definition: SpikingGroup.h:450
bool localrank(NeuronID i)
Checks if the global NeuronID i is integrated on this MPI rank.
Definition: SpikingGroup.cpp:531
NeuronID global2rank(NeuronID i)
Converts global NeuronID within the SpikingGroup to the local NeuronID on this rank.
Definition: SpikingGroup.h:446
T * data
Pointer to the array housing the data.
Definition: AurynVector.h:154
AurynState * target_variable
Target variable.
Definition: BinaryStateMonitor.h:55
AurynStateVector * get_state_vector(std::string key)
Creates a new or returns an existing state vector by name.
Definition: SpikingGroup.cpp:781
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
void init()
Standard initializer to be called by the constructor.
Definition: Device.cpp:32
Monitor()
Constructor which does not open a text file for output.
Definition: Monitor.cpp:47
NeuronID nid
The source neuron id to record from.
Definition: BinaryStateMonitor.h:62
void register_device(Device *device)
Registers an instance of Device to the devices vector.
Definition: System.cpp:272
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
Definition: Logger.h:41
Definition: auryn_definitions.h:289
SpikingGroup * src
The source SpikingGroup to record from.
Definition: BinaryStateMonitor.h:52
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Here is the call graph for this function:

◆ BinaryStateMonitor() [2/3]

BinaryStateMonitor::BinaryStateMonitor ( auryn_vector_float state,
NeuronID  id,
std::string  filename = "",
AurynDouble  sampling_interval = auryn_timestep 
)

Alternative constructor.

Parameters
stateThe source state vector
filenameThe filename of the file to dump the output to
sampling_intervalThe sampling interval in seconds
55  : Monitor(filename, default_extension)
56 {
57  if ( id >= state->size ) return; // do not register if neuron is out of vector range
58 
59  init(filename, sampling_interval);
60 
62  src = NULL;
63  nid = id;
64  target_variable = state->data+nid;
66 }
AurynState lastval
Last value (used for compression)
Definition: BinaryStateMonitor.h:58
T * data
Pointer to the array housing the data.
Definition: AurynVector.h:154
AurynState * target_variable
Target variable.
Definition: BinaryStateMonitor.h:55
IndexType size
Size of the vector.
Definition: AurynVector.h:151
void init()
Standard initializer to be called by the constructor.
Definition: Device.cpp:32
Monitor()
Constructor which does not open a text file for output.
Definition: Monitor.cpp:47
NeuronID nid
The source neuron id to record from.
Definition: BinaryStateMonitor.h:62
void register_device(Device *device)
Registers an instance of Device to the devices vector.
Definition: System.cpp:272
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
SpikingGroup * src
The source SpikingGroup to record from.
Definition: BinaryStateMonitor.h:52
Here is the call graph for this function:

◆ BinaryStateMonitor() [3/3]

BinaryStateMonitor::BinaryStateMonitor ( Trace trace,
NeuronID  id,
std::string  filename = "",
AurynDouble  sampling_interval = auryn_timestep 
)

Trace constructor.

Parameters
traceThe source synaptic trace
filenameThe filename of the file to dump the output to
sampling_intervalThe sampling interval in seconds
68  : Monitor(filename, default_extension)
69 {
70  if ( id >= trace->get_state_ptr()->size ) return; // do not register if neuron is out of vector range
71 
72  init(filename, sampling_interval);
73 
75  src = NULL;
76  nid = id;
79 }
AurynState lastval
Last value (used for compression)
Definition: BinaryStateMonitor.h:58
virtual AurynStateVector * get_state_ptr()
Get pointer to state AurynStateVector for fast processing.
Definition: Trace.cpp:51
T * data
Pointer to the array housing the data.
Definition: AurynVector.h:154
AurynState * target_variable
Target variable.
Definition: BinaryStateMonitor.h:55
IndexType size
Size of the vector.
Definition: AurynVector.h:151
void init()
Standard initializer to be called by the constructor.
Definition: Device.cpp:32
Monitor()
Constructor which does not open a text file for output.
Definition: Monitor.cpp:47
NeuronID nid
The source neuron id to record from.
Definition: BinaryStateMonitor.h:62
void register_device(Device *device)
Registers an instance of Device to the devices vector.
Definition: System.cpp:272
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
SpikingGroup * src
The source SpikingGroup to record from.
Definition: BinaryStateMonitor.h:52
Here is the call graph for this function:

◆ ~BinaryStateMonitor()

BinaryStateMonitor::~BinaryStateMonitor ( )
virtual
120 {
121  AurynState value = *target_variable;
122  AurynState deriv = value-lastval;
123  if ( enable_compression && deriv==lastder ) { //terminate output with last value, but only if wasn't written already
124  const AurynTime t = auryn::sys->get_clock()-ssize;
125  write_frame(t, lastval);
126  }
127 
128  outfile.close();
129 }
AurynState lastval
Last value (used for compression)
Definition: BinaryStateMonitor.h:58
AurynState * target_variable
Target variable.
Definition: BinaryStateMonitor.h:55
AurynTime ssize
The step size (sampling interval) in units of auryn_timestep.
Definition: BinaryStateMonitor.h:65
AurynState lastder
Definition: BinaryStateMonitor.h:59
std::ofstream outfile
Definition: Monitor.h:58
AurynFloat AurynState
Type for Auryn state variables (default single precision since it needs to be compatible with auryn_v...
Definition: auryn_definitions.h:160
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
bool enable_compression
Switch to enable/disable output compression.
Definition: BinaryStateMonitor.h:83
AurynTime get_clock()
Gets the current clock value in AurynTime.
Definition: System.cpp:231
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
Here is the call graph for this function:

Member Function Documentation

◆ execute()

void BinaryStateMonitor::execute ( )
virtual

Virtual execute function to be called at the end of central simulation loop in System

Reimplemented from auryn::Device.

141 {
142  if ( auryn::sys->get_clock() < t_stop && auryn::sys->get_clock()%ssize==0 ) {
143  if ( enable_compression && auryn::sys->get_clock()>0 ) {
144  AurynState value = *target_variable;
145  AurynState deriv = value-lastval;
146 
147  if ( deriv != lastder ) {
148  const AurynTime t = auryn::sys->get_clock()-ssize;
149  write_frame(t, lastval);
150  }
151 
152  lastval = value;
153  lastder = deriv;
154 
155  } else {
156  const AurynTime t = auryn::sys->get_clock();
157  write_frame(t, *target_variable);
158  }
159  }
160 }
AurynState lastval
Last value (used for compression)
Definition: BinaryStateMonitor.h:58
AurynState * target_variable
Target variable.
Definition: BinaryStateMonitor.h:55
AurynTime ssize
The step size (sampling interval) in units of auryn_timestep.
Definition: BinaryStateMonitor.h:65
AurynTime t_stop
Defines the maximum recording time in AurynTime to save space.
Definition: BinaryStateMonitor.h:68
AurynState lastder
Definition: BinaryStateMonitor.h:59
AurynFloat AurynState
Type for Auryn state variables (default single precision since it needs to be compatible with auryn_v...
Definition: auryn_definitions.h:160
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
bool enable_compression
Switch to enable/disable output compression.
Definition: BinaryStateMonitor.h:83
AurynTime get_clock()
Gets the current clock value in AurynTime.
Definition: System.cpp:231
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
Here is the call graph for this function:

◆ init()

void BinaryStateMonitor::init ( std::string  filename,
AurynDouble  stepsize 
)
protected

Standard initialization.

97 {
98  set_stop_time(10.0);
99  ssize = sampling_interval/auryn_timestep;
100  if ( ssize < 1 ) ssize = 1;
101 
102  enable_compression = true;
103  lastval = 0.0;
104  lastder = 0.0;
105 
106 
107  // per convention the first entry contains
108  // the number of timesteps per second
109  // the neuronID field contains a tag
110  // encoding the version number
111  StateValue_type headerFrame;
112  headerFrame.time = (AurynTime)(1.0/auryn_timestep);
113  headerFrame.value = sys->build.tag_binary_state_monitor;
114  outfile.write((char*)&headerFrame, sizeof(StateValue_type));
115 }
AurynState lastval
Last value (used for compression)
Definition: BinaryStateMonitor.h:58
Auryn spike event for binary monitors.
Definition: auryn_definitions.h:201
void set_stop_time(AurynDouble time=10.0)
Set an absolute time when to stop recording.
Definition: BinaryStateMonitor.cpp:162
AurynTime ssize
The step size (sampling interval) in units of auryn_timestep.
Definition: BinaryStateMonitor.h:65
AurynState lastder
Definition: BinaryStateMonitor.h:59
static AurynState tag_binary_state_monitor
file signature for BinaryStateMonitor files
Definition: AurynVersion.h:43
AurynState value
Definition: auryn_definitions.h:204
AurynVersion build
Version info.
Definition: System.h:161
std::ofstream outfile
Definition: Monitor.h:58
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
AurynTime time
Definition: auryn_definitions.h:203
bool enable_compression
Switch to enable/disable output compression.
Definition: BinaryStateMonitor.h:83
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
Here is the call graph for this function:

◆ record_for()

void BinaryStateMonitor::record_for ( AurynDouble  time = 10.0)

Sets relative time at which to stop recording.

The time is given in seconds and interpreted as relative time with respect to the current clock value. This features is useful to decrease IO. The stop time can be set again after calling run to record multiple snippets.

169 {
170  if (time < 0) {
171  auryn::logger->msg("Warning: Negative stop times not supported -- ingoring.",WARNING);
172  }
173  else t_stop = auryn::sys->get_clock() + time/auryn_timestep;
174  auryn::logger->debug("Set record for times for monitor.");
175 }
AurynTime t_stop
Defines the maximum recording time in AurynTime to save space.
Definition: BinaryStateMonitor.h:68
Definition: Logger.h:41
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
AurynTime get_clock()
Gets the current clock value in AurynTime.
Definition: System.cpp:231
void debug(std::string text, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:151
Here is the call graph for this function:

◆ set_stop_time()

void BinaryStateMonitor::set_stop_time ( AurynDouble  time = 10.0)

Set an absolute time when to stop recording.

163 {
164  AurynDouble stoptime = std::min( time, std::numeric_limits<AurynTime>::max()*auryn_timestep );
165  t_stop = stoptime/auryn_timestep;
166 }
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
AurynTime t_stop
Defines the maximum recording time in AurynTime to save space.
Definition: BinaryStateMonitor.h:68
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31

Member Data Documentation

◆ enable_compression

bool auryn::BinaryStateMonitor::enable_compression

Switch to enable/disable output compression.

When set to true, Auryn will compute the derivative of two consecutive datapoints of the state and only a value if the derivative changes. The correct function can then be recovered with linear interpolation (i.e. plotting in gnuplot with lines will yield the correct output). When compression is enabled the last value written to file always by one timestep with respect to the simulation clock. enable_compression is true by default.

◆ lastder

AurynState auryn::BinaryStateMonitor::lastder
protected

◆ lastval

AurynState auryn::BinaryStateMonitor::lastval
protected

Last value (used for compression)

◆ nid

NeuronID auryn::BinaryStateMonitor::nid
protected

The source neuron id to record from.

◆ src

SpikingGroup* auryn::BinaryStateMonitor::src
protected

The source SpikingGroup to record from.

◆ ssize

AurynTime auryn::BinaryStateMonitor::ssize
protected

The step size (sampling interval) in units of auryn_timestep.

◆ t_stop

AurynTime auryn::BinaryStateMonitor::t_stop
protected

Defines the maximum recording time in AurynTime to save space.

◆ target_variable

AurynState* auryn::BinaryStateMonitor::target_variable
protected

Target variable.


The documentation for this class was generated from the following files: