Skip to content

Commit b762470

Browse files
authored
Merge pull request #71 from cmu-delphi/ds/minor-fix
A few minor fixes
2 parents c775304 + d3c7e0d commit b762470

File tree

9 files changed

+81
-30
lines changed

9 files changed

+81
-30
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ install:
33
Rscript -e "renv::restore()"
44

55
run:
6-
Rscript run.R
6+
Rscript run.R
7+
8+
run-nohup:
9+
nohup Rscript run.R &

R/targets_utils.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ lists_of_real_values <- function(param_grid) {
6161
#' - `hhs_signal`
6262
#' - `chng_signal`
6363
#' - `fetch_args`
64-
#'
64+
#' - `eval_time`
65+
#' - `traing_time`
6566
#' @export
6667
make_data_targets <- function() {
6768
list(
@@ -74,7 +75,7 @@ make_data_targets <- function() {
7475
geo_type = "state",
7576
time_type = "day",
7677
geo_values = "*",
77-
time_values = epirange(from = "2020-01-01", to = "2024-01-01"),
78+
time_values = eval_time,
7879
fetch_args = fetch_args
7980
)
8081
}
@@ -88,7 +89,7 @@ make_data_targets <- function() {
8889
geo_type = "state",
8990
time_type = "day",
9091
geo_values = "*",
91-
time_values = epirange(from = "2020-01-01", to = "2024-01-01"),
92+
time_values = eval_time,
9293
fetch_args = fetch_args
9394
)
9495
}
@@ -124,7 +125,7 @@ make_data_targets <- function() {
124125
geo_type = "state",
125126
time_type = "day",
126127
geo_values = "*",
127-
time_values = epirange(from = "20220101", to = "20220401"),
128+
time_values = training_time,
128129
issues = "*",
129130
fetch_args = fetch_args
130131
)
@@ -139,7 +140,7 @@ make_data_targets <- function() {
139140
geo_type = "state",
140141
time_type = "day",
141142
geo_values = "*",
142-
time_values = epirange(from = "20220101", to = "20220401"),
143+
time_values = training_time,
143144
issues = "*",
144145
fetch_args = fetch_args
145146
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ USE_SHINY=false
1717
TAR_PROJECT=covid_hosp_explore
1818
EXTERNAL_SCORES_PATH=
1919
USE_AWS_S3=false
20-
AWS_S3_PREFIX=
20+
AWS_S3_PREFIX=2023/exploration
2121

2222
# Run the pipeline wrapper run.R.
2323
make run

_targets.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
covid_hosp_explore:
22
script: covid_hosp_explore.R
33
store: covid_hosp_explore
4-
use_crew: no
4+
use_crew: yes
55
flu_hosp_explore:
66
script: flu_hosp_explore.R
77
store: flu_hosp_explore
8-
use_crew: no
8+
use_crew: yes
99
flu_hosp_prod:
1010
script: flu_hosp_prod.R
1111
store: flu_hosp_prod
12-
use_crew: no
12+
use_crew: yes
1313
covid_hosp_prod:
1414
script: covid_hosp_prod.R
1515
store: covid_hosp_prod
16-
use_crew: no
16+
use_crew: yes

covid_hosp_explore.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ ensembles_params_grid_target <- list(
126126
# during the actual targets run, since the commands are frozen as expressions).
127127
hhs_signal <- "confirmed_admissions_covid_1d"
128128
chng_signal <- "smoothed_adj_outpatient_covid"
129-
fetch_args <- epidatr::fetch_args_list(return_empty = TRUE, timeout_seconds = 200)
129+
eval_time <- epidatr::epirange(from = "2020-01-01", to = "2024-01-01")
130+
training_time <- epidatr::epirange(from = "2021-01-01", to = "2023-06-01")
131+
fetch_args <- epidatr::fetch_args_list(return_empty = TRUE, timeout_seconds = 400)
130132
data_targets <- make_data_targets()
131133

132134

extras/targets-common.R

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ suppressPackageStartupMessages({
2020
# https://books.ropensci.org/targets/crew.html#heterogeneous-workers
2121
main_controller <- crew_controller_local(
2222
name = "main_controller",
23-
workers = parallel::detectCores() - 5
23+
workers = parallel::detectCores() - 1L
2424
)
2525
serial_controller <- crew_controller_local(
2626
name = "serial_controller",
@@ -50,6 +50,23 @@ tar_option_set(
5050
)
5151
)
5252

53+
use_aws_s3 <- as.logical(Sys.getenv("USE_AWS_S3", FALSE))
54+
tar_project <- Sys.getenv("TAR_PROJECT", "covid_hosp_explore")
55+
aws_s3_prefix <- Sys.getenv("AWS_S3_PREFIX", "exploration")
56+
aws_s3_prefix <- paste0(aws_s3_prefix, "/", tar_project)
57+
if (use_aws_s3) {
58+
tar_option_set(
59+
repository = "aws",
60+
resources = tar_resources(
61+
aws = tar_resources_aws(
62+
bucket = "forecasting-team-data",
63+
prefix = aws_s3_prefix,
64+
region = "us-east-1"
65+
)
66+
)
67+
)
68+
}
69+
5370
linreg <- parsnip::linear_reg()
5471
quantreg <- epipredict::quantile_reg()
5572
ONE_AHEAD_FORECAST_NAME <- "forecast_by_ahead"

flu_hosp_explore.R

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ forecaster_params_grid_target <- list(
4040
name = forecaster_params_grid,
4141
command = {
4242
param_grid
43-
}
43+
},
44+
priority = 0.99
4445
)
4546
)
4647

4748
# moving on to the ensemble
4849
AHEADS <- 1:4
49-
ensemble_grid <- append(
50+
ensemble_grid <- add_row(
5051
make_shared_ensembles(),
5152
make_unique_ensemble_grid()
5253
) %>% id_ahead_ensemble_grid(AHEADS)
@@ -71,14 +72,17 @@ ensembles_params_grid_target <- list(
7172
name = ensemble_forecasters,
7273
command = {
7374
ensemble_grid
74-
}
75+
},
76+
priority = 0.99
7577
)
7678
)
7779

7880
# These globals are needed by the function below (and they need to persist
7981
# during the actual targets run, since the commands are frozen as expressions).
8082
hhs_signal <- "confirmed_admissions_influenza_1d_prop_7dav"
8183
chng_signal <- "smoothed_adj_outpatient_flu"
84+
eval_time <- epidatr::epirange(from = "2020-01-01", to = "2024-01-01")
85+
training_time <- epidatr::epirange(from = "2021-01-01", to = "2023-06-01")
8286
fetch_args <- epidatr::fetch_args_list(return_empty = TRUE, timeout_seconds = 300)
8387
data_targets <- make_data_targets()
8488

@@ -89,8 +93,40 @@ date_step <- 7L
8993
forecasts_and_scores_by_ahead <- make_forecasts_and_scores_by_ahead()
9094
forecasts_and_scores <- make_forecasts_and_scores()
9195
# ensembles
92-
ensemble_and_scores_by_ahead <- make_ensemble_targets_by_ahead()
93-
ensemble_and_scores <- make_ensemble_targets_and_scores()
96+
97+
# do a tar_map or tar_target to asdf
98+
ensembles_and_scores_by_ahead <- tar_map(
99+
values = target_ensemble_grid,
100+
names = id,
101+
tar_target(
102+
name = ensemble_by_ahead,
103+
command = {
104+
ensemble(joined_archive_data_2022,
105+
forecaster_ids,
106+
"hhs",
107+
extra_sources = "chng",
108+
ensemble_params,
109+
ensemble_params_names
110+
)
111+
},
112+
priority = .9999
113+
),
114+
tar_target(
115+
name = score_by_ahead,
116+
command = {
117+
run_evaluation_measure(
118+
data = ensemble_by_ahead,
119+
evaluation_data = hhs_evaluation_data,
120+
measure = list(
121+
wis = weighted_interval_score,
122+
ae = absolute_error,
123+
cov_80 = interval_coverage(0.8)
124+
)
125+
)
126+
}
127+
)
128+
)
129+
ensembles_and_scores <- make_ensemble_targets_and_scores()
94130
# other sources
95131
external_names_and_scores <- make_external_names_and_scores()
96132

man/make_data_targets.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

run.R

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ debug_mode <- as.logical(Sys.getenv("DEBUG_MODE", TRUE))
3232
use_shiny <- as.logical(Sys.getenv("USE_SHINY", FALSE))
3333
use_aws_s3 <- as.logical(Sys.getenv("USE_AWS_S3", FALSE))
3434
aws_s3_prefix <- Sys.getenv("AWS_S3_PREFIX", "exploration")
35+
aws_s3_prefix <- paste0(aws_s3_prefix, "/", tar_project)
3536
cli::cli_inform(
3637
c(
3738
"i" = "Reading environment variables...",
@@ -53,17 +54,6 @@ suppressPackageStartupMessages({
5354
store_dir <- tar_path_store()
5455
if (!dir.exists(store_dir)) dir.create(store_dir)
5556

56-
if (use_aws_s3) {
57-
tar_option_set(
58-
repository = "aws",
59-
resources = tar_resources(
60-
aws = tar_resources_aws(
61-
bucket = "forecasting-team-data",
62-
prefix = aws_s3_prefix
63-
)
64-
)
65-
)
66-
}
6757

6858
tar_manifest()
6959
if (debug_mode) {
@@ -78,7 +68,7 @@ if (use_shiny) {
7868
# Prevent functions defined in /R dir from being loaded unnecessarily
7969
options(shiny.autoload.r = FALSE)
8070

81-
forecaster_options <- unique(tar_read(forecasters)[["parent_id"]])
71+
forecaster_options <- unique(tar_read(forecaster_params_grid)[["parent_id"]])
8272
# Map forecaster names to score files
8373
forecaster_options <- setNames(
8474
# File names

0 commit comments

Comments
 (0)