diff --git a/pipeline/scripts/run_testmode_pipeline.jl b/pipeline/scripts/run_testmode_pipeline.jl new file mode 100644 index 000000000..8dc22ee2e --- /dev/null +++ b/pipeline/scripts/run_testmode_pipeline.jl @@ -0,0 +1,31 @@ +# Local environment script to run the analysis pipeline +using Pkg +Pkg.activate(joinpath(@__DIR__(), "..")) +using Dagger + +@assert !isempty(ARGS) "Test mode script requires the number of draws as an argument." +ndraws = parse(Int64, ARGS[1]) + +@info(""" + Running the analysis pipeline in test mode with $(ndraws) draws per model. + -------------------------------------------- + """) + +# Define the backend resources to use for the pipeline +# in this case we are using distributed local workers with loaded modules +using Distributed +pids = addprocs(; exeflags = ["--project=$(Base.active_project())"]) + +@everywhere using EpiAwarePipeline + +# Create an instance of the pipeline behaviour + +pipelines = [ + SmoothOutbreakPipeline(ndraws = ndraws), MeasuresOutbreakPipeline(ndraws = ndraws), + SmoothEndemicPipeline(ndraws = ndraws), RoughEndemicPipeline(ndraws = ndraws)] + +# Run the pipeline +do_pipeline(pipelines) + +# Remove the workers +rmprocs(pids) diff --git a/pipeline/src/infer/inference_prefix.jl b/pipeline/src/infer/inference_prefix.jl index 526fdff8d..7026454e1 100644 --- a/pipeline/src/infer/inference_prefix.jl +++ b/pipeline/src/infer/inference_prefix.jl @@ -1,3 +1,26 @@ +""" +This is an internal method that generates part of the prefix for the inference + results file name from the truth data and inference configuration. +""" +function _prefix_from_config(truthdata, inference_config) + igp_str = string(inference_config["igp"]) |> str -> split(str, ".")[end] + + return "_igp_" * igp_str * "_latentmodel_" * + inference_config["latent_namemodels"].first * "_truth_gi_mean_" * + string(truthdata["truth_gi_mean"]) * "_inference_T_" * + string(inference_config["T"]) +end + +""" +This is an internal method that generates the part of the prefix for the inference + results file name from the pipeline. +""" +_prefix_from_pipeline(pipeline::AbstractEpiAwarePipeline) = "observables" +_prefix_from_pipeline(pipeline::SmoothOutbreakPipeline) = "smooth_outbreak" +_prefix_from_pipeline(pipeline::MeasuresOutbreakPipeline) = "measures_outbreak" +_prefix_from_pipeline(pipeline::SmoothEndemicPipeline) = "smooth_endemic" +_prefix_from_pipeline(pipeline::RoughEndemicPipeline) = "rough_endemic" + """ This is an internal method that generates the prefix for the inference results file name. """ @@ -24,31 +47,12 @@ function _inference_prefix( string(inference_config["gi_mean"]) end -function _inference_prefix(truthdata, inference_config, pipeline::SmoothOutbreakPipeline) - return "smooth_outbreak" * "_igp_" * string(inference_config["igp"]) * "_latentmodel_" * - inference_config["latent_namemodels"].first * "_truth_gi_mean_" * - string(truthdata["truth_gi_mean"]) * "_used_gi_mean_" * - string(inference_config["gi_mean"]) -end - -function _inference_prefix(truthdata, inference_config, pipeline::MeasuresOutbreakPipeline) - return "measures_outbreak" * "_igp_" * string(inference_config["igp"]) * - "_latentmodel_" * - inference_config["latent_namemodels"].first * "_truth_gi_mean_" * - string(truthdata["truth_gi_mean"]) * "_used_gi_mean_" * - string(inference_config["gi_mean"]) -end - -function _inference_prefix(truthdata, inference_config, pipeline::SmoothEndemicPipeline) - return "smooth_endemic" * "_igp_" * string(inference_config["igp"]) * "_latentmodel_" * - inference_config["latent_namemodels"].first * "_truth_gi_mean_" * - string(truthdata["truth_gi_mean"]) * "_used_gi_mean_" * - string(inference_config["gi_mean"]) -end - -function _inference_prefix(truthdata, inference_config, pipeline::RoughEndemicPipeline) - return "rough_endemic" * "_igp_" * string(inference_config["igp"]) * "_latentmodel_" * - inference_config["latent_namemodels"].first * "_truth_gi_mean_" * - string(truthdata["truth_gi_mean"]) * "_used_gi_mean_" * - string(inference_config["gi_mean"]) +""" +This is an internal method that generates the prefix for the inference results file name for + `pipeline` objects of type `AbstractRtwithoutRenewalPipeline`. +""" +function _inference_prefix( + truthdata, inference_config, pipeline::AbstractRtwithoutRenewalPipeline) + return _prefix_from_pipeline(pipeline) * + _prefix_from_config(truthdata, inference_config) end diff --git a/pipeline/src/pipeline/do_pipeline.jl b/pipeline/src/pipeline/do_pipeline.jl index 7d4ec86c2..09b41f63f 100644 --- a/pipeline/src/pipeline/do_pipeline.jl +++ b/pipeline/src/pipeline/do_pipeline.jl @@ -22,7 +22,7 @@ Perform the pipeline for each `AbstractEpiAwarePipeline` in the given vector `pi """ function do_pipeline(pipelines::Vector{<:AbstractEpiAwarePipeline}) map(pipelines) do pipeline - Dagger.@spawn do_pipeline(pipeline) + do_pipeline(pipeline) end return nothing end diff --git a/pipeline/test/pipeline/test_pipelinefunctions.jl b/pipeline/test/pipeline/test_pipelinefunctions.jl index a8c0fab10..ed4406f7b 100644 --- a/pipeline/test/pipeline/test_pipelinefunctions.jl +++ b/pipeline/test/pipeline/test_pipelinefunctions.jl @@ -37,13 +37,3 @@ end res = do_pipeline(pipelines) @test isnothing(res) end - -@testset "do_pipeline test: main scenarios" begin - using EpiAwarePipeline - pipelines = [SmoothOutbreakPipeline(ndraws = 20, nchains = 1), - MeasuresOutbreakPipeline(ndraws = 20, nchains = 1), - SmoothEndemicPipeline(ndraws = 20, nchains = 1), - RoughEndemicPipeline(ndraws = 20, nchains = 1)] - res = do_pipeline(pipelines) - @test isnothing(res) -end