Skip to content

Commit 4dbfb86

Browse files
committed
resolve some problem like: eliminate unnecessary parameters, put more message and explanation
1 parent dbc404b commit 4dbfb86

File tree

10 files changed

+34
-36
lines changed

10 files changed

+34
-36
lines changed

Simulator/Core/Model.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Model::Model()
6767
void Model::saveResults()
6868
{
6969
if (recorder_ != nullptr) {
70-
recorder_->saveSimData(layout_->getVertices());
70+
recorder_->saveSimData();
7171
}
7272
}
7373

@@ -146,7 +146,7 @@ void Model::updateHistory()
146146
LOG4CPLUS_INFO(fileLogger_, "ERROR: Recorder class is null.");
147147
}
148148
if (recorder_ != nullptr) {
149-
recorder_->compileHistories(layout_->getVertices());
149+
recorder_->compileHistories();
150150
}
151151
}
152152

Simulator/Recorders/Hdf5Recorder.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void Hdf5Recorder::term()
104104
}
105105

106106
// create the dataset for constant variable and store the data to dataset
107-
void Hdf5Recorder::saveSimData(const AllVertices &neurons)
107+
void Hdf5Recorder::saveSimData()
108108
{
109109
// Initialize datasets for constant variables
110110
for (auto &variableInfo : variableTable_) {
@@ -124,9 +124,11 @@ void Hdf5Recorder::saveSimData(const AllVertices &neurons)
124124
}
125125

126126
// Processes and updates HDF5 datasets for variables marked as DYNAMIC
127-
void Hdf5Recorder::compileHistories(AllVertices &vertices)
127+
void Hdf5Recorder::compileHistories()
128128
{
129129
// Define the maximum chunk size for datasets to optimize storage and access
130+
// This defines the maximum number of elements per chunk
131+
// If the dataset size exceeds this value, HDF5 will create multiple chunks to store the data
130132
const hsize_t max_chunk_size = 1024;
131133

132134
// Iterate over each variableInfo object in the variable table
@@ -178,29 +180,30 @@ void Hdf5Recorder::compileHistories(AllVertices &vertices)
178180

179181
// Prepare the data buffer and write the new data to the dataset
180182
if (variableInfo.hdf5Datatype_ == PredType::NATIVE_FLOAT) {
181-
std::vector<float> dataBuffer(variableInfo.variableLocation_.getNumElements());
183+
vector<float> dataBuffer(variableInfo.variableLocation_.getNumElements());
182184
for (size_t i = 0; i < variableInfo.variableLocation_.getNumElements(); ++i) {
183185
dataBuffer[i] = get<float>(variableInfo.variableLocation_.getElement(i));
184186
}
185187
variableInfo.hdf5DataSet_.write(dataBuffer.data(), variableInfo.hdf5Datatype_,
186188
memSpace, fileSpace);
187189
} else if (variableInfo.hdf5Datatype_ == PredType::NATIVE_INT) {
188-
std::vector<int> dataBuffer(variableInfo.variableLocation_.getNumElements());
190+
vector<int> dataBuffer(variableInfo.variableLocation_.getNumElements());
189191
for (size_t i = 0; i < variableInfo.variableLocation_.getNumElements(); ++i) {
190192
dataBuffer[i] = get<int>(variableInfo.variableLocation_.getElement(i));
191193
}
192194
variableInfo.hdf5DataSet_.write(dataBuffer.data(), variableInfo.hdf5Datatype_,
193195
memSpace, fileSpace);
194196
} else if (variableInfo.hdf5Datatype_ == PredType::NATIVE_UINT64) {
195-
std::vector<uint64_t> dataBuffer(variableInfo.variableLocation_.getNumElements());
197+
vector<uint64_t> dataBuffer(variableInfo.variableLocation_.getNumElements());
196198
for (size_t i = 0; i < variableInfo.variableLocation_.getNumElements(); ++i) {
197199
dataBuffer[i] = get<uint64_t>(variableInfo.variableLocation_.getElement(i));
198200
}
199201
variableInfo.hdf5DataSet_.write(dataBuffer.data(), variableInfo.hdf5Datatype_,
200202
memSpace, fileSpace);
201203
} else {
202204
// Throw an exception if the data type is unsupported
203-
throw std::runtime_error("Unsupported data type");
205+
throw runtime_error("Unsupported data type for variable: "
206+
+ variableInfo.variableName_);
204207
}
205208
}
206209
}

Simulator/Recorders/Hdf5Recorder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ class Hdf5Recorder : public Recorder {
5858
/// Terminate process
5959
virtual void term() override;
6060

61-
// TODO: No parameters needed (AllVertices &vertices)
61+
6262
/// Compile/capture variable history information in every epoch
63-
virtual void compileHistories(AllVertices &neurons) override;
63+
virtual void compileHistories() override;
6464

65-
// TODO: No parameters needed (AllVertices &vertices)
65+
6666
/// Writes simulation results to an output destination.
67-
virtual void saveSimData(const AllVertices &neurons) override;
67+
virtual void saveSimData() override;
6868

6969
/// Prints out all parameters to logging file.
7070
/// Registered to OperationManager as Operation::printParameters

Simulator/Recorders/NG911/Xml911Recorder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ void Xml911Recorder::getValues()
3333
/// Compile history information in every epoch
3434
///
3535
/// @param[in] vertices The entire list of vertices.
36-
void Xml911Recorder::compileHistories(AllVertices &vertices)
36+
void Xml911Recorder::compileHistories()
3737
{
3838
}
3939

4040
/// Writes simulation results to an output destination.
4141
///
4242
/// @param vertices the Vertex list to search from.
43-
void Xml911Recorder::saveSimData(const AllVertices &vertices)
43+
void Xml911Recorder::saveSimData()
4444
{
4545
auto &conns = Simulator::getInstance().getModel().getConnections();
4646
Connections911 &conns911 = dynamic_cast<Connections911 &>(conns);

Simulator/Recorders/NG911/Xml911Recorder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class Xml911Recorder : public XmlRecorder {
4040
/// Compile history information in every epoch
4141
///
4242
/// @param[in] vertices The entire list of vertices.
43-
virtual void compileHistories(AllVertices &vertices) override;
43+
virtual void compileHistories() override;
4444

4545
/// Writes simulation results to an output destination.
4646
///
4747
/// @param vertices the Vertex list to search from.
48-
virtual void saveSimData(const AllVertices &vertices) override;
48+
virtual void saveSimData() override;
4949

5050
/// Prints out all parameters to logging file.
5151
/// Registered to OperationManager as Operation::printParameters

Simulator/Recorders/Recorder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class Recorder {
5252
/// Terminate process
5353
virtual void term() = 0;
5454

55-
// TODO: No parameters needed (AllVertices &vertices)
55+
5656
/// Compile/capture variable history information in every epoch
57-
virtual void compileHistories(AllVertices &vertices) = 0;
57+
virtual void compileHistories() = 0;
5858

59-
// TODO: No parameters needed (AllVertices &vertices)
59+
6060
/// Writes simulation results to an output destination.
61-
virtual void saveSimData(const AllVertices &vertices) = 0;
61+
virtual void saveSimData() = 0;
6262

6363
/// Prints loaded parameters to logging file.
6464
virtual void printParameters() = 0;

Simulator/Recorders/XmlRecorder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void XmlRecorder::term()
7373

7474
// TODO : @param[in] vertices will be removed eventually after HDF5Recorder implementing
7575
/// Compile history information in every epoch
76-
void XmlRecorder::compileHistories(AllVertices &vertices)
76+
void XmlRecorder::compileHistories()
7777
{
7878
//capture data information in each epoch
7979
for (int rowIndex = 0; rowIndex < variableTable_.size(); rowIndex++) {
@@ -86,7 +86,7 @@ void XmlRecorder::compileHistories(AllVertices &vertices)
8686

8787
// TODO : @param[in] vertices will be removed eventually after HDF5Recorder implementing
8888
/// Writes simulation results to an output destination.
89-
void XmlRecorder::saveSimData(const AllVertices &vertices)
89+
void XmlRecorder::saveSimData()
9090
{
9191
// Write XML header information:
9292
string header = "<?xml version=\"1.0\" standalone=\"no\"?>\n";

Simulator/Recorders/XmlRecorder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ class XmlRecorder : public Recorder {
6060
/// Terminate process
6161
virtual void term() override;
6262

63-
// TODO: No parameters needed (AllVertices &vertices)
63+
6464
/// Compile/capture variable history information in every epoch
65-
virtual void compileHistories(AllVertices &vertices) override;
65+
virtual void compileHistories() override;
6666

67-
// TODO: No parameters needed (AllVertices &vertices)
67+
6868
/// Writes simulation results to an output destination.
69-
virtual void saveSimData(const AllVertices &vertices) override;
69+
virtual void saveSimData() override;
7070

7171
/// Prints out all parameters to logging file.
7272
/// Registered to OperationManager as Operation::printParameters

Testing/UnitTesting/Hdf5RecorderTests.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,8 @@ TEST(Hdf5RecorderTest, SaveSimDataTest)
8686
// Register the variable with Hdf5Recorder
8787
recorder.registerVariable("test_var1", eventBuffer, Recorder::UpdatedType::CONSTANT);
8888

89-
// Create a unique_ptr to an empty AllVertices object
90-
unique_ptr<AllVertices> vertices = 0;
91-
9289
// Call saveSimData() to write the data to the file
93-
recorder.saveSimData(*vertices);
90+
recorder.saveSimData();
9491

9592
// Open the HDF5 file and read back the data
9693
H5File file(outputFile, H5F_ACC_RDONLY);
@@ -129,8 +126,6 @@ TEST(Hdf5RecorderTest, CompileHistoriesTest)
129126
// Register the variable with Hdf5Recorder as DYNAMIC
130127
recorder.registerVariable("test_var_int", eventBufferInt, Recorder::UpdatedType::DYNAMIC);
131128

132-
// Create a unique_ptr to an empty AllVertices object
133-
unique_ptr<AllVertices> vertices = 0;
134129

135130
// Call compileHistories() multiple times to simulate multiple epochs
136131
for (int epoch = 0; epoch < 3; ++epoch) {
@@ -142,7 +137,7 @@ TEST(Hdf5RecorderTest, CompileHistoriesTest)
142137
eventBufferInt.insertEvent(4 * (epoch + 1));
143138
eventBufferInt.insertEvent(5 * (epoch + 1));
144139

145-
recorder.compileHistories(*vertices);
140+
recorder.compileHistories();
146141
}
147142

148143
// Open the HDF5 file and read back the data

Testing/UnitTesting/XmlRecorderTests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ TEST(XmlRecorderTest, CompileHistoriesTest)
146146
buffer0.insertEvent(2);
147147

148148
// Call the compileHistories method
149-
recorderTest_->compileHistories(*vertices.get());
149+
recorderTest_->compileHistories();
150150
vector<std::variant<uint64_t, bool, int, BGFLOAT>> history = recorderTest_->getHistory(0);
151151

152152
// Verify the events compiled hisotry
@@ -214,9 +214,9 @@ TEST(XmlRecorderTest, SaveSimDataTest)
214214
buffer.insertEvent(3);
215215

216216
// Call the compileHistories method
217-
recorderTest_->compileHistories(*vertices.get());
217+
recorderTest_->compileHistories();
218218
// Call the saveSimData() function
219-
recorderTest_->saveSimData(*vertices.get());
219+
recorderTest_->saveSimData();
220220

221221
// Open the test_output.xml file and read its content
222222
std::ifstream inputFile("../Testing/UnitTesting/TestOutput/test_output.xml");

0 commit comments

Comments
 (0)