Skip to content

Commit

Permalink
Merge pull request #325 from mrc-ide/named-processes
Browse files Browse the repository at this point in the history
Assign names to all processes.
  • Loading branch information
plietar authored Jul 25, 2024
2 parents 342799e + e3091a4 commit 8bb953c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 35 deletions.
85 changes: 53 additions & 32 deletions R/processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,26 @@ create_processes <- function(
# ========
processes <- list(
# Maternal immunity
create_exponential_decay_process(variables$icm, parameters$rm),
create_exponential_decay_process(variables$ivm, parameters$rvm),
immunity_process = create_exponential_decay_process(variables$icm,
parameters$rm),
immunity_process = create_exponential_decay_process(variables$ivm,
parameters$rvm),
# Blood immunity
create_exponential_decay_process(variables$ib, parameters$rb),
immunity_process = create_exponential_decay_process(variables$ib,
parameters$rb),
# Acquired immunity
create_exponential_decay_process(variables$ica, parameters$rc),
create_exponential_decay_process(variables$iva, parameters$rva),
create_exponential_decay_process(variables$id, parameters$rid)
immunity_process = create_exponential_decay_process(variables$ica,
parameters$rc),
immunity_process = create_exponential_decay_process(variables$iva,
parameters$rva),
immunity_process = create_exponential_decay_process(variables$id,
parameters$rid)
)

if (parameters$individual_mosquitoes) {
processes <- c(
processes,
create_mosquito_emergence_process(
mosquito_emergence_process = create_mosquito_emergence_process(
solvers,
variables$mosquito_state,
variables$species,
Expand All @@ -72,7 +78,7 @@ create_processes <- function(
# kill mosquitoes caught in vector control
processes <- c(
processes,
create_biting_process(
biting_process = create_biting_process(
renderer,
solvers,
models,
Expand All @@ -84,21 +90,21 @@ create_processes <- function(
mixing_fn,
mixing_index
),
create_asymptomatic_progression_process(
asymptotic_progression_process = create_asymptomatic_progression_process(
variables$state,
parameters$dd,
variables,
parameters
),
create_progression_process(
progression_process = create_progression_process(
variables$state,
'A',
'U',
parameters$da,
variables$infectivity,
parameters$cu
),
create_progression_process(
progression_process = create_progression_process(
variables$state,
'U',
'S',
Expand Down Expand Up @@ -126,7 +132,7 @@ create_processes <- function(
# Create the progression process for Tr --> S specifying dt_input as the rate:
processes <- c(
processes,
create_progression_process(
progression_process = create_progression_process(
variables$state,
'Tr',
'S',
Expand All @@ -141,7 +147,7 @@ create_processes <- function(
# ===============
processes <- c(
processes,
create_solver_stepping_process(solvers, parameters)
solver_process = create_solver_stepping_process(solvers, parameters)
)

# =========
Expand All @@ -150,7 +156,7 @@ create_processes <- function(
if (!is.null(parameters$pev_epi_coverage)) {
processes <- c(
processes,
create_epi_pev_process(
epi_pev_process = create_epi_pev_process(
variables,
events,
parameters,
Expand All @@ -167,7 +173,7 @@ create_processes <- function(
if(!is.null(parameters$pmc_coverages)){
processes <- c(
processes,
create_pmc_process(
pmc_process = create_pmc_process(
variables,
events,
parameters,
Expand All @@ -188,42 +194,46 @@ create_processes <- function(

processes <- c(
processes,
individual::categorical_count_renderer_process(
renderer,
variables$state,
c('S', 'A', 'D', 'U', 'Tr')
),
create_variable_mean_renderer_process(
categorical_renderer = individual::categorical_count_renderer_process(
renderer,
variables$state,
c('S', 'A', 'D', 'U', 'Tr')
),
immunity_renderer = create_variable_mean_renderer_process(
renderer,
imm_var_names,
variables[imm_var_names]
),
create_prevalence_renderer(
prevalence_renderer = create_prevalence_renderer(
variables$state,
variables$birth,
variables$id,
parameters,
renderer
),
create_age_group_renderer(
age_group_renderer = create_age_group_renderer(
variables$birth,
parameters,
renderer
),
create_age_variable_mean_renderer_process(
age_aggregated_immunity_renderer = create_age_variable_mean_renderer_process(
imm_var_names[paste0(imm_var_names,"_rendering_min_ages") %in% names(parameters)],
variables[imm_var_names[paste0(imm_var_names,"_rendering_min_ages") %in% names(parameters)]],
variables$birth,
parameters,
renderer
),
create_compartmental_rendering_process(renderer, solvers, parameters)
mosquito_state_renderer = create_compartmental_rendering_process(
renderer,
solvers,
parameters
)
)

if (parameters$individual_mosquitoes) {
processes <- c(
processes,
create_vector_count_renderer_individual(
vector_count_renderer = create_vector_count_renderer_individual(
variables$mosquito_state,
variables$species,
variables$mosquito_state,
Expand All @@ -234,7 +244,7 @@ create_processes <- function(
} else {
processes <- c(
processes,
create_total_M_renderer_compartmental(
vector_count_renderer = create_total_M_renderer_compartmental(
renderer,
solvers,
parameters
Expand All @@ -249,20 +259,25 @@ create_processes <- function(
if (parameters$bednets) {
processes <- c(
processes,
distribute_nets(
distribute_nets_process = distribute_nets(
variables,
events$throw_away_net,
parameters,
correlations
),
net_usage_renderer(variables$net_time, renderer)
net_usage_renderer = net_usage_renderer(variables$net_time, renderer)
)
}

if (parameters$spraying) {
processes <- c(
processes,
indoor_spraying(variables$spray_time, renderer, parameters, correlations)
indoor_spraying_process = indoor_spraying(
variables$spray_time,
renderer,
parameters,
correlations
)
)
}

Expand All @@ -272,14 +287,20 @@ create_processes <- function(
if (parameters$progress_bar){
processes <- c(
processes,
create_progress_process(timesteps)
progress_bar_process = create_progress_process(timesteps)
)
}

# Mortality step
processes <- c(
processes,
create_mortality_process(variables, events, renderer, parameters))
mortality_process = create_mortality_process(
variables,
events,
renderer,
parameters
)
)

processes
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ test_that("exponential_decay_process works as expected", {
v <- individual::DoubleVariable$new(c(0,0.5,1,2,4,10))
p <- create_exponential_decay_process(v, rate)

individual:::execute_any_process(p, 1)
individual:::execute_process(p, 1)
v$.update()

expect_equal(v$get_values(), c(0, 0.25, 0.5, 1, 2, 5))

individual:::execute_any_process(p, 2)
individual:::execute_process(p, 2)
v$.update()

expect_equal(v$get_values(), c(0, 0.125, 0.25, 0.5, 1, 2.5))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-resume.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ test_that("Correlations can be set when resuming with new interventions", {
renderer$render("total_tbv_and_mda", tbv$copy()$and(mda)$size(), t)
renderer$render("total_tbv_or_mda", tbv$copy()$or(mda)$size(), t)
}
c(create_processes(renderer, variables, events, parameters, ...), p)
c(create_processes(renderer, variables, events, parameters, ...), p=p)
}

mockery::stub(run_resumable_simulation, 'create_processes', create_processes_stub)
Expand Down

0 comments on commit 8bb953c

Please sign in to comment.