mlr-org / mlr-org/batchtools

scoping errors depending on objects in global environment

Open
#275 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
184
Forks
53
Avg merge
7d 2h
Merged PRs (30d)
1

Description

I recently stumbled across the following rather weird behavior:
If a custom function named eval is present in my .GlobalEnv, testing jobs with external = TRUE and potentially also submitting will fail:

library(batchtools)  # 0.9.15
library(data.table)

reg = makeExperimentRegistry(file.dir = NA, seed = 1)

addProblem(name = "test", fun = function(...) list(...), seed = 2)

eval_ = function(data, job, instance, ...) {
  xs = list(...)
  1 + xs$x1
}

eval = function(...) list(...)

addAlgorithm(name = "eval_", fun = eval_)

pdes = list(test = data.table())
ades = list(eval_ = data.table(x1 = c(1, 2)))
addExperiments(pdes, ades, repls = 1)

testJob(1)
#### [bt]: Generating problem instance for problem 'test' ...
#### [bt]: Applying algorithm 'eval_' on problem 'test' for job 1 (seed = 2) ...
#[1] 2

testJob(1, external = TRUE)
# Error: testJob() failed for job with id=1. To properly debug, re-run with external=FALSE

rm(eval)

testJob(1, external = TRUE)
### [bt]: Generating problem instance for problem 'test' ...
### [bt]: Applying algorithm 'eval_' on problem 'test' for job 1 (seed = 2) ...
[1] 2

Initially, the algorithm was named eval and I thought this caused the problem, however, it seems like it suffices to have a custom function eval present in the .GlobalEnv. My initial guess would be that this interferes with properly scoping base::eval at some later stages (not sure why though).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with testJob(1, external = TRUE) while a custom eval exists in .GlobalEnv, then compare it with external = FALSE and after rm(eval). Trace the external job path and its evaluation scoping; done means the external run succeeds despite the global eval function, while the shown behavior remains reproducible as a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
hpc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.