@@ -15,7 +15,7 @@ test_that("compute_grid_info - recipe only", {
15
15
16
16
expect_equal(res $ .iter_preprocessor , 1 : 5 )
17
17
expect_equal(res $ .msg_preprocessor , paste0(" preprocessor " , 1 : 5 , " /5" ))
18
- expect_equal(res $ deg_free , grid $ deg_free )
18
+ expect_equal(sort( res $ deg_free ), sort( grid $ deg_free ) )
19
19
expect_equal(res $ .iter_model , rep(1 , 5 ))
20
20
expect_equal(res $ .iter_config , as.list(paste0(" Preprocessor" , 1 : 5 , " _Model1" )))
21
21
expect_equal(res $ .msg_model , paste0(" preprocessor " , 1 : 5 , " /5, model 1/1" ))
@@ -27,6 +27,7 @@ test_that("compute_grid_info - recipe only", {
27
27
ignore.order = TRUE
28
28
)
29
29
expect_equal(nrow(res ), 5 )
30
+ expect_equal(vctrs :: vec_unique_count(res $ .iter_config ), nrow(grid ))
30
31
})
31
32
32
33
test_that(" compute_grid_info - model only (no submodels)" , {
@@ -57,6 +58,7 @@ test_that("compute_grid_info - model only (no submodels)", {
57
58
ignore.order = TRUE
58
59
)
59
60
expect_equal(nrow(res ), 5 )
61
+ expect_equal(vctrs :: vec_unique_count(res $ .iter_config ), nrow(grid ))
60
62
})
61
63
62
64
test_that(" compute_grid_info - model only (with submodels)" , {
@@ -107,8 +109,8 @@ test_that("compute_grid_info - recipe and model (no submodels)", {
107
109
108
110
expect_equal(res $ .iter_preprocessor , 1 : 5 )
109
111
expect_equal(res $ .msg_preprocessor , paste0(" preprocessor " , 1 : 5 , " /5" ))
110
- expect_equal(res $ learn_rate , grid $ learn_rate )
111
- expect_equal(res $ deg_free , grid $ deg_free )
112
+ expect_equal(sort( res $ learn_rate ), sort( grid $ learn_rate ) )
113
+ expect_equal(sort( res $ deg_free ), sort( grid $ deg_free ) )
112
114
expect_equal(res $ .iter_model , rep(1 , 5 ))
113
115
expect_equal(res $ .iter_config , as.list(paste0(" Preprocessor" , 1 : 5 , " _Model1" )))
114
116
expect_equal(res $ .msg_model , paste0(" preprocessor " , 1 : 5 , " /5, model 1/1" ))
@@ -120,6 +122,7 @@ test_that("compute_grid_info - recipe and model (no submodels)", {
120
122
ignore.order = TRUE
121
123
)
122
124
expect_equal(nrow(res ), 5 )
125
+ expect_equal(vctrs :: vec_unique_count(res $ .iter_config ), nrow(grid ))
123
126
})
124
127
125
128
test_that(" compute_grid_info - recipe and model (with submodels)" , {
@@ -169,6 +172,7 @@ test_that("compute_grid_info - recipe and model (with submodels)", {
169
172
)
170
173
expect_equal(nrow(res ), 3 )
171
174
})
175
+
172
176
test_that(" compute_grid_info - recipe and model (with and without submodels)" , {
173
177
library(workflows )
174
178
library(parsnip )
@@ -185,25 +189,30 @@ test_that("compute_grid_info - recipe and model (with and without submodels)", {
185
189
# use grid_regular to (partially) trigger submodel trick
186
190
set.seed(1 )
187
191
param_set <- extract_parameter_set_dials(wflow )
188
- grid <- bind_rows(grid_regular(param_set ), grid_space_filling(param_set ))
192
+ grid <-
193
+ bind_rows(grid_regular(param_set ), grid_space_filling(param_set )) %> %
194
+ arrange(deg_free , loss_reduction , trees )
189
195
res <- compute_grid_info(wflow , grid )
190
196
191
197
expect_equal(length(unique(res $ .iter_preprocessor )), 5 )
192
198
expect_equal(
193
199
unique(res $ .msg_preprocessor ),
194
200
paste0(" preprocessor " , 1 : 5 , " /5" )
195
201
)
196
- expect_equal(res $ trees , c(rep(max(grid $ trees ), 10 ), 1 ))
202
+ expect_equal(sort( res $ trees ), sort( c(rep(max(grid $ trees ), 10 ), 1 ) ))
197
203
expect_equal(unique(res $ .iter_model ), 1 : 3 )
198
204
expect_equal(
199
- res $ .iter_config [1 : 3 ],
205
+ res $ .iter_config [res $ .iter_preprocessor == 1 ],
200
206
list (
201
- c(" Preprocessor1_Model1 " , " Preprocessor1_Model2 " , " Preprocessor1_Model3 " , " Preprocessor1_Model4 " ),
202
- c(" Preprocessor2_Model1 " , " Preprocessor2_Model2 " , " Preprocessor2_Model3 " ),
203
- c(" Preprocessor3_Model1 " , " Preprocessor3_Model2 " , " Preprocessor3_Model3 " )
207
+ c(" Preprocessor1_Model01 " , " Preprocessor1_Model02 " , " Preprocessor1_Model03 " , " Preprocessor1_Model04 " ),
208
+ c(" Preprocessor1_Model05 " , " Preprocessor1_Model06 " , " Preprocessor1_Model07 " ),
209
+ c(" Preprocessor1_Model08 " , " Preprocessor1_Model09 " , " Preprocessor1_Model10 " )
204
210
)
205
211
)
206
- expect_equal(res $ .msg_model [1 : 3 ], paste0(" preprocessor " , 1 : 3 , " /5, model 1/3" ))
212
+ expect_equal(
213
+ res $ .msg_model [res $ .iter_preprocessor == 1 ],
214
+ paste0(" preprocessor 1/5, model " , 1 : 3 , " /3" )
215
+ )
207
216
expect_equal(
208
217
res $ .submodels [1 : 3 ],
209
218
list (
@@ -212,6 +221,12 @@ test_that("compute_grid_info - recipe and model (with and without submodels)", {
212
221
list (trees = c(1L , 1000L ))
213
222
)
214
223
)
224
+ expect_equal(
225
+ res %> %
226
+ mutate(num_models = purrr :: map_int(.iter_config , length )) %> %
227
+ summarize(n = sum(num_models ), .by = c(deg_free )),
228
+ grid %> % count(deg_free )
229
+ )
215
230
expect_named(
216
231
res ,
217
232
c(" .iter_preprocessor" , " .msg_preprocessor" , " deg_free" , " trees" ,
@@ -325,4 +340,5 @@ test_that("compute_grid_info - recipe and model (no submodels but has inner grid
325
340
ignore.order = TRUE
326
341
)
327
342
expect_equal(nrow(res ), 9 )
343
+ expect_equal(vctrs :: vec_unique_count(res $ .iter_config ), nrow(grid ))
328
344
})
0 commit comments