Skip to content

Recorder Updates for Neuro and NG911 #823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: SharedDevelopment
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Simulator/Connections/Connections.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class Connections {
/// Registered to OperationManager as Operation::printParameters
virtual void printParameters() const = 0;

/// Registers history variables for recording during simulation
virtual void registerHistoryVariables() = 0;

/// Update the connections status in every epoch.
///
/// @param vertices The vertex list to search from.
Expand Down
35 changes: 22 additions & 13 deletions Simulator/Connections/NG911/Connections911.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool Connections911::updateConnections(AllVertices &vertices)
// Record old type map
int numVertices = Simulator::getInstance().getTotalVertices();
Layout &layout = Simulator::getInstance().getModel().getLayout();
oldTypeMap_ = layout.vertexTypeMap_;
// oldTypeMap_ = layout.vertexTypeMap_;

// Erase PSAPs
for (int i = 0; i < psapsToErase_; i++) {
Expand Down Expand Up @@ -183,7 +183,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
erasedEdge.srcV = srcVertex;
erasedEdge.destV = destVertex;
erasedEdge.eType = layout.edgType(srcVertex, destVertex);
edgesErased.push_back(erasedEdge);
edgesErased_.push_back(erasedEdge);

changesMade = true;
edges_->eraseEdge(destVertex, iEdg);
Expand All @@ -204,7 +204,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)

if (changesMade) {
// This is here so that we don't delete the vertex if we can't find any edges
verticesErased.push_back(randPSAP);
verticesErased_.push_back(randPSAP);
layout.vertexTypeMap_[randPSAP] = vertexType::VTYPE_UNDEF;
}

Expand Down Expand Up @@ -238,7 +238,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
addedEdge.srcV = srcVertex;
addedEdge.destV = closestPSAP;
addedEdge.eType = edgeType::CP;
edgesAdded.push_back(addedEdge);
edgesAdded_.push_back(addedEdge);
}

// For each psap-less responder, find closest match
Expand Down Expand Up @@ -266,7 +266,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
addedEdge.srcV = closestPSAP;
addedEdge.destV = destVertex;
addedEdge.eType = edgeType::PR;
edgesAdded.push_back(addedEdge);
edgesAdded_.push_back(addedEdge);
}

return changesMade;
Expand Down Expand Up @@ -317,7 +317,7 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)
erasedEdge.srcV = srcVertex;
erasedEdge.destV = destVertex;
erasedEdge.eType = layout.edgType(srcVertex, destVertex);
edgesErased.push_back(erasedEdge);
edgesErased_.push_back(erasedEdge);

changesMade = true;
edges_->eraseEdge(destVertex, iEdg);
Expand All @@ -326,7 +326,7 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)

if (changesMade) {
// This is here so that we don't delete the vertex if we can't find any edges
verticesErased.push_back(randRESP);
verticesErased_.push_back(randRESP);
layout.vertexTypeMap_[randRESP] = vertexType::VTYPE_UNDEF;
}

Expand Down Expand Up @@ -370,16 +370,23 @@ string Connections911::ChangedEdge::toString()
return os.str();
}

/// Registers variable to be recorded
void Connections911::registerHistoryVariables()
{
Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
recorder.registerVariable("verticesDeleted", verticesErased_, Recorder::UpdatedType::DYNAMIC);
}

/// Returns the complete list of all deleted or added edges as a string.
string Connections911::changedEdgesToXML(bool added)
{
stringstream os;

vector<ChangedEdge> changed = edgesErased;
vector<ChangedEdge> changed = edgesErased_;
string name = "edgesDeleted";

if (added) {
changed = edgesAdded;
changed = edgesAdded_;
name = "edgesAdded";
}

Expand All @@ -394,22 +401,24 @@ string Connections911::changedEdgesToXML(bool added)
return os.str();
}

/*
/// Returns the complete list of deleted vertices as a string.
string Connections911::erasedVerticesToXML()
{
stringstream os;

os << "<Matrix name=\"verticesDeleted\" type=\"complete\" rows=\"1\" columns=\""
<< verticesErased.size() << "\" multiplier=\"1.0\">" << endl;
<< verticesErased_.size() << "\" multiplier=\"1.0\">" << endl;
os << " ";

sort(verticesErased.begin(), verticesErased.end());
for (int i = 0; i < verticesErased.size(); i++) {
os << verticesErased[i] << " ";
sort(verticesErased_.begin(), verticesErased_.end());
for (int i = 0; i < verticesErased_.size(); i++) {
os << verticesErased_[i] << " ";
}

os << endl << "</Matrix>";
return os.str();
}
*/

#endif
12 changes: 8 additions & 4 deletions Simulator/Connections/NG911/Connections911.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "Connections.h"
#include "InputEvent.h"
#include "RecordableVector.h"
#include <vector>

using namespace std;
Expand All @@ -33,7 +34,7 @@ class Connections911 : public Connections {
return new Connections911();
}
/// Records typeMap history for recorders
vector<vertexType> oldTypeMap_;
/// vector<vertexType> oldTypeMap_;

/// Setup the internal structure of the class (allocate memories and initialize them).
/// Initialize the network characterized by parameters:
Expand All @@ -48,6 +49,9 @@ class Connections911 : public Connections {
/// Registered to OperationManager as Operation::printParameters
virtual void printParameters() const override;

/// Registers history variables for recording during simulation
virtual void registerHistoryVariables() override;

private:
/// number of psaps to erase at the end of 1 epoch
int psapsToErase_;
Expand All @@ -58,13 +62,13 @@ class Connections911 : public Connections {
struct ChangedEdge;

// Edges that were added but later removed are still here
vector<ChangedEdge> edgesAdded;
vector<ChangedEdge> edgesAdded_;

// New edges = (old edges + edgesAdded) - edgesErased <-- works
// New edges = (old edges - edgesErased) + edgesAdded <-- does not work
vector<ChangedEdge> edgesErased;
vector<ChangedEdge> edgesErased_;

vector<int> verticesErased;
RecordableVector<int> verticesErased_;

#if !defined(USE_GPU)

Expand Down
4 changes: 4 additions & 0 deletions Simulator/Connections/Neuro/ConnGrowth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,7 @@ void ConnGrowth::printRadii() const
cout << "radii[" << i << "] = " << radii_[i] << endl;
}
}

void ConnGrowth::registerHistoryVariables()
{
}
3 changes: 3 additions & 0 deletions Simulator/Connections/Neuro/ConnGrowth.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class ConnGrowth : public Connections {
/// Registered to OperationManager as Operations::op::loadParameters
virtual void loadParameters() override;

/// Registers history variables for recording during simulation
virtual void registerHistoryVariables() override;

/// Prints out all parameters to logging file.
/// Registered to OperationManager as Operation::printParameters
virtual void printParameters() const override;
Expand Down
12 changes: 12 additions & 0 deletions Simulator/Connections/Neuro/ConnStatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ void ConnStatic::loadParameters()
void ConnStatic::printParameters() const
{
}

void ConnStatic::registerHistoryVariables()
{
// Register the following variables to be recorded
// Note: There may be potential duplicate weight, source, destination vertices
Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
recorder.registerVariable("weight", WCurrentEpoch_, Recorder::UpdatedType::DYNAMIC);
recorder.registerVariable("sourceVertex", sourceVertexIndexCurrentEpoch_,
Recorder::UpdatedType::DYNAMIC);
recorder.registerVariable("destinationVertex", destVertexIndexCurrentEpoch_,
Recorder::UpdatedType::DYNAMIC);
}
11 changes: 7 additions & 4 deletions Simulator/Connections/Neuro/ConnStatic.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class ConnStatic : public Connections {
/// Registered to OperationManager as Operation::printParameters
virtual void printParameters() const override;

/// Registers history variables for recording during simulation
virtual void registerHistoryVariables() override;

/// Get array of vertex weights
const vector<BGFLOAT> &getWCurrentEpoch() const
{
Expand All @@ -71,24 +74,24 @@ class ConnStatic : public Connections {
/// Get all edge source vertex indices
const vector<int> &getSourceVertexIndexCurrentEpoch() const
{
return sourceVertexIndexCurrentEpoch_;
return sourceVertexIndexCurrentEpoch_.getVector();
}

/// Get all edge destination vertex indices
const vector<int> &getDestVertexIndexCurrentEpoch() const
{
return destVertexIndexCurrentEpoch_;
return destVertexIndexCurrentEpoch_.getVector();
}

/// Cereal serialization method
template <class Archive> void serialize(Archive &archive);

private:
/// Indices of the source vertex for each edge
vector<int> sourceVertexIndexCurrentEpoch_;
RecordableVector<int> sourceVertexIndexCurrentEpoch_;

/// Indices of the destination vertex for each edge
vector<int> destVertexIndexCurrentEpoch_;
RecordableVector<int> destVertexIndexCurrentEpoch_;

/// The weight (scaling factor, strength, maximal amplitude) of each vertex for the current epoch.
// vector<BGFLOAT> changes to RecordableVector for recording purpose
Expand Down
1 change: 1 addition & 0 deletions Simulator/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ int Core::runSimulation(string executableName, string cmdLineArguments)

// Helper function for recorder to register spike history variables for all neurons.
simulator.getModel().getLayout().getVertices().registerHistoryVariables();
simulator.getModel().getConnections().registerHistoryVariables();

// Run simulation
LOG4CPLUS_TRACE(consoleLogger, "Starting Simulation");
Expand Down
14 changes: 7 additions & 7 deletions Simulator/Layouts/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ void Layout::setup()
// Finally take the square root to get the distances
dist_ = sqrt(dist2_);

// Register variable: vertex locations if need
//Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
//string baseName = "Location";
//string xLocation = "x_" + baseName;
//string yLocation = "y_" + baseName;
//recorder.registerVariable(xLocation, xloc_, Recorder::UpdatedType::CONSTANT);
//recorder.registerVariable(yLocation, yloc_, Recorder::UpdatedType::CONSTANT);
//Register variable: vertex locations
Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
string baseName = "Location";
string xLocation = "x_" + baseName;
string yLocation = "y_" + baseName;
recorder.registerVariable(xLocation, xloc_, Recorder::UpdatedType::CONSTANT);
recorder.registerVariable(yLocation, yloc_, Recorder::UpdatedType::CONSTANT);

// test purpose
// cout << "xloc_: " << &xloc_ << endl;
Expand Down
3 changes: 2 additions & 1 deletion Simulator/Layouts/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#pragma once

#include "AllVertices.h"
#include "RecordableVector.h"
#include "Utils/Global.h"
#include <iostream>
#include <log4cplus/loggingmacros.h>
Expand Down Expand Up @@ -78,7 +79,7 @@ class Layout {
vector<int>
probedNeuronList_; ///< Probed neurons list. // ToDo: Move this to Hdf5 recorder once its implemented in project -chris

vector<vertexType> vertexTypeMap_; ///< The vertex type mao, (INH, EXC).
RecordableVector<vertexType> vertexTypeMap_; ///< The vertex type mao, (INH, EXC).

vector<bool> starterMap_; ///< The starter existence map (T/F).

Expand Down
4 changes: 4 additions & 0 deletions Simulator/Layouts/NG911/Layout911.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ void Layout911::generateVertexTypeMap()
vTypeCount[gm[*vi].type] += 1;
}

// Register vertexTypes with recorder
Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
recorder.registerVariable("vertexTypeMap", vertexTypeMap_, Recorder::UpdatedType::CONSTANT);

LOG4CPLUS_DEBUG(fileLogger_, "\nVERTEX TYPE MAP"
<< endl
<< "\tTotal vertices: " << numVertices_ << endl
Expand Down
4 changes: 4 additions & 0 deletions Simulator/Layouts/Neuro/LayoutNeuro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ void LayoutNeuro::generateVertexTypeMap()
}
}

// Register vertexTypeMap to be recorded
Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
recorder.registerVariable("vertexTypeMap", vertexTypeMap_, Recorder::UpdatedType::CONSTANT);

numExcititoryNeurons = numVertices_ - numInhibitoryNeurons;

LOG4CPLUS_DEBUG(fileLogger_, "\nVERTEX TYPE MAP"
Expand Down
21 changes: 18 additions & 3 deletions Simulator/Recorders/Hdf5Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,32 @@ void Hdf5Recorder::compileHistories()
}
variableInfo.hdf5DataSet_.write(dataBuffer.data(), variableInfo.hdf5Datatype_,
memSpace, fileSpace);
} else if (variableInfo.hdf5Datatype_ == PredType::NATIVE_DOUBLE) {
vector<double> dataBuffer(variableInfo.variableLocation_.getNumElements());
for (size_t i = 0; i < variableInfo.variableLocation_.getNumElements(); ++i) {
dataBuffer[i] = get<double>(variableInfo.variableLocation_.getElement(i));
}
variableInfo.hdf5DataSet_.write(dataBuffer.data(), variableInfo.hdf5Datatype_,
memSpace, fileSpace);
} else if (variableInfo.hdf5Datatype_ == PredType::NATIVE_UCHAR) {
vector<unsigned char> dataBuffer(variableInfo.variableLocation_.getNumElements());
for (size_t i = 0; i < variableInfo.variableLocation_.getNumElements(); ++i) {
dataBuffer[i]
= get<unsigned char>(variableInfo.variableLocation_.getElement(i));
}
variableInfo.hdf5DataSet_.write(dataBuffer.data(), variableInfo.hdf5Datatype_,
memSpace, fileSpace);
} else {
// Throw an exception if the data type is unsupported
throw runtime_error("Unsupported data type for variable: "
+ variableInfo.variableName_);
}
}
}
// Call startNewEpoch() to prepare for new data input
// Only done for dynamic variables since constant variables are only captured at end
variableInfo.variableLocation_.startNewEpoch();
}

// Call startNewEpoch() to prepare for new data input
variableInfo.variableLocation_.startNewEpoch();
}
}

Expand Down
15 changes: 15 additions & 0 deletions Simulator/Recorders/Hdf5Recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class Hdf5Recorder : public Recorder {
hdf5Datatype_ = PredType::NATIVE_DOUBLE;
} else if (dataType_ == typeid(vertexType).name()) {
hdf5Datatype_ = PredType::NATIVE_INT;
} else if (dataType_ == typeid(unsigned char).name()) {
hdf5Datatype_ = PredType::NATIVE_UCHAR;
} else {
throw runtime_error("Unsupported data type");
}
Expand Down Expand Up @@ -163,6 +165,19 @@ class Hdf5Recorder : public Recorder {
}
hdf5DataSet_.write(dataBuffer.data(), hdf5Datatype_);

} else if (hdf5Datatype_ == PredType::NATIVE_DOUBLE) {
vector<double> dataBuffer(variableLocation_.getNumElements());
for (int i = 0; i < variableLocation_.getNumElements(); ++i) {
dataBuffer[i] = get<double>(variableLocation_.getElement(i));
}
hdf5DataSet_.write(dataBuffer.data(), hdf5Datatype_);

} else if (hdf5Datatype_ == PredType::NATIVE_UCHAR) {
vector<unsigned char> dataBuffer(variableLocation_.getNumElements());
for (int i = 0; i < variableLocation_.getNumElements(); ++i) {
dataBuffer[i] = get<unsigned char>(variableLocation_.getElement(i));
}
hdf5DataSet_.write(dataBuffer.data(), hdf5Datatype_);
} else {
// Throw an error if the data type is unsupported
throw runtime_error("Unsupported data type");
Expand Down
2 changes: 2 additions & 0 deletions Simulator/Recorders/NG911/Xml911Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void Xml911Recorder::compileHistories()
/// @param vertices the Vertex list to search from.
void Xml911Recorder::saveSimData()
{
/*
auto &conns = Simulator::getInstance().getModel().getConnections();
Connections911 &conns911 = dynamic_cast<Connections911 &>(conns);
All911Vertices &all911Vertices = dynamic_cast<All911Vertices &>(
Expand Down Expand Up @@ -104,6 +105,7 @@ void Xml911Recorder::saveSimData()
resultOut_ << " " << g_simulationStep * Simulator::getInstance().getDeltaT() << endl;
resultOut_ << "</Matrix>" << endl;
resultOut_ << "</SimState>" << endl;
*/
}

/// Prints out all parameters to logging file.
Expand Down
Loading