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)) {
        return(get_private(self$instance$objective)$.xs)
      } else {
        self$instance$objective$.__enclos_env__$private$.xs = rhs
      }
    },

    #' @field resample_result ([mlr3::BenchmarkResult])\cr
    #' The resample result of the hyperparameter configuration currently evaluated.
    resample_result = function(rhs) {
      if (missing(rhs)) {
        return(get_private(self$instance$objective)$.resample_result)
      } else {
        self$instance$objective$.__enclos_env__$private$.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)) {
        return(get_private(self$instance$objective)$.aggregated_performance)
      } else {
        self$instance$objective$.__enclos_env__$private$.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)) {
        return(get_private(self$instance)$.result_learner_param_vals)
      } else {
        self$instance$.__enclos_env__$private$.result_learner_param_vals = rhs
      }
    }
  )
)
mlr-org/mlr3tuning documentation built on April 14, 2025, 1 a.m.