Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create run_testmode_pipeline.jl #359

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading