From 441982e6393be6cdc04b966bcfb74025fafaba0f Mon Sep 17 00:00:00 2001 From: Dhruva Vatsal Pyapali Date: Thu, 7 May 2026 11:35:56 -0700 Subject: [PATCH 1/9] Modernized Global.h for C++17 and split graph/matrix-specific definitions into dedicated utility headers. --- Simulator/Utils/Global.cpp | 21 +++--- Simulator/Utils/Global.h | 92 ++++++------------------- Simulator/Utils/GraphManager.h | 9 ++- Simulator/Utils/GraphProperties.h | 37 ++++++++++ Simulator/Utils/Matrix/MatrixDefaults.h | 5 ++ 5 files changed, 76 insertions(+), 88 deletions(-) create mode 100644 Simulator/Utils/GraphProperties.h create mode 100644 Simulator/Utils/Matrix/MatrixDefaults.h diff --git a/Simulator/Utils/Global.cpp b/Simulator/Utils/Global.cpp index 8b6b0db96..b9ac00faa 100644 --- a/Simulator/Utils/Global.cpp +++ b/Simulator/Utils/Global.cpp @@ -6,7 +6,6 @@ * @brief Globally available functions/variables and default parameter values. */ #include "Global.h" -#include "MTRand.h" #include "Norm.h" // Debugging log data and routines @@ -23,9 +22,9 @@ int g_debug_mask /// @param width width of the two-dimensional array /// @param height height of the two-dimensional array /// @return string with the converted indexes and square brackets surrounding them. -string index2dToString(int i, int width, int height) +std::string index2dToString(int i, int width, int height) { - stringstream ss; + std::stringstream ss; ss << "[" << i % width << "][" << i / height << "]"; return ss.str(); } @@ -34,9 +33,9 @@ string index2dToString(int i, int width, int height) /// @param x x coordinate. /// @param y y coordinate. /// @return returns the given coordinates surrounded by square brackets. -string coordToString(int x, int y) +std::string coordToString(int x, int y) { - stringstream ss; + std::stringstream ss; ss << "[" << x << "][" << y << "]"; return ss.str(); } @@ -46,9 +45,9 @@ string coordToString(int x, int y) /// @param y y coordinate. /// @param z z coordinate. /// @return returns the given coordinates surrounded by square brackets. -string coordToString(int x, int y, int z) +std::string coordToString(int x, int y, int z) { - stringstream ss; + std::stringstream ss; ss << "[" << x << "][" << y << "][" << z << "]"; return ss.str(); } @@ -62,10 +61,10 @@ int g_deviceId = 0; MTRand initRNG; // A normalized random number generator. -unique_ptr noiseRNG; +std::unique_ptr noiseRNG; // simulation vars -uint64_t g_simulationStep = 0; +std::uint64_t g_simulationStep = 0; //const BGFLOAT g_synapseStrengthAdjustmentConstant = 1.0e-8; @@ -116,7 +115,3 @@ void printPerformanceMetrics(const float total_time, int steps) } #endif // PERFORMANCE_METRICS -// TODO comment -const string MATRIX_TYPE = "complete"; -// TODO comment -const string MATRIX_INIT = "const"; diff --git a/Simulator/Utils/Global.h b/Simulator/Utils/Global.h index c4d48d800..b15ba311c 100644 --- a/Simulator/Utils/Global.h +++ b/Simulator/Utils/Global.h @@ -53,22 +53,20 @@ extern int g_debug_mask; #include +#include #include +#include #include -#ifdef _WIN32 //needs to be before #include "bgtypes.h" or the #define BGFLOAT will cause problems - #include //warning! windows.h also defines BGFLOAT -using uint64_t = unsigned long long int; //included in inttypes.h, which is not available in WIN32 -#else - #include //used for uint64_t, unavailable in WIN32 -#endif +#include +#include #include "BGTypes.h" +#include "GraphProperties.h" +#include "Matrix/MatrixDefaults.h" //#include "Norm.h" #include "Coordinate.h" #include "VectorMatrix.h" #include "VertexType.h" -using namespace std; - // If defined, a table with time and each neuron voltage will output to stdout. //#define DUMP_VOLTAGES @@ -84,12 +82,12 @@ extern const BGFLOAT pi; extern MTRand initRNG; // A normalized random number generator. -extern unique_ptr noiseRNG; +extern std::unique_ptr noiseRNG; // The current simulation step. -extern uint64_t g_simulationStep; +extern std::uint64_t g_simulationStep; -const int g_nMaxChunkSize = 100; +inline constexpr int g_nMaxChunkSize = 100; // Edge types. // NEURO: @@ -127,27 +125,27 @@ inline std::ostream &operator<<(std::ostream &os, edgeType eT) } // The default time step size. -#define DEFAULT_dt (1e-4) // MODEL INDEPENDENT +inline constexpr double DEFAULT_dt = 1e-4; // MODEL INDEPENDENT // } NMV-END // Converts a 1-d index into a coordinate string. -string index2dToString(int i, int width, int height); +std::string index2dToString(int i, int width, int height); // Converts a 2-d coordinate into a string. -string coordToString(int x, int y); +std::string coordToString(int x, int y); // Converts a 3-d coordinate into a string. -string coordToString(int x, int y, int z); +std::string coordToString(int x, int y, int z); -template ostream &operator<<(ostream &os, const vector &v) +template std::ostream &operator<<(std::ostream &os, const std::vector &v) { - for (T element : v) { + for (const auto &element : v) { os << element << " "; } return os; } -template string vectorToXML(const vector &v, const string &name) +template std::string vectorToXML(const std::vector &v, const std::string &name) { - stringstream ss; + std::stringstream ss; ss << " \n"; ss << " " << v << "\n"; ss << " "; @@ -155,11 +153,11 @@ template string vectorToXML(const vector &v, const string &name) } template -string vector2dToXML(const vector &v, const string &name, const string &rowName) +std::string vector2dToXML(const std::vector &v, const std::string &name, const std::string &rowName) { - stringstream ss; + std::stringstream ss; ss << " \n"; - for (int i = 0; i < v.size(); ++i) { + for (size_t i = 0; i < v.size(); ++i) { if (v[i].empty()) { continue; } // No log to print @@ -187,53 +185,3 @@ extern double t_gpu_calcSummation; void printPerformanceMetrics(const float total_time, int steps); #endif // PERFORMANCE_METRICS -// TODO comment -extern const string MATRIX_TYPE; -// TODO comment -extern const string MATRIX_INIT; - -/*****************************************************************************/ -/* Structures to hold the GraphML properties */ -/*****************************************************************************/ -// We are using the Boost Graph Library (BGL) to load the simulator's initial -// graph. BGL needs to associate the GraphML properties, we do that by -// registering them before loading the graph. -// The following structures are used to register those properties with the -// GraphManager class, which is just a wrapper around BGL. The corresponding -// classes (Layout, Connections, etc) need to do this before we can load the -// graph. - -/// @brief Parent structure to store common properties for all graph vertices -struct VertexProperties { - string type; - double x; - double y; -}; - -/// @brief Derived structure for NG911-specific properties -/// Inherits from VertexProperty and includes attributes specific to 911 networks -struct NG911VertexProperties : public VertexProperties { - string objectID; - string name; - int servers = 0; - int trunks = 0; - string segments; -}; - -/// @brief Derived structure for Neural Network-specific properties -struct NeuralVertexProperties : public VertexProperties { - bool active; -}; - -/// @brief The structure to hold the edge properties -struct NeuralEdgeProperties { - int source; - int target; - double weight; -}; - - -/// @brief The structure to hold the Graph properties -struct GraphProperties { - // TODO: Graph Properties -}; diff --git a/Simulator/Utils/GraphManager.h b/Simulator/Utils/GraphManager.h index 6430d87ef..67fc40183 100644 --- a/Simulator/Utils/GraphManager.h +++ b/Simulator/Utils/GraphManager.h @@ -30,8 +30,8 @@ * - The entire GraphManager class is included in the header file to ensure that * the templated class can be compiled without requiring separate declarations. * - * The structures for `VertexProperties`, `EdgeProperties`, and `GraphProperties` - * are declared in `Global.h`. + * The structures for `VertexProperties`, `EdgeProperties`, and `GraphProperties` + * are declared in `GraphProperties.h`. * * This class follows the Singleton design pattern, ensuring a single instance * is used throughout the simulation for consistent graph management. @@ -39,10 +39,13 @@ #pragma once -#include "Global.h" +#include "GraphProperties.h" #include "ParameterManager.h" #include #include +#include +#include +#include #include #include diff --git a/Simulator/Utils/GraphProperties.h b/Simulator/Utils/GraphProperties.h new file mode 100644 index 000000000..77a61a277 --- /dev/null +++ b/Simulator/Utils/GraphProperties.h @@ -0,0 +1,37 @@ +#pragma once + +#include + +/// @brief Parent structure to store common properties for all graph vertices +struct VertexProperties { + std::string type; + double x; + double y; +}; + +/// @brief Derived structure for NG911-specific properties +/// Inherits from VertexProperty and includes attributes specific to 911 networks +struct NG911VertexProperties : public VertexProperties { + std::string objectID; + std::string name; + int servers = 0; + int trunks = 0; + std::string segments; +}; + +/// @brief Derived structure for Neural Network-specific properties +struct NeuralVertexProperties : public VertexProperties { + bool active; +}; + +/// @brief The structure to hold the edge properties +struct NeuralEdgeProperties { + int source; + int target; + double weight; +}; + +/// @brief The structure to hold the Graph properties +struct GraphProperties { + // TODO: Graph Properties +}; diff --git a/Simulator/Utils/Matrix/MatrixDefaults.h b/Simulator/Utils/Matrix/MatrixDefaults.h new file mode 100644 index 000000000..d612cbda3 --- /dev/null +++ b/Simulator/Utils/Matrix/MatrixDefaults.h @@ -0,0 +1,5 @@ +#pragma once + +// Default matrix implementation and initialization mode used across simulator modules. +inline constexpr const char MATRIX_TYPE[] = "complete"; +inline constexpr const char MATRIX_INIT[] = "const"; From b8e8941750c8cb0684c26de3cbcdc31d064e335a Mon Sep 17 00:00:00 2001 From: Dhruva Vatsal Pyapali Date: Thu, 7 May 2026 11:53:56 -0700 Subject: [PATCH 2/9] Fixed Clang issues --- Simulator/Utils/Global.cpp | 2 +- Simulator/Utils/Global.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Simulator/Utils/Global.cpp b/Simulator/Utils/Global.cpp index b9ac00faa..cde426a0f 100644 --- a/Simulator/Utils/Global.cpp +++ b/Simulator/Utils/Global.cpp @@ -113,5 +113,5 @@ void printPerformanceMetrics(const float total_time, int steps) cout << "t_gpu_advanceSynapses: " << t_gpu_advanceSynapses / steps << " ms/epoch" << endl; cout << "t_gpu_calcSummation: " << t_gpu_calcSummation / steps << " ms/epoch" << endl; } -#endif // PERFORMANCE_METRICS +#endif // PERFORMANCE_METRICS diff --git a/Simulator/Utils/Global.h b/Simulator/Utils/Global.h index b15ba311c..8177dfd99 100644 --- a/Simulator/Utils/Global.h +++ b/Simulator/Utils/Global.h @@ -73,7 +73,7 @@ extern int g_debug_mask; #if defined(USE_GPU) //! CUDA device ID extern int g_deviceId; -#endif // USE_GPU +#endif // USE_GPU // The constant PI. extern const BGFLOAT pi; @@ -153,7 +153,8 @@ template std::string vectorToXML(const std::vector &v, const std } template -std::string vector2dToXML(const std::vector &v, const std::string &name, const std::string &rowName) +std::string vector2dToXML(const std::vector &v, const std::string &name, + const std::string &rowName) { std::stringstream ss; ss << " \n"; @@ -183,5 +184,5 @@ extern double t_gpu_advanceSynapses; extern double t_gpu_calcSummation; void printPerformanceMetrics(const float total_time, int steps); -#endif // PERFORMANCE_METRICS +#endif // PERFORMANCE_METRICS From 557deaac3e18f1bdf2fa259c5c8e3031a2e0dde4 Mon Sep 17 00:00:00 2001 From: Dhruva Vatsal Pyapali Date: Thu, 7 May 2026 11:57:51 -0700 Subject: [PATCH 3/9] Fixed Clang issues pt 2 --- Simulator/Utils/Global.cpp | 3 +-- Simulator/Utils/Global.h | 13 ++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Simulator/Utils/Global.cpp b/Simulator/Utils/Global.cpp index cde426a0f..396d7273d 100644 --- a/Simulator/Utils/Global.cpp +++ b/Simulator/Utils/Global.cpp @@ -113,5 +113,4 @@ void printPerformanceMetrics(const float total_time, int steps) cout << "t_gpu_advanceSynapses: " << t_gpu_advanceSynapses / steps << " ms/epoch" << endl; cout << "t_gpu_calcSummation: " << t_gpu_calcSummation / steps << " ms/epoch" << endl; } -#endif // PERFORMANCE_METRICS - +#endif // PERFORMANCE_METRICS diff --git a/Simulator/Utils/Global.h b/Simulator/Utils/Global.h index 8177dfd99..604b9c3e8 100644 --- a/Simulator/Utils/Global.h +++ b/Simulator/Utils/Global.h @@ -52,6 +52,9 @@ extern int g_debug_mask; +#include "BGTypes.h" +#include "GraphProperties.h" +#include "Matrix/MatrixDefaults.h" #include #include #include @@ -59,10 +62,7 @@ extern int g_debug_mask; #include #include #include -#include "BGTypes.h" -#include "GraphProperties.h" -#include "Matrix/MatrixDefaults.h" - //#include "Norm.h" +//#include "Norm.h" #include "Coordinate.h" #include "VectorMatrix.h" #include "VertexType.h" @@ -73,7 +73,7 @@ extern int g_debug_mask; #if defined(USE_GPU) //! CUDA device ID extern int g_deviceId; -#endif // USE_GPU +#endif // USE_GPU // The constant PI. extern const BGFLOAT pi; @@ -184,5 +184,4 @@ extern double t_gpu_advanceSynapses; extern double t_gpu_calcSummation; void printPerformanceMetrics(const float total_time, int steps); -#endif // PERFORMANCE_METRICS - +#endif // PERFORMANCE_METRICS From ea602e5530fb12167950f44a7e3a262fb2f18151 Mon Sep 17 00:00:00 2001 From: CodersRepo <148278464+CodersRepo@users.noreply.github.com> Date: Thu, 7 May 2026 12:17:09 -0700 Subject: [PATCH 4/9] VertexProperties defaults init Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- Simulator/Utils/GraphProperties.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Simulator/Utils/GraphProperties.h b/Simulator/Utils/GraphProperties.h index 77a61a277..2b7830341 100644 --- a/Simulator/Utils/GraphProperties.h +++ b/Simulator/Utils/GraphProperties.h @@ -5,8 +5,8 @@ /// @brief Parent structure to store common properties for all graph vertices struct VertexProperties { std::string type; - double x; - double y; + double x = 0.0; + double y = 0.0; }; /// @brief Derived structure for NG911-specific properties From 58e047367038fd30aef6fa8ac51ea961d498c950 Mon Sep 17 00:00:00 2001 From: CodersRepo <148278464+CodersRepo@users.noreply.github.com> Date: Thu, 7 May 2026 12:18:08 -0700 Subject: [PATCH 5/9] NeuralVertexProperties active init Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- Simulator/Utils/GraphProperties.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Simulator/Utils/GraphProperties.h b/Simulator/Utils/GraphProperties.h index 2b7830341..56dac8295 100644 --- a/Simulator/Utils/GraphProperties.h +++ b/Simulator/Utils/GraphProperties.h @@ -21,7 +21,7 @@ struct NG911VertexProperties : public VertexProperties { /// @brief Derived structure for Neural Network-specific properties struct NeuralVertexProperties : public VertexProperties { - bool active; + bool active = false; }; /// @brief The structure to hold the edge properties From 602cbd1e00d2782fbc6530d2a1cccb511b6e99fc Mon Sep 17 00:00:00 2001 From: CodersRepo <148278464+CodersRepo@users.noreply.github.com> Date: Thu, 7 May 2026 12:19:20 -0700 Subject: [PATCH 6/9] NeuralEdgeProperties attributes default init Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- Simulator/Utils/GraphProperties.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Simulator/Utils/GraphProperties.h b/Simulator/Utils/GraphProperties.h index 56dac8295..861f245b9 100644 --- a/Simulator/Utils/GraphProperties.h +++ b/Simulator/Utils/GraphProperties.h @@ -26,9 +26,9 @@ struct NeuralVertexProperties : public VertexProperties { /// @brief The structure to hold the edge properties struct NeuralEdgeProperties { - int source; - int target; - double weight; + int source = 0; + int target = 0; + double weight = 0.0; }; /// @brief The structure to hold the Graph properties From 409172ec4f372e83cdfec57c25c8f548eebbd2ce Mon Sep 17 00:00:00 2001 From: CodersRepo <148278464+CodersRepo@users.noreply.github.com> Date: Thu, 7 May 2026 12:21:10 -0700 Subject: [PATCH 7/9] Comments update Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- Simulator/Utils/GraphManager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Simulator/Utils/GraphManager.h b/Simulator/Utils/GraphManager.h index 67fc40183..09e6f1399 100644 --- a/Simulator/Utils/GraphManager.h +++ b/Simulator/Utils/GraphManager.h @@ -30,8 +30,8 @@ * - The entire GraphManager class is included in the header file to ensure that * the templated class can be compiled without requiring separate declarations. * - * The structures for `VertexProperties`, `EdgeProperties`, and `GraphProperties` - * are declared in `GraphProperties.h`. + * The structures for `VertexProperties`, `NeuralEdgeProperties`, and + * `GraphProperties` are declared in `GraphProperties.h`. * * This class follows the Singleton design pattern, ensuring a single instance * is used throughout the simulation for consistent graph management. From c1b4d562066dd3498479f15b08245a7d562483ce Mon Sep 17 00:00:00 2001 From: Dhruva Vatsal Pyapali Date: Tue, 12 May 2026 16:57:38 -0700 Subject: [PATCH 8/9] Removed Inline --- Simulator/Utils/Global.h | 6 +++--- Simulator/Utils/Matrix/MatrixDefaults.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Simulator/Utils/Global.h b/Simulator/Utils/Global.h index 604b9c3e8..a5b7c912f 100644 --- a/Simulator/Utils/Global.h +++ b/Simulator/Utils/Global.h @@ -87,7 +87,7 @@ extern std::unique_ptr noiseRNG; // The current simulation step. extern std::uint64_t g_simulationStep; -inline constexpr int g_nMaxChunkSize = 100; +constexpr int g_nMaxChunkSize = 100; // Edge types. // NEURO: @@ -118,14 +118,14 @@ enum class edgeType { ETYPE_UNDEF = -1 }; // Custom streaming operator<< for the enum class edgeType -inline std::ostream &operator<<(std::ostream &os, edgeType eT) +std::ostream &operator<<(std::ostream &os, edgeType eT) { os << static_cast(eT); return os; } // The default time step size. -inline constexpr double DEFAULT_dt = 1e-4; // MODEL INDEPENDENT +constexpr double DEFAULT_dt = 1e-4; // MODEL INDEPENDENT // } NMV-END // Converts a 1-d index into a coordinate string. diff --git a/Simulator/Utils/Matrix/MatrixDefaults.h b/Simulator/Utils/Matrix/MatrixDefaults.h index d612cbda3..488ddb995 100644 --- a/Simulator/Utils/Matrix/MatrixDefaults.h +++ b/Simulator/Utils/Matrix/MatrixDefaults.h @@ -1,5 +1,5 @@ #pragma once // Default matrix implementation and initialization mode used across simulator modules. -inline constexpr const char MATRIX_TYPE[] = "complete"; -inline constexpr const char MATRIX_INIT[] = "const"; +const char MATRIX_TYPE[] = "complete"; +const char MATRIX_INIT[] = "const"; From 95235b59b7f318f72448345b56384b198937e94f Mon Sep 17 00:00:00 2001 From: Dhruva Vatsal Pyapali Date: Tue, 12 May 2026 17:04:52 -0700 Subject: [PATCH 9/9] Fixed Global.h ostream --- Simulator/Utils/Global.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Simulator/Utils/Global.h b/Simulator/Utils/Global.h index a5b7c912f..aea869965 100644 --- a/Simulator/Utils/Global.h +++ b/Simulator/Utils/Global.h @@ -118,7 +118,7 @@ enum class edgeType { ETYPE_UNDEF = -1 }; // Custom streaming operator<< for the enum class edgeType -std::ostream &operator<<(std::ostream &os, edgeType eT) +inline std::ostream &operator<<(std::ostream &os, edgeType eT) { os << static_cast(eT); return os;