R/ContextAsyncTuning.R

#' @title Asynchronous Tuning Context
#'
#' @description
#' A [CallbackAsyncTuning] accesses and modifies data during the optimization via the `ContextAsyncTuning`.
#' See the section on active bindings for a list of modifiable objects.
#' See [callback_async_tuning()] for a list of stages that access `ContextAsyncTuning`.
#'
#' @details
#' Changes to `$instance` and `$optimizer` in the stages executed on the workers are not reflected in the main process.
#'
#' @template param_inst_async
#' @template param_tuner
#'
#' @export
ContextAsyncTuning = R6Class(
  "ContextAsyncTuning",
  inherit = ContextAsync,
  active = list(
    #' @field xs_learner (list())\cr
    #' The hyperparameter configuration currently evaluated.
    #' Contains the values on the learner scale i.e. transformations are applied.
    xs_learner = function(rhs) {
      if (missing(rhs)) {
        get_private(self$instance$objective)$.xs
      } else {
        get_private(self$instance$objective, ".xs") = rhs
      }
    },

    #' @field resample_result ([mlr3::ResampleResult])\cr
    #' The resample result of the hyperparameter configuration currently evaluated.
    resample_result = function(rhs) {
      if (missing(rhs)) {
        get_private(self$instance$objective)$.resample_result
      } else {
        get_private(self$instance$objective, ".resample_result") = rhs
      }
    },

    #' @field aggregated_performance (`list()`)\cr
    #' Aggregated performance scores and training time of the evaluated hyperparameter configuration.
    #' This list is passed to the archive.
    #' A callback can add additional elements which are also written to the archive.
    aggregated_performance = function(rhs) {
      if (missing(rhs)) {
        get_private(self$instance$objective)$.aggregated_performance
      } else {
        get_private(self$instance$objective, ".aggregated_performance") = rhs
      }
    },

    #' @field result_learner_param_vals (list())\cr
    #' The learner parameter values passed to `instance$assign_result()`.
    result_learner_param_vals = function(rhs) {
      if (missing(rhs)) {
        get_private(self$instance)$.result_learner_param_vals
      } else {
        get_private(self$instance, ".result_learner_param_vals") = rhs
      }
    }
  )
)

Try the mlr3tuning package in your browser

Any scripts or data that you put into this service are public.

mlr3tuning documentation built on Sept. 2, 2026, 5:08 p.m.