Commit 61274ee0 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: remove time step for observers

parent 90ed4b96
......@@ -2747,7 +2747,7 @@ editor::show_editor() noexcept
plot = &tf;
out.plot_id = plot_outs.get_id(tf);
auto& o =
sim.observers.alloc(0.01, names[i].c_str(), tf);
sim.observers.alloc(names[i].c_str(), tf);
sim.observe(*mdl, o);
}
......@@ -2765,7 +2765,7 @@ editor::show_editor() noexcept
file = &tf;
out.file_id = file_outs.get_id(tf);
auto& o =
sim.observers.alloc(0.01, names[i].c_str(), tf);
sim.observers.alloc(names[i].c_str(), tf);
sim.observe(*mdl, o);
}
ImGui::InputText(
......
......@@ -238,6 +238,7 @@ struct plot_output
std::vector<float> ys;
small_string<24u> name;
double tl = 0.0;
double time_step = 0.1;
float min = -1.f;
float max = +1.f;
};
......
......@@ -47,7 +47,7 @@ plot_output::operator()(const irt::observer& obs,
min = std::min(min, value);
max = std::max(max, value);
for (auto to_fill = tl; to_fill < t; to_fill += obs.time_step) {
for (auto to_fill = tl; to_fill < t; to_fill += time_step) {
ys.emplace_back(value);
xs.emplace_back(static_cast<float>(t));
}
......
......@@ -147,7 +147,7 @@ lif_benchmark(double simulation_duration, double quantum)
file_output fo_a(file_name.c_str());
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(
sim.qss2_integrator_models.get(neuron_model.integrator).id),
obs_a);
......@@ -311,7 +311,7 @@ izhikevich_benchmark(double simulation_duration,
file_output fo_a(file_name.c_str());
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
file_name = "output_izhikevitch_aqss_b_sd_" +
std::to_string(simulation_duration) + "_q_" +
std::to_string(quantum) + "_a_" + std::to_string(a) + "_b_" +
......@@ -319,7 +319,7 @@ izhikevich_benchmark(double simulation_duration,
std::to_string(d) + ".csv";
file_output fo_b(file_name.c_str());
expect(fo_b.os != nullptr);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......
......@@ -137,7 +137,7 @@ lif_benchmark(double simulation_duration, double quantum)
file_output fo_a(file_name.c_str());
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.1, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(
sim.qss1_integrator_models.get(neuron_model.integrator).id),
obs_a);
......@@ -255,7 +255,7 @@ izhikevich_benchmark(double simulation_duration,
file_output fo_a(file_name.c_str());
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
file_name = "output_izhikevitch_qss1_b_sd_" +
std::to_string(simulation_duration) + "_q_" +
......@@ -264,7 +264,7 @@ izhikevich_benchmark(double simulation_duration,
std::to_string(d) + ".csv";
file_output fo_b(file_name.c_str());
expect(fo_b.os != nullptr);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......
......@@ -136,7 +136,7 @@ lif_benchmark(double simulation_duration, double quantum)
file_output fo_a(file_name.c_str());
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(
sim.qss2_integrator_models.get(neuron_model.integrator).id),
......@@ -255,7 +255,7 @@ izhikevich_benchmark(double simulation_duration,
file_output fo_a(file_name.c_str());
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
file_name = "output_izhikevitch_qss2_b_sd_" +
std::to_string(simulation_duration) + "_q_" +
std::to_string(quantum) + "_a_" + std::to_string(a) + "_b_" +
......@@ -263,7 +263,7 @@ izhikevich_benchmark(double simulation_duration,
std::to_string(d) + ".csv";
file_output fo_b(file_name.c_str());
expect(fo_b.os != nullptr);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......
This diff is collapsed.
......@@ -2465,17 +2465,13 @@ struct observer
using update_fn =
function_ref<void(const observer&, const time, const observer::status)>;
observer() noexcept = default;
observer(const time time_step_, const char* name_, update_fn cb_)
observer(const char* name_, update_fn cb_) noexcept
: cb(cb_)
, time_step(std::clamp(time_step_, 0.0, time_domain<time>::infinity))
, name(name_)
{}
update_fn cb;
double tl = 0.0;
double time_step = 0.0;
small_string<8> name;
model_id model = static_cast<model_id>(0);
message msg;
......@@ -6573,14 +6569,10 @@ public:
if constexpr (is_detected_v<observation_function_t, Dynamics>) {
if (mdl.obs_id != static_cast<observer_id>(0)) {
if (auto* observer = observers.try_to_get(mdl.obs_id);
observer && !observer->cb.empty()) {
if (observer->time_step == 0.0 ||
t - observer->tl >= observer->time_step) {
observer->msg = dyn.observation(t - mdl.tl);
observer->cb(*observer, t, observer::status::run);
observer->tl = t;
}
if (auto* obs = observers.try_to_get(mdl.obs_id); obs) {
obs->msg = dyn.observation(t - mdl.tl);
obs->cb(*obs, t, observer::status::run);
obs->tl = t;
} else {
mdl.obs_id = static_cast<observer_id>(0);
}
......
......@@ -522,7 +522,7 @@ main()
file_output fo_a("output_laudanski.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.0001, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(
sim.models.get(
......
......@@ -1118,8 +1118,8 @@ main()
expect(fo_a.os != nullptr);
expect(fo_b.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_a = sim.observers.alloc("A", fo_a);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -1305,11 +1305,11 @@ main()
file_output fo_a("izhikevitch_a.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
file_output fo_b("izhikevitch_b.csv");
expect(fo_b.os != nullptr);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -1395,8 +1395,8 @@ main()
expect(fo_a.os != nullptr);
expect(fo_b.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_a = sim.observers.alloc("A", fo_a);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -1482,8 +1482,8 @@ main()
expect(fo_a.os != nullptr);
expect(fo_b.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_a = sim.observers.alloc("A", fo_a);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -1582,7 +1582,7 @@ main()
file_output fo_a("lif-qss.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(integrator.id), obs_a);
......@@ -1668,7 +1668,7 @@ main()
file_output fo_a("lif-qss1.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(integrator.id), obs_a);
......@@ -1755,7 +1755,7 @@ main()
file_output fo_a("lif-qss2.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.001, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(integrator.id), obs_a);
......@@ -1914,11 +1914,11 @@ main()
file_output fo_a("izhikevitch-qss1_a.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.1, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
file_output fo_b("izhikevitch-qss1_b.csv");
expect(fo_b.os != nullptr);
auto& obs_b = sim.observers.alloc(0.1, "B", fo_b);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -2075,11 +2075,11 @@ main()
file_output fo_a("izhikevitch-qss2_a.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
file_output fo_b("izhikevitch-qss2_b.csv");
expect(fo_b.os != nullptr);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -2165,8 +2165,8 @@ main()
expect(fo_a.os != nullptr);
expect(fo_b.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_a = sim.observers.alloc("A", fo_a);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -2254,7 +2254,7 @@ main()
file_output fo_a("lif-qss3.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.001, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(integrator.id), obs_a);
......@@ -2411,11 +2411,11 @@ main()
file_output fo_a("izhikevitch-qss3_a.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
file_output fo_b("izhikevitch-qss3_b.csv");
expect(fo_b.os != nullptr);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -2527,8 +2527,8 @@ main()
expect(fo_a.os != nullptr);
expect(fo_b.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_a = sim.observers.alloc("A", fo_a);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -2616,8 +2616,8 @@ main()
expect(fo_a.os != nullptr);
expect(fo_b.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_b = sim.observers.alloc(0.01, "B", fo_b);
auto& obs_a = sim.observers.alloc("A", fo_a);
auto& obs_b = sim.observers.alloc("B", fo_b);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
......@@ -2705,7 +2705,7 @@ main()
file_output fo_a("neg-lif-qss1.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(integrator.id), obs_a);
......@@ -2792,7 +2792,7 @@ main()
file_output fo_a("neg-lif-qss2.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(integrator.id), obs_a);
......@@ -2879,7 +2879,7 @@ main()
file_output fo_a("neg-lif-qss3.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01, "A", fo_a);
auto& obs_a = sim.observers.alloc("A", fo_a);
sim.observe(sim.models.get(integrator.id), obs_a);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment