wlandau / crew

A distributed worker launcher
https://wlandau.github.io/crew/
Other
123 stars 4 forks source link

crew_controller_group cannot be saved to a variable and used inside _targets.R, but crew_controller_local can #172

Closed stemangiola closed 3 months ago

stemangiola commented 3 months ago

Prework

Description

crew_controller_group cannot be saved to a variable and used inside _targets.R, but crew_controller_local can

Please describe the bug.

Reproducible example

This works


library(targets)
library(tarchetypes)
library(crew)
library(crew.cluster)

tar_option_set(memory = "transient", garbage_collection = TRUE, 
               storage = "worker", retrieval = "worker", format = "qs", 
               debug = readRDS("temp_debug_step.rds"), controller = crew_controller_group(

                 crew_controller_local(
                   name = "tier_1",
                   workers = 2,
                   seconds_idle = 10
                 ),
                 crew_controller_local(
                   name = "tier_2",
                   workers = 2,
                   seconds_idle = 10
                 )
               ), 
               packages = c("HPCell"))
list(tar_target(a, 1, resources = tar_resources(crew = tar_resources_crew("tier_1"))))

If I try to save the controller into a variable first, it fails with core dumped


library(targets)
library(tarchetypes)
library(crew)
library(crew.cluster)

crew_controller_group(

  crew_controller_local(
    name = "tier_1",
    workers = 2,
    seconds_idle = 10
  ),
  crew_controller_local(
    name = "tier_2",
    workers = 2,
    seconds_idle = 10
  )
) |> saveRDS("~/temp.rds")

tar_option_set(memory = "transient", garbage_collection = TRUE, 
               storage = "worker", retrieval = "worker", format = "qs", 
               debug = readRDS("temp_debug_step.rds"), controller = readRDS("~/temp.rds"), 
               packages = c("HPCell"))
list(tar_target(a, 1, resources = tar_resources(crew = tar_resources_crew("tier_1"))))

But if I try to save a simpler controller, not a group, it works


library(targets)
library(tarchetypes)
library(crew)
library(crew.cluster)

  crew_controller_local(
    name = "tier_1",
    workers = 2,
    seconds_idle = 10
  ) |> saveRDS("~/temp.rds")

tar_option_set(memory = "transient", garbage_collection = TRUE, 
               storage = "worker", retrieval = "worker", format = "qs", 
               debug = readRDS("temp_debug_step.rds"), controller = readRDS("~/temp.rds"), 
               packages = c("HPCell"))
list(tar_target(a, 1, resources = tar_resources(crew = tar_resources_crew("tier_1"))))

I would like the second case to work.

Thanks a lot.

wlandau commented 3 months ago

Controllers are designed to operate only within the R session where they are originally created. They are not designed to be saved to disk. If you need to save something to disk to load later, I recommend instead saving the R code you used to generate the controller.