/
run_model.Rmd
109 lines (98 loc) · 3.31 KB
/
run_model.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: "run_model"
author: "Luke Holman"
output: workflowr::wflow_html
editor_options:
chunk_output_type: console
---
```{r}
# This bit is for the unimelb cluster, Spartan
working_directory <- "/data/projects/punim0243/W_shredder"
setwd(working_directory)
```
```{r setup, echo=FALSE, results='hide'}
source_rmd <- function(file){
options(knitr.duplicate.label = "allow")
tempR <- tempfile(tmpdir = ".", fileext = ".R")
on.exit(unlink(tempR))
knitr::purl(file, output = tempR, quiet = TRUE)
source(tempR, local = globalenv())
}
source_rmd("analysis/model_functions.Rmd")
custom_functions <- ls()
```
## Define the parameter space
```{r}
set.seed(1)
parameters <- expand.grid(
release_size = 20,
release_strategy = c("one_patch", "all_patches"),
W_shredding_rate = c(0.95, 1),
Z_conversion_rate = c(0, 0.5, 0.95),
Zr_creation_rate = c(0, 0.001, 0.01),
Zr_mutation_rate = c(0.0, 0.00001),
Wr_mutation_rate = c(0.0, 0.00001),
cost_Zdrive_female = c(0.01, 0.1, 0.5),
male_migration_prob = c(0.05, 0.5),
female_migration_prob = c(0.05, 0.5),
migration_type = c("local", "global"),
softness = c(0, 0.5, 1),
male_weighting = c(0.8, 1, 1.2),
density_dependence_shape = 0.2,
cost_Zdrive_male = c(0.01, 0.1),
cost_Wr = 0.05,
cost_Zr = 0.05,
cost_A = 0.01,
cost_B = 0.01,
n_patches = c(2, 20),
max_fecundity = 50,
carrying_capacity = 10000,
initial_pop_size = 10000,
initial_Zdrive = 0,
initial_Zr = 0.00,
initial_Wr = 0.00,
initial_A = 0.00,
initial_B = 0.00,
realisations = 1, # change to e.g. 1:100 for replication
generations = 900,
burn_in = 50
) %>% filter(!(W_shredding_rate == 0 & Z_conversion_rate == 0))
parameters <- parameters[sample(nrow(parameters)), ]
# Set the initial frequency to teh mutation rate for the resistant chromosomes
parameters$initial_Wr <- parameters$Wr_mutation_rate
parameters$initial_Zr <- parameters$Zr_mutation_rate
```
## Run the model on each parameter space
```{r}
# keep_going <- TRUE
# while(keep_going) do_all_parameters(parameters, over_write = FALSE, cores = 8)
# combine_results_files(cores = 8) %>% saveRDS(file = "data/all_results.rds")
```
# Fix over.write = FALSE
# Wr mutants more common than expected? First Wr mutants invade quickly, and can more than double N at carrying capacity!
# With density, I currently assume that females with half fecundity affect density half as much as wild-type females...
# So, patches of low-fitness females have lower density (though those females will reproduce less)
```{r}
chunk_size <- 400
cpus <- 8
sopt <- list(time = '48:00:00', # time in hours
mem = '65536') # 64GB memory across all 8 cores
chunks <- split(1:nrow(parameters),
ceiling(seq_along(1:nrow(parameters))/chunk_size))
number_of_chunks <- length(chunks)
sjob <- slurm_apply(function(i) {
try(do_all_parameters(parameters[chunks[[i]],],
over_write = FALSE,
cores = cpus,
wd = working_directory))},
data.frame(i = 1:length(chunks)),
add_objects = c("do_all_parameters",
"parameters", "cpus",
"working_directory",
"chunks", "number_of_chunks",
custom_functions),
jobname = 'W_shredder',
nodes = number_of_chunks,
cpus_per_node = cpus,
slurm_options = sopt)
```