Skip to content

Commit

Permalink
Create run_testmode_pipeline.jl (#359)
Browse files Browse the repository at this point in the history
* Create run_testmode_pipeline.jl

* Fix inference prefixing along with a method refactor

* QUICKFIX: remove dagger spawn at top level of pipeline
  • Loading branch information
SamuelBrand1 authored Jul 10, 2024
1 parent 7bf2726 commit 4dfdfad
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 38 deletions.
31 changes: 31 additions & 0 deletions pipeline/scripts/run_testmode_pipeline.jl
Original file line number Diff line number Diff line change
@@ -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)
58 changes: 31 additions & 27 deletions pipeline/src/infer/inference_prefix.jl
Original file line number Diff line number Diff line change
@@ -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.
"""
Expand All @@ -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
2 changes: 1 addition & 1 deletion pipeline/src/pipeline/do_pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 0 additions & 10 deletions pipeline/test/pipeline/test_pipelinefunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4dfdfad

Please sign in to comment.