Skip to content

Commit 4f12578

Browse files
committed
differences for PR #18
1 parent d2dad18 commit 4f12578

13 files changed

+217
-1898
lines changed

basic-targets.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ tar_make()
279279
▶ dispatched target penguins_csv_file
280280
● completed target penguins_csv_file [0.001 seconds, 190 bytes]
281281
▶ dispatched target penguins_data_raw
282-
● completed target penguins_data_raw [0.188 seconds, 10.403 kilobytes]
282+
● completed target penguins_data_raw [0.203 seconds, 10.403 kilobytes]
283283
▶ dispatched target penguins_data
284284
● completed target penguins_data [0.007 seconds, 1.609 kilobytes]
285-
▶ ended pipeline [0.341 seconds]
285+
▶ ended pipeline [0.356 seconds]
286286
```
287287

288288
Congratulations, you've run your first workflow with `targets`!

branch.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ tar_plan(
8181
✔ skipped target penguins_data_raw
8282
✔ skipped target penguins_data
8383
▶ dispatched target combined_model
84-
● completed target combined_model [0.024 seconds, 11.201 kilobytes]
85-
▶ ended pipeline [0.273 seconds]
84+
● completed target combined_model [0.044 seconds, 11.201 kilobytes]
85+
▶ ended pipeline [0.302 seconds]
8686
```
8787

8888
Let's have a look at the model. We will use the `glance()` function from the `broom` package. Unlike base R `summary()`, this function returns output as a tibble (the tidyverse equivalent of a dataframe), which as we will see later is quite useful for downstream analyses.
@@ -156,12 +156,12 @@ tar_plan(
156156
▶ dispatched target species_model
157157
● completed target species_model [0.001 seconds, 15.439 kilobytes]
158158
▶ dispatched target combined_summary
159-
● completed target combined_summary [0.006 seconds, 348 bytes]
159+
● completed target combined_summary [0.007 seconds, 348 bytes]
160160
▶ dispatched target interaction_summary
161-
● completed target interaction_summary [0.003 seconds, 348 bytes]
161+
● completed target interaction_summary [0.004 seconds, 348 bytes]
162162
▶ dispatched target species_summary
163-
● completed target species_summary [0.003 seconds, 347 bytes]
164-
▶ ended pipeline [0.28 seconds]
163+
● completed target species_summary [0.004 seconds, 347 bytes]
164+
▶ ended pipeline [0.307 seconds]
165165
```
166166

167167
Let's look at the summary of one of the models:
@@ -234,11 +234,11 @@ First, let's look at the messages provided by `tar_make()`.
234234
▶ dispatched branch model_summaries_812e3af782bee03f
235235
● completed branch model_summaries_812e3af782bee03f [0.006 seconds, 348 bytes]
236236
▶ dispatched branch model_summaries_2b8108839427c135
237-
● completed branch model_summaries_2b8108839427c135 [0.003 seconds, 347 bytes]
237+
● completed branch model_summaries_2b8108839427c135 [0.004 seconds, 347 bytes]
238238
▶ dispatched branch model_summaries_533cd9a636c3e05b
239-
● completed branch model_summaries_533cd9a636c3e05b [0.003 seconds, 348 bytes]
239+
● completed branch model_summaries_533cd9a636c3e05b [0.004 seconds, 348 bytes]
240240
● completed pattern model_summaries
241-
▶ ended pipeline [0.302 seconds]
241+
▶ ended pipeline [0.314 seconds]
242242
```
243243

244244
There is a series of smaller targets (branches) that are each named like model_summaries_812e3af782bee03f, then one overall `model_summaries` target.
@@ -369,13 +369,13 @@ tar_plan(
369369
✔ skipped target penguins_data
370370
✔ skipped target models
371371
▶ dispatched branch model_summaries_812e3af782bee03f
372-
● completed branch model_summaries_812e3af782bee03f [0.012 seconds, 374 bytes]
372+
● completed branch model_summaries_812e3af782bee03f [0.013 seconds, 374 bytes]
373373
▶ dispatched branch model_summaries_2b8108839427c135
374-
● completed branch model_summaries_2b8108839427c135 [0.007 seconds, 371 bytes]
374+
● completed branch model_summaries_2b8108839427c135 [0.008 seconds, 371 bytes]
375375
▶ dispatched branch model_summaries_533cd9a636c3e05b
376376
● completed branch model_summaries_533cd9a636c3e05b [0.004 seconds, 377 bytes]
377377
● completed pattern model_summaries
378-
▶ ended pipeline [0.281 seconds]
378+
▶ ended pipeline [0.301 seconds]
379379
```
380380

381381
And this time, when we load the `model_summaries`, we can tell which model corresponds to which row (you may need to scroll to the right to see it).

config.yaml

-87
This file was deleted.

files.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ tar_plan(
5656

5757
``` output
5858
▶ dispatched target some_data
59-
● completed target some_data [0 seconds, 64 bytes]
60-
▶ ended pipeline [0.089 seconds]
59+
● completed target some_data [0.001 seconds, 64 bytes]
60+
▶ ended pipeline [0.094 seconds]
6161
```
6262

6363
If we inspect the contents of `some_data` with `tar_read(some_data)`, it will contain the string `"Hello World"` as expected.
@@ -77,7 +77,7 @@ tar_plan(
7777

7878
``` output
7979
✔ skipped target some_data
80-
✔ skipped pipeline [0.087 seconds]
80+
✔ skipped pipeline [0.089 seconds]
8181
```
8282

8383
The target `some_data` was skipped, even though the contents of the file changed.
@@ -101,7 +101,7 @@ tar_plan(
101101
● completed target data_file [0.001 seconds, 26 bytes]
102102
▶ dispatched target some_data
103103
● completed target some_data [0 seconds, 78 bytes]
104-
▶ ended pipeline [0.109 seconds]
104+
▶ ended pipeline [0.111 seconds]
105105
```
106106

107107
This time we see that `targets` does successfully re-build `some_data` as expected.
@@ -186,10 +186,10 @@ tar_plan(
186186
▶ dispatched target penguins_data_raw_file
187187
● completed target penguins_data_raw_file [0.001 seconds, 53.098 kilobytes]
188188
▶ dispatched target penguins_data_raw
189-
● completed target penguins_data_raw [0.099 seconds, 10.403 kilobytes]
189+
● completed target penguins_data_raw [0.096 seconds, 10.403 kilobytes]
190190
▶ dispatched target penguins_data
191-
● completed target penguins_data [0.015 seconds, 1.495 kilobytes]
192-
▶ ended pipeline [0.369 seconds]
191+
● completed target penguins_data [0.014 seconds, 1.495 kilobytes]
192+
▶ ended pipeline [0.368 seconds]
193193
```
194194

195195
::::::::::::::::::::::::::::::::::
@@ -262,14 +262,14 @@ tar_plan(
262262

263263
``` output
264264
▶ dispatched target hello_file
265-
● completed target hello_file [0 seconds, 26 bytes]
265+
● completed target hello_file [0.001 seconds, 26 bytes]
266266
▶ dispatched target hello
267267
● completed target hello [0 seconds, 78 bytes]
268268
▶ dispatched target hello_caps
269-
● completed target hello_caps [0.001 seconds, 78 bytes]
269+
● completed target hello_caps [0 seconds, 78 bytes]
270270
▶ dispatched target hello_caps_out
271271
● completed target hello_caps_out [0 seconds, 26 bytes]
272-
▶ ended pipeline [0.111 seconds]
272+
▶ ended pipeline [0.107 seconds]
273273
```
274274

275275
Take a look at `hello_caps.txt` in the `results` folder and verify it is as you expect.

files/plans/plan_slurm.R

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
library(crew.cluster)
2+
library(targets)
3+
library(tarchetypes)
4+
library(palmerpenguins)
5+
library(broom)
6+
suppressPackageStartupMessages(library(tidyverse))
7+
8+
source("R/packages.R")
9+
source("R/functions.R")
10+
11+
tar_option_set(
12+
controller = crew_controller_slurm(
13+
workers = 3,
14+
script_lines = "module load R",
15+
slurm_memory_gigabytes_per_cpu = 1
16+
)
17+
)
18+
19+
tar_plan(
20+
# Load raw data
21+
tar_file_read(
22+
penguins_data_raw,
23+
path_to_file("penguins_raw.csv"),
24+
read_csv(!!.x, show_col_types = FALSE)
25+
),
26+
# Clean data
27+
penguins_data = clean_penguin_data(penguins_data_raw),
28+
# Build models
29+
models = list(
30+
combined_model = lm(
31+
bill_depth_mm ~ bill_length_mm, data = penguins_data),
32+
species_model = lm(
33+
bill_depth_mm ~ bill_length_mm + species, data = penguins_data),
34+
interaction_model = lm(
35+
bill_depth_mm ~ bill_length_mm * species, data = penguins_data)
36+
),
37+
# Get model summaries
38+
tar_target(
39+
model_summaries,
40+
glance_with_mod_name_slow(models),
41+
pattern = map(models)
42+
),
43+
# Get model predictions
44+
tar_target(
45+
model_predictions,
46+
augment_with_mod_name_slow(models),
47+
pattern = map(models)
48+
)
49+
)

files/plans/plan_slurm_gpu.R

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
graphics_devices <- function(){
2+
system2("lshw", c("-class", "display"), stdout=TRUE, stderr=FALSE)
3+
}
4+
5+
library(crew)
6+
library(targets)
7+
library(tarchetypes)
8+
library(crew.cluster)
9+
10+
source("R/packages.R")
11+
source("R/functions.R")
12+
13+
tar_option_set(
14+
controller = crew_controller_group(
15+
crew_controller_slurm(
16+
name = "cpu_worker",
17+
workers = 1,
18+
script_lines = "module load R",
19+
slurm_memory_gigabytes_per_cpu = 1,
20+
slurm_cpus_per_task = 1
21+
),
22+
23+
crew_controller_slurm(
24+
name = "gpu_worker",
25+
workers = 1,
26+
script_lines = c(
27+
"#SBATCH --partition=gpuq",
28+
"#SBATCH --gres=gpu:1",
29+
"module load R"
30+
),
31+
slurm_memory_gigabytes_per_cpu = 1,
32+
slurm_cpus_per_task = 1
33+
)
34+
)
35+
)
36+
37+
tar_plan(
38+
tar_target(
39+
cpu_hardware,
40+
graphics_devices(),
41+
resources = tar_resources(
42+
crew = tar_resources_crew(controller = "cpu_worker")
43+
)
44+
),
45+
tar_target(
46+
gpu_hardware,
47+
graphics_devices(),
48+
resources = tar_resources(
49+
crew = tar_resources_crew(controller = "gpu_worker")
50+
)
51+
)
52+
)

files/plans/plan_slurm_memory.R

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
library(crew)
2+
library(targets)
3+
library(tarchetypes)
4+
library(crew.cluster)
5+
6+
source("R/packages.R")
7+
source("R/functions.R")
8+
9+
small_memory <- crew_controller_slurm(
10+
name = "small_memory",
11+
script_lines = "module load R",
12+
slurm_memory_gigabytes_per_cpu = 1
13+
)
14+
big_memory <- crew_controller_slurm(
15+
name = "big_memory",
16+
script_lines = "module load R",
17+
slurm_memory_gigabytes_per_cpu = 2
18+
)
19+
20+
tar_option_set(
21+
controller = crew_controller_group(small_memory, big_memory)
22+
)
23+
24+
list(
25+
tar_target(
26+
name = big_memory_task,
27+
command = Sys.getenv("SLURM_MEM_PER_CPU"),
28+
resources = tar_resources(
29+
crew = tar_resources_crew(controller = "big_memory")
30+
)
31+
),
32+
tar_target(
33+
name = small_memory_task,
34+
command = Sys.getenv("SLURM_MEM_PER_CPU"),
35+
resources = tar_resources(
36+
crew = tar_resources_crew(controller = "small_memory")
37+
)
38+
)
39+
)

0 commit comments

Comments
 (0)