Skip to content

Evaluating an initial design while providing a callback causes errors from unrelated callback #141

Open
@larskotthoff

Description

@larskotthoff
require(data.table)
require(mlr3mbo)
require(bbotk)

callback_plot = callback_optimization("plot",
  on_optimizer_after_eval = function(callback, context) {
  }
)

obfun = ObjectiveRFun$new(
  fun = function(xs) 2 * xs$x * sin(14 * xs$x),
  domain = ps(x = p_dbl(lower = 0, upper = 1)),
  codomain = ps(y = p_dbl(tags = "minimize")))

instance = OptimInstanceSingleCrit$new(
  objective = obfun,
  terminator = trm("evals", n_evals = 20),
  callbacks = callback_plot)
initial_design = data.table(x = c(0, 0.5, 1))
instance$eval_batch(initial_design)
```

gives me

````R
Error in call_back("on_optimizer_before_eval", self$callbacks, private$.context) : 
  Assertion on 'context' failed: Must inherit from class 'Context', but has class 'NULL'.
Calls: <Anonymous> ... call_back -> assert_class -> makeAssertion -> mstop
Execution halted

Note that the callback specified is on_optimizer_after_eval and the error comes from on_optimizer_before_eval (the same error would probably come from the specified callback as well though).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions