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

add irace #227

Merged
merged 45 commits into from
Mar 19, 2021
Merged

add irace #227

merged 45 commits into from
Mar 19, 2021

Conversation

RaphaelS1
Copy link

  • Adds TunerIrace
  • Adds irace dependency
  • Adds irace_helpers.R for helper functions to make TunerIrace a bit neater
  • Adds tests for TunerIrace

Also changed the template very slightly to include all three constructor methods. If you dislike this let me know and I'll revert back.

R/TunerIrace.R Outdated Show resolved Hide resolved
R/TunerIrace.R Outdated Show resolved Hide resolved
R/irace_helpers.R Outdated Show resolved Hide resolved
R/irace_helpers.R Outdated Show resolved Hide resolved
R/irace_helpers.R Outdated Show resolved Hide resolved
R/irace_helpers.R Outdated Show resolved Hide resolved
R/TunerIrace.R Show resolved Hide resolved
R/irace_helpers.R Outdated Show resolved Hide resolved
R/irace_helpers.R Outdated Show resolved Hide resolved
irace::readParameters(text = par.tab)
}
getIraceRange = function(ps){
rng = data.table(lower = ps$lower, upper = ps$upper, lvl = ps$levels)
Copy link
Collaborator

Choose a reason for hiding this comment

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

as.data.table() should be enough

Copy link
Author

Choose a reason for hiding this comment

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

What do you mean by enough?

Copy link
Collaborator

Choose a reason for hiding this comment

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

you can probably do something with

as.data.table(ps)[, ifelse(is.na(lower),
  <whatever paste collapse 'levels'>,
  paste0("(", lower, ",", upper, ")"))]

Copy link
Author

Choose a reason for hiding this comment

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

Do you know the best way to collapse lists with some elements characters and some not?

as.data.table(ps)[,ifelse(is.na(lower),
                            paste0("(",paste0(levels, collapse = ","),")"),
                            paste0("(",lower,",",upper,")"))]

Doesn't work as it collapses all levels and ignores the `ifelse, e.g. I got:

"c(TRUE, FALSE),NULL,c(\"lvl1\", \"lvl2\"),NULL" "(1,9)" 

Copy link
Collaborator

Choose a reason for hiding this comment

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

add by = id and use levels[[1]]:

as.data.table(ps(x = p_dbl(1, 4), y = p_lgl()))[,
  ifelse(is.na(lower),
    paste0("(",paste0(levels[[1]], collapse = ","),")"),
    paste0("(",lower,",",upper,")")),
  by = "id"]$V1
#> [1] "(1,4)"        "(TRUE,FALSE)"

@berndbischl
Copy link
Member

some small comments for now:

  • i dislike that you are tagging every irace-control param with "irace". just to be able to add the meta-param "show.irace.output". can we somehow get around this?
  • your coding style is in many place not mlr3-complaint (arrow, spaces, camel-case, etc). pls fix now
  • you need to set
    properties = "dependencies"
    to tell the tuner that it can handle dependent params

@berndbischl
Copy link
Member

  • please unit-test paradox_to_irace separately
  • mlr2 had a lot of unit tests for irace. copy most of them over if possible please

@codecov-io
Copy link

codecov-io commented Mar 10, 2020

Codecov Report

❗ No coverage uploaded for pull request base (main@83d8022). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #227   +/-   ##
=======================================
  Coverage        ?   92.30%           
=======================================
  Files           ?       20           
  Lines           ?      390           
  Branches        ?        0           
=======================================
  Hits            ?      360           
  Misses          ?       30           
  Partials        ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 83d8022...45ef598. Read the comment docs.

tests/testthat/test_TunerIrace.R Outdated Show resolved Hide resolved
tests/testthat/test_TunerIrace.R Outdated Show resolved Hide resolved
@RaphaelS1
Copy link
Author

i dislike that you are tagging every irace-control param with "irace". just to be able to add the meta-param "show.irace.output". can we somehow get around this?
your coding style is in many place not mlr3-complaint (arrow, spaces, camel-case, etc). pls fix now
you need to set
properties = "dependencies"
to tell the tuner that it can handle dependent params

Done, done, done.

please unit-test paradox_to_irace separately
mlr2 had a lot of unit tests for irace. copy most of them over if possible please

Done - Need to check how dependencies are working though. I'm unsure if some tests working as expected. Also added a few dependencies to suggests that could be removed if needed by changing tested learners

@RaphaelS1
Copy link
Author

Shall we try to finish, merge and close this PR? @mb706 @berndbischl . Open questions seem to be about correctly setting instances to match mlr3tuning to irace design

@jakob-r
Copy link
Member

jakob-r commented Jun 15, 2020

We should first merge #240 and then I will probably have to adapt this PR to the API changes.

@RaphaelS1 RaphaelS1 marked this pull request as draft June 15, 2020 15:51
@RaphaelS1
Copy link
Author

We should first merge #240 and then I will probably have to adapt this PR to the API changes.

okay great, I've converted to a draft for now

@RaphaelS1
Copy link
Author

@jakob-r after the merge from #240 (and probably many others since then), what needs to change in this PR?

@jakob-r
Copy link
Member

jakob-r commented Dec 8, 2020

Have you merged the master into your branch, check that tests are complete and running, mark this PR as ready for review and we will merge it if everyhting is fine.

@RaphaelS1 RaphaelS1 marked this pull request as ready for review December 8, 2020 22:37
@RaphaelS1
Copy link
Author

RaphaelS1 commented Dec 8, 2020

Okay so pinging everyone who replied above many months ago: @jakob-r @be-marc @mb706

I've merged in Master and got it working, however there seems to be a problem upstream causing warnings ('partial match') you can see it on all the builds. For most of the tests I can handle this with suppressWarnings but I can't do this on the primary autotest. The hacky fix would be to catch irace in the autotest and then wrap the public optimize method in suppressWarningsbut that's up to you. I'm 99% sure the problem isn't our side because we don't use length as an argument in a package (grep), but let me know if wrong.

About the tuner itself, some things I'd appreciate double checking before merging, sorry I don't know the internals of mlr3tuning or irace well so a lot of my implementation is unfortunately guesswork:

  1. Is the use of instance correct and concordant with the use in the irace packages? See conversations about this
  2. Currently it's only set-up to work with TerminatorEvals and TerminatorRunTime as the parameters of these are passed to the maxExperiments and maxTime arguments in the irace scenario (see make_scenario in irace_helpers.R), i) do you agree with this?; ii) what does this mean for other terminators? i.e. will they just not work here or do we have to add them in some other way?
  3. Can someone confirm that they agree that minimizing time will work as expected? See lines 43-52 in test_TunerIrace.R for an example
  4. Follow-up from the conversation I had with @mb706 above regarding assign_result, does this still need updating or will the result automatically returned be the 'correct one'. Sorry I'm not very clear here but I'm also not sure at all about the internal of mlr3tuning so it's hard for me to know how the 'best' configuration is returned at the end of tuning (same with irace not sure how this works internally).

Thanks for the help with this

EDIT: For some reason the warnings didn't show up in the tests this time, so it's possibly stochastic? Which seems weird given the nature of the warnings in the previous tests, either way looks good now.

@mllg
Copy link
Member

mllg commented Dec 9, 2020

I've merged in Master and got it working, however there seems to be a problem upstream causing warnings ('partial match') you can see it on all the builds. For most of the tests I can handle this with suppressWarnings but I can't do this on the primary autotest. The hacky fix would be to catch irace in the autotest and then wrap the public optimize method in suppressWarningsbut that's up to you. I'm 99% sure the problem isn't our side because we don't use length as an argument in a package (grep), but let me know if wrong.

These checks are enabled by our setup.R, i.e. https://github.com/mlr-org/mlr3tuning/blob/master/tests/testthat/setup.R#L4.

You can temporarily disable them if required.

@be-marc
Copy link
Member

be-marc commented Jan 15, 2021

I added a new unit test with TerminatorRunTime that seems to run stable. The PR is ready for a review.
The unit test with TerminatorRunTime is still not stable. It rarely fails and is difficult to reproduce. If irace::irace does not return a result, we throw the error message irace::irace did not return a result. The evaluated configurations are still accessible through the archive. The unit test wraps tuner$optimize(instance) in a try statement to avoid failing tests. We just check if the archive has evaluated configurations. Does anyone have a better idea?

Copy link
Member

@jakob-r jakob-r left a comment

Choose a reason for hiding this comment

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

Thanks for the effort. Looks good for the most part. Have we discussed it this would be worth an extra package?

R/ObjectiveTuning.R Show resolved Hide resolved
R/ObjectiveTuning.R Outdated Show resolved Hide resolved
R/TunerIrace.R Show resolved Hide resolved
R/TunerIrace.R Outdated Show resolved Hide resolved
R/TunerIrace.R Show resolved Hide resolved
R/TunerIrace.R Outdated Show resolved Hide resolved
R/TunerIrace.R Show resolved Hide resolved
R/irace_helpers.R Outdated Show resolved Hide resolved
R/irace_helpers.R Outdated Show resolved Hide resolved
@jakob-r
Copy link
Member

jakob-r commented Jan 18, 2021

I added a new unit test with TerminatorRunTime that seems to run stable. The PR is ready for a review.
The unit test with TerminatorRunTime is still not stable. It rarely fails and is difficult to reproduce. If irace::irace does not return a result, we throw the error message irace::irace did not return a result. The evaluated configurations are still accessible through the archive. The unit test wraps tuner$optimize(instance) in a try statement to avoid failing tests. We just check if the archive has evaluated configurations. Does anyone have a better idea?

Does it fail bc. irace is taking a tiny bit longer than the terminator is allowing?

@be-marc
Copy link
Member

be-marc commented Jan 18, 2021

Our documentation stated

Uninstantiated resamplings are instantiated during construction so that all configurations are evaluated on the same data splits.

I added

If a new resampling is passed, it is instantiated with new data splits. Already instantiated resamplings are kept unchanged.

@be-marc
Copy link
Member

be-marc commented Jan 18, 2021

Does it fail bc. irace is taking a tiny bit longer than the terminator is allowing?

It does not fail often. We substract 5 seconds now. Maybe it helps.

Base automatically changed from master to main January 25, 2021 19:30
@be-marc be-marc mentioned this pull request Jan 27, 2021
R/TunerIrace.R Outdated Show resolved Hide resolved
@be-marc
Copy link
Member

be-marc commented Feb 4, 2021

Closes #63

warnPartialMatchAttr = TRUE,
warnPartialMatchDollar = TRUE
)
# The upstream package causes partial match warnings
Copy link
Member

Choose a reason for hiding this comment

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

Which one?

Copy link
Member

Choose a reason for hiding this comment

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

irace uses rep with length instead of length.out

Copy link
Member

Choose a reason for hiding this comment

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

Reported upstream MLopez-Ibanez/irace#7.

Choose a reason for hiding this comment

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

For what is worth, this issue is now fixed upstream so you should be able to re-enable the warnings. We, the irace team (which is basically 2 people doing both teaching and research), are happy to receive issues and pull requests for fixes like these but also for changes that simplify integration with mlr (or other packages).

@jakob-r
Copy link
Member

jakob-r commented Mar 19, 2021

I think this can be merged. Any objections?

@be-marc be-marc merged commit 5248176 into main Mar 19, 2021
@be-marc be-marc deleted the irace branch March 19, 2021 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants