From 6e91cd8e1a195a300be0e9a049b2d2958e114b7c Mon Sep 17 00:00:00 2001
From: Mahmoud Bentriou <mahmoud.bentriou@centralesupelec.fr>
Date: Mon, 16 Nov 2020 17:01:05 +0100
Subject: [PATCH] New test for sir row bench + fix other test

---
 core/_tests_simulate.jl                        | 15 ++++++++++++++-
 tests/run_simulation.jl                        |  1 +
 tests/simulation/sim_sir_col_buffer_bounded.jl |  2 +-
 tests/simulation/sim_sir_row_buffer_bounded.jl | 16 ++++++++++++++++
 4 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 tests/simulation/sim_sir_row_buffer_bounded.jl

diff --git a/core/_tests_simulate.jl b/core/_tests_simulate.jl
index 0f55f06..06e01d1 100644
--- a/core/_tests_simulate.jl
+++ b/core/_tests_simulate.jl
@@ -1,11 +1,24 @@
 
 # File for benchmarking simulation and memory access of the package.
 
+# Trajectories
+
 _get_values_col(σ::AbstractTrajectory, var::String) = 
 σ.values[(σ.m)._map_obs_var_idx[var],:] 
 _get_values_row(σ::AbstractTrajectory, var::String) = 
 σ.values[:,(σ.m)._map_obs_var_idx[var]] 
 
+_get_state_col(σ::AbstractTrajectory, idx::Int) = 
+σ.values[:,idx]
+_get_state_row(σ::AbstractTrajectory, idx::Int) = 
+σ.values[idx,:]
+
+_get_value_col(σ::AbstractTrajectory, var::String, idx::Int) = 
+σ.values[(σ.m)._map_obs_var_idx[var],idx] 
+_get_value_row(σ::AbstractTrajectory, var::String, idx::Int) = 
+σ.values[idx,(σ.m)._map_obs_var_idx[var]] 
+
+# Model
 
 function _simulate_col(m::ContinuousTimeModel)
     # trajectory fields
@@ -135,7 +148,7 @@ function _simulate_row_buffer(m::ContinuousTimeModel; buffer_size::Int = 5)
         while i < buffer_size && !is_absorbing && (tn <= m.time_bound)
             i += 1
             m.f!(mat_x, l_t, l_tr, i, xn, tn, m.p)
-            xn = @view mat_x[:,i]
+            xn = @view mat_x[i,:]
             tn = l_t[i]
             is_absorbing = m.is_absorbing(m.p,xn)::Bool
         end
diff --git a/tests/run_simulation.jl b/tests/run_simulation.jl
index 224820f..0336e50 100644
--- a/tests/run_simulation.jl
+++ b/tests/run_simulation.jl
@@ -9,6 +9,7 @@ if !isdir(str_dir_pics) mkdir(str_dir_pics) end
     @test include("simulation/sim_sir.jl")
     @test include("simulation/sim_sir_bounded.jl")
     @test include("simulation/sim_sir_col_buffer_bounded.jl")
+    @test include("simulation/sim_sir_row_buffer_bounded.jl")
     @test include("simulation/sim_er.jl")
 end
 
diff --git a/tests/simulation/sim_sir_col_buffer_bounded.jl b/tests/simulation/sim_sir_col_buffer_bounded.jl
index 94335f9..3343495 100644
--- a/tests/simulation/sim_sir_col_buffer_bounded.jl
+++ b/tests/simulation/sim_sir_col_buffer_bounded.jl
@@ -8,7 +8,7 @@ SIR_col_buffer.time_bound = 100.0
 
 σ = _simulate_col_buffer(SIR_col_buffer)
 plt.figure()
-plt.step(σ["times"], σ["I"], "ro--", marker="x", where="post", linewidth=1.0)
+plt.step(σ["times"], _get_values_col(σ,"I"), "ro--", marker="x", where="post", linewidth=1.0)
 plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir_col_buffer_bounded.png")
 plt.close()
 
diff --git a/tests/simulation/sim_sir_row_buffer_bounded.jl b/tests/simulation/sim_sir_row_buffer_bounded.jl
new file mode 100644
index 0000000..b6a3898
--- /dev/null
+++ b/tests/simulation/sim_sir_row_buffer_bounded.jl
@@ -0,0 +1,16 @@
+
+using MarkovProcesses 
+include(get_module_path() * "/core/_tests_simulate.jl")
+using PyPlot
+
+load_model("_bench_perf_test/SIR_row_buffer")
+SIR_row_buffer.time_bound = 100.0
+
+σ = _simulate_row_buffer(SIR_row_buffer)
+plt.figure()
+plt.step(σ["times"], _get_values_row(σ,"I"), "ro--", marker="x", where="post", linewidth=1.0)
+plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir_row_buffer_bounded.png")
+plt.close()
+
+return true
+
-- 
GitLab