2323
2424#include < knp/framework/model.h>
2525#include < knp/framework/model_executor.h>
26+ #include < knp/framework/monitoring/model.h>
2627#include < knp/framework/monitoring/observer.h>
2728#include < knp/framework/network.h>
2829#include < knp/framework/sonata/network_io.h>
3435
3536#include " construct_network.h"
3637#include " data_read.h"
37- #include " logging .h"
38+ #include " time_string .h"
3839#include " wta.h"
3940
41+ constexpr size_t aggregated_spikes_logging_period = 4e3 ;
4042
4143namespace fs = std::filesystem;
4244
@@ -66,16 +68,15 @@ std::vector<knp::core::messaging::SpikeMessage> run_mnist_inference(
6668 auto &out_channel = model_executor.get_loader ().get_output_channel (o_channel_uid);
6769
6870 model_executor.get_backend ()->stop_learning ();
69- std::vector<InferenceResult> result;
7071
71- // Add observer.
72- model_executor.add_observer <knp::core::messaging::SpikeMessage>(
73- make_observer_function (result), described_network.data_ .output_uids_ );
72+ knp::framework::monitoring::model::add_status_logger (model_executor, model, std::cout, 1 );
73+
7474 std::ofstream log_stream;
75- // These two variables should have the same lifetime as model_executor, or else UB.
75+
76+ // This variable should have the same lifetime as model_executor, or else UB.
77+ // cppcheck-suppress variableScope
7678 std::map<std::string, size_t > spike_accumulator;
77- // cppcheck-suppress variableScope
78- size_t current_index = 0 ;
79+
7980 auto wta_uids = add_wta_handlers (described_network, model_executor);
8081 auto all_senders_names = described_network.data_ .population_names_ ;
8182 for (const auto &uid : wta_uids)
@@ -91,7 +92,8 @@ std::vector<knp::core::messaging::SpikeMessage> run_mnist_inference(
9192 }
9293 if (log_stream.is_open ())
9394 {
94- add_aggregate_logger (model, all_senders_names, model_executor, current_index, spike_accumulator, log_stream);
95+ knp::framework::monitoring::model::add_aggregated_spikes_logger (
96+ model, all_senders_names, model_executor, spike_accumulator, log_stream, aggregated_spikes_logging_period);
9597 }
9698
9799 // Start model.
0 commit comments