-
-
Notifications
You must be signed in to change notification settings - Fork 87
feat: add mirai parallelization #1314
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
Open
be-marc
wants to merge
23
commits into
main
Choose a base branch
from
mirai
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c6f410a
...
be-marc e79da73
...
be-marc a9fa258
...
be-marc e39c244
...
be-marc b98ad9b
Merge branch 'main' into mirai
be-marc 9ae87a4
...
be-marc 67e6031
...
be-marc c050efa
...
be-marc 1cdcfc7
...
be-marc 597fa9b
...
be-marc 63709a6
...
be-marc 6c45a15
...
be-marc 3d90df8
...
be-marc 8ef3cbb
...
be-marc f511627
...
be-marc 1198a7d
...
be-marc 8437803
...
be-marc e28bc38
...
be-marc 2ee1b76
...
be-marc 2e60779
...
be-marc 5f08eaa
...
be-marc db0af10
...
be-marc 867d128
chore: remotes
be-marc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,6 @@ | |
^cran-comments\.md$ | ||
^CRAN-SUBMISSION$ | ||
^benchmark$ | ||
^attic$ | ||
^.cursor$ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,3 +183,4 @@ revdep/ | |
# misc | ||
Meta/ | ||
Rplots.pdf | ||
.cursor/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
#' @section Parallelization: | ||
#' | ||
#' This function can be parallelized with the \CRANpkg{future} package. | ||
#' One job is one resampling iteration, and all jobs are send to an apply function | ||
#' from \CRANpkg{future.apply} in a single batch. | ||
#' This function can be parallelized with the \CRANpkg{future} or \CRANpkg{mirai} package. | ||
#' One job is one resampling iteration. | ||
#' All jobs are send to an apply function from \CRANpkg{future.apply} or `mirai::mirai_map()` in a single batch. | ||
#' To select a parallel backend, use [future::plan()]. | ||
#' To use `mirai`, call `mirai::daemons()` before calling this function. | ||
#' The `future` package guarantees reproducible results independent of the parallel backend. | ||
#' The results of `mirai` will not be the same but can be made reproducible by setting a `seed` and `dispatcher = FALSE` when calling `mirai::daemons()`. | ||
#' More on parallelization can be found in the book: | ||
#' \url{https://mlr3book.mlr-org.com/chapters/chapter10/advanced_technical_aspects_of_mlr3.html} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
skip_if_not_installed("mirai") | ||
|
||
test_that("parallel resample", { | ||
with_mirai({ | ||
task = tsk("pima") | ||
learner = lrn("classif.rpart") | ||
rr = resample(task, learner, rsmp("cv", folds = 3)) | ||
expect_resample_result(rr) | ||
expect_data_table(rr$errors, nrows = 0L) | ||
}) | ||
}) | ||
|
||
test_that("parallel benchmark", { | ||
task = tsk("pima") | ||
learner = lrn("classif.rpart") | ||
|
||
with_mirai({ | ||
bmr = benchmark(benchmark_grid(task, learner, rsmp("cv", folds = 3))) | ||
}) | ||
expect_benchmark_result(bmr) | ||
expect_equal(bmr$aggregate(conditions = TRUE)$warnings, 0L) | ||
expect_equal(bmr$aggregate(conditions = TRUE)$errors, 0L) | ||
}) | ||
|
||
test_that("real parallel resample", { | ||
with_mirai({ | ||
task = tsk("pima") | ||
learner = lrn("classif.rpart") | ||
rr = resample(task, learner, rsmp("cv", folds = 3)) | ||
|
||
expect_resample_result(rr) | ||
expect_data_table(rr$errors, nrows = 0L) | ||
}) | ||
}) | ||
|
||
test_that("data table threads are not changed in main session", { | ||
skip_on_os("mac") # number of threads cannot be changed on mac | ||
skip_on_cran() | ||
|
||
old_dt_threads = getDTthreads() | ||
on.exit({ | ||
setDTthreads(old_dt_threads) | ||
}, add = TRUE) | ||
setDTthreads(2L) | ||
|
||
task = tsk("sonar") | ||
learner = lrn("classif.debug", predict_type = "prob") | ||
resampling = rsmp("cv", folds = 3L) | ||
measure = msr("classif.auc") | ||
|
||
rr1 = with_seed(123, resample(task, learner, resampling)) | ||
expect_equal(getDTthreads(), 2L) | ||
|
||
rr2 = with_seed(123, with_mirai(resample(task, learner, resampling))) | ||
expect_equal(getDTthreads(), 2L) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it call
data.table(...)
? And does it have any chance of getting into conflict with any of the special args ofdata.table()
(e.g.key
,keep.rownames
)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mirai::mirai_map()
only acceptsdata.frame
andmatrix
when you want to map over multiple input.data.table
handles list columns better....
contains the iteration and learner when called byresample()
and additionally task and resampling when called bybenchmark()
.I think no.
future_map
is only called internally.