Skip to content

Commit

Permalink
Assign names to all processes.
Browse files Browse the repository at this point in the history
Thanks to [individual#198], processes in the simulation can now be
named. This has no effect on the behaviour of the simulation but helps
in debugging and profiling by labelling the call frames with the given
names.

While at it, I've fixed a typo in the name of the prevalence renderer.

[individual#198]: mrc-ide/individual#198
  • Loading branch information
plietar committed Jul 12, 2024
1 parent e51c6bc commit 8363172
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 34 deletions.
83 changes: 52 additions & 31 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 @@ -185,35 +191,39 @@ 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,
c('ica', 'icm', 'ib', 'id', 'iva', 'ivm'),
variables[c('ica', 'icm', 'ib', 'id', 'iva', 'ivm')]
),
create_prevelance_renderer(
prevalance_renderer = create_prevalance_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_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 @@ -224,7 +234,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 @@ -239,20 +249,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 @@ -262,14 +277,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
2 changes: 1 addition & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ in_age_range <- function(birth, timestep, lower, upper) {
#' @param renderer model renderer
#'
#' @noRd
create_prevelance_renderer <- function(
create_prevalance_renderer <- function(
state,
birth,
immunity,
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-render.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_that('that default rendering works', {
immunity <- individual::DoubleVariable$new(rep(1, 4))

renderer <- mock_render(1)
process <- create_prevelance_renderer(
process <- create_prevalance_renderer(
state,
birth,
immunity,
Expand Down Expand Up @@ -70,7 +70,7 @@ test_that('that default rendering works when no one is in the age range', {
immunity <- individual::DoubleVariable$new(rep(1, 4))

renderer <- mock_render(1)
process <- create_prevelance_renderer(
process <- create_prevalance_renderer(
state,
birth,
immunity,
Expand Down

0 comments on commit 8363172

Please sign in to comment.