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 printer for callback set #185

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions R/CallbackSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,35 @@ CallbackSet = R6Class("CallbackSet",
#' @field ctx ([`ContextTorch`] or `NULL`)\cr
#' The evaluation context for the callback.
#' This field should always be `NULL` except during the `$train()` call of the torch learner.
ctx = NULL
ctx = NULL,
#' @description
#' Prints the object.
#' @param ... (any)\cr
#' Currently unused.
print = function(...) {
catn(sprintf("<%s>", class(self)[[1L]]))
catn(str_indent("* Stages:", self$stages))
}
),
active = list(
#' @field stages (`character()`)\cr
#' The active stages of this callback set.
stages = function(rhs) {
assert_ro_binding(rhs)
if (is.null(private$.stages)) {
private$.stages = mlr_reflections$torch$callback_stages[
map_lgl(mlr_reflections$torch$callback_stages, function(stage) exists(stage, self, inherits = FALSE))]
}

private$.stages
}

),
private = list(
.stages = NULL,
deep_clone = function(name, value) {
if (name == "ctx" && !is.null(value)) {
stopf("CallbackSet instances must never be cloned unless the ctx is NULL.")
stopf("CallbackSet instances can only be cloned when the 'ctx' is NULL.")
} else {
value
}
Expand Down
27 changes: 27 additions & 0 deletions man/mlr_callback_set.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions man/mlr_callback_set.checkpoint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions man/mlr_callback_set.history.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions man/mlr_callback_set.progress.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/mlr_learners.alexnet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/mlr_learners.mlp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/mlr_learners.torch_featureless.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/mlr_learners_torch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/mlr_learners_torch_image.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/mlr_learners_torch_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/helper_autotest.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,5 @@ autotest_torch_callback = function(torch_callback, check_man = TRUE) {
expect_class(cb_trained, "CallbackSet")
expect_deep_clone(cb_trained, cb_trained$clone(deep = TRUE))
cb_trained$ctx = "placeholder"
expect_error(cb_trained$clone(deep = TRUE), "must never be cloned unless")
expect_error(cb_trained$clone(deep = TRUE), "can only be cloned")
}
Loading