# Interventional truths for every world x scenario (plan section 5.5). # Usage: Rscript simulations/02_truths.R [n] [cores] # Writes simulations/truths/truths.csv and simulations/truths/risk_curves.csv. pkgload::load_all("pvisim", quiet = TRUE) suppressPackageStartupMessages(library(data.table)) args <- commandArgs(TRUE) n <- if (length(args) >= 1) as.numeric(args[1]) else 1e6 cores <- if (length(args) >= 2) as.integer(args[2]) else 6L raw <- yaml::read_yaml(default_params_path()) jobs <- CJ(world = names(raw$worlds), scenario = names(raw$scenarios), sorted = FALSE) res <- parallel::mclapply(seq_len(nrow(jobs)), function(i) compute_truths(jobs$world[i], jobs$scenario[i], n = n), mc.cores = cores) bad <- vapply(res, inherits, TRUE, "try-error") if (any(bad)) stop("failed: ", paste(jobs$world[bad], jobs$scenario[bad], collapse = "; "), "\n", res[bad][[1]]) dir.create("simulations/truths", showWarnings = FALSE) fwrite(rbindlist(lapply(res, `[[`, "truths")), "simulations/truths/truths.csv") fwrite(rbindlist(lapply(res, `[[`, "curves")), "simulations/truths/risk_curves.csv") cat("wrote simulations/truths/truths.csv\n")