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::StateMonitor Class Reference

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

#include <StateMonitor.h>

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

Public Member Functions

 StateMonitor (SpikingGroup *source, NeuronID id, string statename, string filename, AurynDouble sampling_interval=auryn_timestep)
 Standard constructor. More...
 
 StateMonitor (AurynStateVector *state, NeuronID id, string filename, AurynDouble sampling_interval=auryn_timestep)
 Alternative constructor. More...
 
 StateMonitor (AurynSynStateVector *state, NeuronID id, string filename, AurynDouble sampling_interval=auryn_timestep)
 Alternative constructor for synaptic states. More...
 
 StateMonitor (Trace *trace, NeuronID id, 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...
 
void set_step_size (int step=1)
 Sets the step size. More...
 
virtual ~StateMonitor ()
 
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 open_output_file (std::string filename)
 
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 file.

Constructor & Destructor Documentation

◆ StateMonitor() [1/4]

StateMonitor::StateMonitor ( 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
31  : Monitor(filename, "state")
32 {
33 
34  if ( !source->localrank(id) ) return; // do not register if neuron is not on the local rank
35 
36  init(filename, sampling_interval);
38  src = source;
39  nid = src->global2rank(id);
40 
41  if ( nid >= src->get_rank_size() ) {
42  auryn::logger->msg("Error: StateMonitor trying to read from non-existing neuron.",ERROR);
44  }
45 
46  // TODO test if state exists -- use find_state_vector instead ..
47  if ( source->evolve_locally() ) {
49  } else {
50  nid = src->get_rank_size() + 1;
51  }
52 }
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
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
SpikingGroup * src
The source SpikingGroup to record from.
Definition: StateMonitor.h:44
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
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
NeuronID nid
The source neuron id to record from.
Definition: StateMonitor.h:54
AurynState * target_variable
Target variable.
Definition: StateMonitor.h:47
Definition: auryn_definitions.h:289
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:

◆ StateMonitor() [2/4]

StateMonitor::StateMonitor ( AurynStateVector 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
54  : Monitor(filename, "state")
55 {
56  if ( id >= state->size ) return; // do not register if neuron is out of vector range
57 
58  init(filename, sampling_interval);
59 
61  src = NULL;
62  nid = id;
63  target_variable = state->data+nid;
65 }
T * data
Pointer to the array housing the data.
Definition: AurynVector.h:154
IndexType size
Size of the vector.
Definition: AurynVector.h:151
SpikingGroup * src
The source SpikingGroup to record from.
Definition: StateMonitor.h:44
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
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
NeuronID nid
The source neuron id to record from.
Definition: StateMonitor.h:54
AurynState * target_variable
Target variable.
Definition: StateMonitor.h:47
AurynState lastval
Last value (used for compression)
Definition: StateMonitor.h:50
Here is the call graph for this function:

◆ StateMonitor() [3/4]

StateMonitor::StateMonitor ( AurynSynStateVector state,
NeuronID  id,
std::string  filename,
AurynDouble  sampling_interval = auryn_timestep 
)

Alternative constructor for synaptic states.

Parameters
stateThe source state vector
filenameThe filename of the file to dump the output to
sampling_intervalThe sampling interval in seconds
67  : Monitor(filename, "state")
68 {
69  if ( id >= state->size ) return; // do not register if neuron is out of vector range
70 
71  init(filename, sampling_interval);
72 
74  src = NULL;
75  nid = id;
76  target_variable = state->data+nid;
78 }
T * data
Pointer to the array housing the data.
Definition: AurynVector.h:154
IndexType size
Size of the vector.
Definition: AurynVector.h:151
SpikingGroup * src
The source SpikingGroup to record from.
Definition: StateMonitor.h:44
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
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
NeuronID nid
The source neuron id to record from.
Definition: StateMonitor.h:54
AurynState * target_variable
Target variable.
Definition: StateMonitor.h:47
AurynState lastval
Last value (used for compression)
Definition: StateMonitor.h:50
Here is the call graph for this function:

◆ StateMonitor() [4/4]

StateMonitor::StateMonitor ( 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
80  : Monitor(filename, "state")
81 {
82  if ( id >= trace->get_state_ptr()->size ) return; // do not register if neuron is out of vector range
83 
84  init(filename, sampling_interval);
85 
87  src = NULL;
88  nid = id;
91 }
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
IndexType size
Size of the vector.
Definition: AurynVector.h:151
SpikingGroup * src
The source SpikingGroup to record from.
Definition: StateMonitor.h:44
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
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
NeuronID nid
The source neuron id to record from.
Definition: StateMonitor.h:54
AurynState * target_variable
Target variable.
Definition: StateMonitor.h:47
AurynState lastval
Last value (used for compression)
Definition: StateMonitor.h:50
Here is the call graph for this function:

◆ ~StateMonitor()

StateMonitor::~StateMonitor ( )
virtual
108 {
109  AurynState value = *target_variable;
110  AurynState deriv = value-lastval;
111  if ( enable_compression && deriv==lastder ) { //terminate output with last value
112  char buffer[255];
113  int n = sprintf(buffer,"%f %f\n",auryn::sys->get_time(), *target_variable);
114  outfile.write(buffer,n);
115  }
116 }
int n
Definition: mkpat.py:5
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
AurynState * target_variable
Target variable.
Definition: StateMonitor.h:47
AurynState lastder
Definition: StateMonitor.h:51
AurynState lastval
Last value (used for compression)
Definition: StateMonitor.h:50
bool enable_compression
Switch to enable/disable output compression.
Definition: StateMonitor.h:75

Member Function Documentation

◆ execute()

void StateMonitor::execute ( )
virtual

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

Reimplemented from auryn::Device.

Reimplemented in auryn::VoltageClampMonitor, and auryn::VoltageMonitor.

119 {
120  if ( auryn::sys->get_clock() < t_stop && auryn::sys->get_clock()%ssize==0 ) {
121  char buffer[255];
122  if ( enable_compression && auryn::sys->get_clock()>0 ) {
123  AurynState value = *target_variable;
124  AurynState deriv = value-lastval;
125 
126  if ( deriv != lastder ) {
127  int n = sprintf(buffer,"%f %f\n",(auryn::sys->get_clock()-ssize)*auryn_timestep, lastval);
128  outfile.write(buffer,n);
129  }
130 
131  lastval = value;
132  lastder = deriv;
133 
134  } else {
135  int n = sprintf(buffer,"%f %f\n",auryn::sys->get_time(), *target_variable);
136  outfile.write(buffer,n);
137  }
138  }
139 }
int n
Definition: mkpat.py:5
std::ofstream outfile
Definition: Monitor.h:58
AurynTime ssize
The step size (sampling interval) in units of auryn_timestep.
Definition: StateMonitor.h:57
AurynFloat AurynState
Type for Auryn state variables (default single precision since it needs to be compatible with auryn_v...
Definition: auryn_definitions.h:160
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
AurynState * target_variable
Target variable.
Definition: StateMonitor.h:47
AurynState lastder
Definition: StateMonitor.h:51
AurynState lastval
Last value (used for compression)
Definition: StateMonitor.h:50
AurynTime t_stop
Defines the maximum recording time in AurynTime to save space.
Definition: StateMonitor.h:60
bool enable_compression
Switch to enable/disable output compression.
Definition: StateMonitor.h:75

◆ init()

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

Standard initialization.

94 {
95  outfile << std::setiosflags(std::ios::fixed) << std::setprecision(6);
96 
97  // set_stop_time(10.0);
98  t_stop = -1; // at the end of all times
99  ssize = sampling_interval/auryn_timestep;
100  if ( ssize < 1 ) ssize = 1;
101 
102  enable_compression = false;
103  lastval = 0.0;
104  lastder = 0.0;
105 }
std::ofstream outfile
Definition: Monitor.h:58
AurynTime ssize
The step size (sampling interval) in units of auryn_timestep.
Definition: StateMonitor.h:57
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
AurynState lastder
Definition: StateMonitor.h:51
AurynState lastval
Last value (used for compression)
Definition: StateMonitor.h:50
AurynTime t_stop
Defines the maximum recording time in AurynTime to save space.
Definition: StateMonitor.h:60
bool enable_compression
Switch to enable/disable output compression.
Definition: StateMonitor.h:75

◆ record_for()

void StateMonitor::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.

154 {
155  if (time < 0) {
156  auryn::logger->msg("Warning: Negative stop times not supported -- ingoring.",WARNING);
157  }
158  else t_stop = auryn::sys->get_clock() + time/auryn_timestep;
159  auryn::logger->debug("Set record for times for monitor.");
160 }
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
AurynTime t_stop
Defines the maximum recording time in AurynTime to save space.
Definition: StateMonitor.h:60
Here is the call graph for this function:

◆ set_step_size()

void StateMonitor::set_step_size ( int  step = 1)

Sets the step size.

Sets the sampling interval using units of AurynTime.

Parameters
stepThe step size
148 {
149  if ( step >= 1 ) ssize = step;
150  else ssize = 1;
151 }
AurynTime ssize
The step size (sampling interval) in units of auryn_timestep.
Definition: StateMonitor.h:57

◆ set_stop_time()

void StateMonitor::set_stop_time ( AurynDouble  time = 10.0)

Set an absolute time when to stop recording.

142 {
143  AurynDouble stoptime = std::min( time, std::numeric_limits<AurynTime>::max()*auryn_timestep );
144  t_stop = stoptime/auryn_timestep;
145 }
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
AurynTime t_stop
Defines the maximum recording time in AurynTime to save space.
Definition: StateMonitor.h:60

Member Data Documentation

◆ enable_compression

bool auryn::StateMonitor::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::StateMonitor::lastder
protected

◆ lastval

AurynState auryn::StateMonitor::lastval
protected

Last value (used for compression)

◆ nid

NeuronID auryn::StateMonitor::nid
protected

The source neuron id to record from.

◆ src

SpikingGroup* auryn::StateMonitor::src
protected

The source SpikingGroup to record from.

◆ ssize

AurynTime auryn::StateMonitor::ssize
protected

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

◆ t_stop

AurynTime auryn::StateMonitor::t_stop
protected

Defines the maximum recording time in AurynTime to save space.

◆ target_variable

AurynState* auryn::StateMonitor::target_variable
protected

Target variable.


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