Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of get_tune_schedule() #978

Closed
wants to merge 34 commits into from
Closed

Conversation

hfrick
Copy link
Member

@hfrick hfrick commented Jan 17, 2025

Here's the refactor of get_tune_schedule()! The basic idea is to schedule the stages recursively, starting at the preprocessing stage down to the postprocessing stage, and always do one stage at a time, pushing the remaining parameters into a nested tibble.

I've made a PR into tune-schedule so that you can see the diffs to the previous version clearly. I understand that branch to be our place to work things out, so I'm happy to make a separate PR into main if we are happy with how get_tune_schedule() looks. I think the tests could also make use of that separation of the stages into smaller scheduling functions, but I didn't do this here because I wanted you to see how the tests changed for this refactor.

The refactor leads to 0-row tibbles when there are no tuning parameters at all (which we discussed in the team meeting) and small changes in the order of the columns. The ordering of the rows (for preprocessing) also stays the same now between the ingoing grid and the outgoing schedule.

Since this is the second round of working over this scheduling function, no need to review "only" high-level, hit me with your nits so that this part is ready for main!

R/schedule.R Outdated

# ------------------------------------------------------------------------------
get_param_info <- function(wflow) {
param_info <- tune_args(wflow) %>%
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using tune_args() here instead of a parameter set object, due to considerations I've put in #974 (comment)

mod_tune_bst <- boost_tree(trees = tune(), min_n = tune(), mode = "regression")
mod_tune_rf <- rand_forest(min_n = tune(), mode = "regression")
mod_tune_bst <- parsnip::boost_tree(trees = tune(), min_n = tune(), mode = "regression")
mod_tune_rf <- parsnip::rand_forest(min_n = tune(), mode = "regression")

if (rlang::is_installed("probably")) {

adjust_tune_min <-
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we usually use rec in the name of recipes objects, I would like to advocate for calling tailor objects something with tailor rather than adjust_.

Copy link
Contributor

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to hold off on a proper review until I can carve out a solid chunk of time, but re:

I've made a PR into tune-schedule so that you can see the diffs to the previous version clearly. I understand that branch to be our place to work things out, so I'm happy to make a separate PR into main if we are happy with how get_tune_schedule() looks. I think the tests could also make use of that separation of the stages into smaller scheduling functions, but I didn't do this here because I wanted you to see how the tests changed for this refactor.

Totally makes sense, thanks! I'm definitely on board for the workflow of taking chunks of that PR and refactoring + reviewing more in-detail and then sending those smaller portions into main as we do so.

Just eyeballing the diffs, it looks like this PR still makes use of the UseSpacesForTab: No setting. I see that it probably makes sense to keep that setting around to prevent conflicts with—and more easily diff against—tune-schedule, but I'd advocate for reverting back to UseSpacesForTab: Yes and reformatting the smaller chunks at some point before we send them into main. I can imagine a couple different ways that workflow could look (wait to reformat, merge into tune-schedule, reformat that whole PR to line up with the rest of the repo, extract out the relevant bits and merge to main?), but whatever results in the least work for the implementer has a thumbs-up from me.

@hfrick hfrick requested review from topepo and simonpcouch January 17, 2025 15:40
Copy link
Contributor

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very readable, very concise. A huge step up from compute_grid_info() or any of its refactors. Got a lot of joy from reviewing this one—bravo to yall!

+1 to working in some tests at the level of the newly separate functions, but fine with me to wait for a separate PR to make that happen.

Huzzah🙆

Copy link
Member

@topepo topepo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, since I forgot to say it in the review... this looks great. Big improvement on may refactor.

@hfrick
Copy link
Member Author

hfrick commented Feb 25, 2025

Can't comment directly on the line, so putting this here:

While thinking about param_info in the signature of schedule_stages(), I realized that we do not need the parameter set param here as an input.

What we do need is the grid to schedule, the info which parameter belongs to which stage, and the info which parameters are submodel paramters. For that last one, we need to know the model type and we deduct that from the workflow. The info which parameter belongs to which stage we originally pulled from the paramter set, that's why it's (still) in the function signature here.

But we can get that info also from the workflow, via tune_args(), which is what I've done here. My reasons for that:

  • If someone provides a workflow with tune() tags and a corresponding grid, there is no (conceptual) need for a dials parameter set. Hence, me not wanting to rely on one.
  • If someone provides a custom parameter set, they still need to tag parameters via tune() in the workflow spec for anything to be tuned. Therefore, we can rely on the workflow via tune_args() and don't need a parameter set.

Therefore, my suggestion is use only grid and wflow in the signature here.

hfrick added a commit that referenced this pull request Mar 3, 2025
@topepo
Copy link
Member

topepo commented Mar 10, 2025

Should this be closed since # #988 was merged?

@hfrick
Copy link
Member Author

hfrick commented Mar 10, 2025

yes!

@hfrick hfrick closed this Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants