Last active
April 1, 2020 16:32
-
-
Save pat-s/938d5642573107654e09c9884dd3bc28 to your computer and use it in GitHub Desktop.
add mlr3learners Paramtest
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
fs::dir_create("inst/paramtest", recurse = TRUE) | |
writeLines('on: | |
push: | |
pull_request: | |
# for now, CRON jobs only run on the default branch of the repo (i.e. usually on master) | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
- cron: "0 4 * * *" | |
name: Parameter Check | |
jobs: | |
R-CMD-check: | |
runs-on: ${{ matrix.config.os }} | |
name: ${{ matrix.config.os }} (${{ matrix.config.r }}) | |
strategy: | |
fail-fast: false | |
matrix: | |
config: | |
- { os: ubuntu-latest, r: "release", paramtest: "true" } | |
env: | |
# otherwise remotes::fun() errors cause the build to fail. Example: Unavailability of binaries | |
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true | |
CRAN: ${{ matrix.config.cran }} | |
# we are not allowed to write to ~/.ccache on GH Actions | |
# setting some ccache options | |
CCACHE_BASEDIR: ${{ GITHUB.WORKSPACE }} | |
CCACHE_DIR: ${{ GITHUB.WORKSPACE }}/.ccache | |
CCACHE_NOHASHDIR: true | |
CCACHE_SLOPPINESS: include_file_ctime | |
# make sure to run `tic::use_ghactions_deploy()` to set up deployment | |
id_rsa: ${{ secrets.id_rsa }} | |
# env for ParamTest | |
PARAMTEST: ${{ matrix.config.paramtest }} | |
# prevent rgl issues because no X11 display is available | |
RGL_USE_NULL: true | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: r-lib/actions/setup-r@master | |
with: | |
r-version: ${{ matrix.config.r }} | |
Ncpus: 4 | |
# set date/week for use in cache creation | |
# https://git.521000.bestmunity/t5/GitHub-Actions/How-to-set-and-access-a-Workflow-variable/m-p/42970 | |
# - cache R packages daily | |
# - cache ccache weekly -> \'ccache\' helps rebuilding the package cache faster | |
- name: "[Cache] Prepare daily timestamp for cache" | |
if: runner.os != \'Windows\' | |
id: date | |
run: echo "::set-output name=date::$(date \'+%d-%m\')" | |
- name: "[Cache] Prepare weekly timestamp for cache" | |
if: runner.os != \'Windows\' | |
id: datew | |
run: echo "::set-output name=datew::$(date \'+%Y-%V\')" | |
- name: "[Cache] Cache R packages" | |
if: runner.os != \'Windows\' | |
uses: pat-s/[email protected] | |
with: | |
path: ${{ env.R_LIBS_USER }} | |
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}-1 | |
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}-1 | |
- name: "[Cache] Cache ccache" | |
if: runner.os != \'Windows\' | |
uses: pat-s/[email protected] | |
with: | |
path: ${{ env.CCACHE_DIR}} | |
key: ${{ runner.os }}-r-${{ matrix.config.r }}-ccache-${{steps.datew.outputs.datew}} | |
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-ccache-${{steps.datew.outputs.datew}} | |
# install ccache and write config file | |
- name: "[Linux] ccache" | |
if: runner.os == \'Linux\' | |
run: | | |
sudo apt install ccache libcurl4-openssl-dev | |
mkdir -p ~/.R && echo -e \'CXX_STD = CXX14\\n\\nCC=ccache gcc -std=gnu99\\nCXX=ccache g++\\nCXX11=ccache g++ -std=gnu99\\nCXX14=ccache g++ -std=gnu99\\nC11=ccache g++\\nC14=ccache g++\\nFC=ccache gfortran\\nF77=ccache gfortran\' > $HOME/.R/Makevars | |
# for some strange Windows reason this step and the next one need to be decoupled | |
- name: "[Stage] Prepare" | |
run: | | |
Rscript -e "if (!requireNamespace(\'remotes\')) install.packages(\'remotes\', type = \'source\')" | |
Rscript -e "if (getRversion() < \'3.2\' && !requireNamespace(\'curl\')) install.packages(\'curl\', type = \'source\')" | |
- name: "[Stage] Install" | |
if: matrix.config.os != \'macOS-latest\' || matrix.config.r != \'devel\' | |
run: Rscript -e "remotes::install_github(\'ropensci/tic\')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()" | |
- name: "[Stage] Parameter test" | |
run: | | |
R CMD INSTALL . | |
Rscript -e "tic::script()"', | |
".github/workflows/paramtest.yml") | |
writeLines('# R CMD check | |
if (!ci_has_env("PARAMTEST")) { | |
do_package_checks() | |
do_drat("mlr3learners/mlr3learners.drat") | |
} else { | |
# PARAMTEST | |
get_stage("install") %>% | |
add_step(step_install_deps()) | |
get_stage("script") %>% | |
add_code_step(remotes::install_dev("mlr3")) %>% | |
add_code_step(testthat::test_dir(system.file("paramtest", package = "<package>"), | |
stop_on_failure = TRUE)) | |
}', "tic.R") | |
writeLines('library(mlr3) | |
lapply(list.files(system.file("testthat", package = "mlr3"), | |
pattern = "helper_autotest", full.names = TRUE), source)', | |
"inst/paramtest/helper.R") | |
writeLines('library(mlr3learners.<package>) | |
test_that("<type>.<algorithm>", { | |
learner = lrn("<type>.<algorithm>") | |
fun = <package>::<algorithm> # replace! | |
exclude = c( | |
# Examples how to exclude certain parameters. Always comment why a parameter | |
# was excluded! | |
"formula", # handled via mlr3 | |
"data", # handled via mlr3 | |
"weights", # handled via mlr3 | |
"control", # handled to mboost::boost_control | |
"..." # not used | |
) | |
ParamTest = run_paramtest(learner, fun, exclude) | |
expect_true(ParamTest, info = paste0("\nMissing parameters:\n", | |
paste0("- \'", ParamTest$missing,"\'", collapse = "\n"))) | |
}) | |
# example for checking a "control" function of a learner | |
test_that("<type>.<algorithm>_control", { | |
learner = lrn("<type>.<algorithm>") | |
fun = <package>::boost_control # replace! | |
exclude = c( | |
"center", # deprecated | |
) | |
ParamTest = run_paramtest(learner, fun, exclude) | |
expect_true(ParamTest, info = paste0("\nMissing parameters:\n", | |
paste0("- \'", ParamTest$missing,"\'", collapse = "\n"))) | |
})', "inst/paramtest/test_paramtest_<type>.<algorithm>.R") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment