Closed Aariq closed 2 months ago
I'm stumped on this one. As a workaround, setting deployment = "main"
allows this to work.
Hmmm... getting this same bug with a tar_terra_rast()
target that subsets a multi-layer SpatRaster and does some calculations with app()
. Works interactively, works with deployment = "main"
, but errors with multiple workers
Ok, I suspect the reason for this has something to do with how marshaling works with branching. In this example, rast_plus
is a list, which can't be wrap()
ed. I think we really need an iteration = "terra_layers"
or something that does branching with [[]]
and aggregation with terra::c()
.
I think you might be right there with some kind of nice iteration
handler for geotargets
. I can take a look at this later this week/end
Unable to reproduce this with just crew
, although I'm not certain that this is equivalent to how targets
and crew
interact with marshaling/unmarshaling.
library(crew)
library(terra)
#> terra 1.7.71
library(purrr)
controller <- crew_controller_local(
name = "example",
workers = 2,
seconds_idle = 10
)
controller$start()
marshal <- terra::wrap
unmarshal <- terra::unwrap
rast_list <- list(a = marshal(terra::rast(system.file("ex/logo.tif", package = "terra"))),
b = marshal(terra::rast(system.file("ex/logo.tif", package = "terra")) + 1))
#goal is to combine rast list like so:
terra::rast(purrr::map(rast_list, unmarshal))
#> class : SpatRaster
#> dimensions : 77, 101, 6 (nrow, ncol, nlyr)
#> resolution : 1, 1 (x, y)
#> extent : 0, 101, 0, 77 (xmin, xmax, ymin, ymax)
#> coord. ref. : Cartesian (Meter)
#> source(s) : memory
#> names : a_1, a_2, a_3, b_1, b_2, b_3
#> min values : 0, 0, 0, 1, 1, 1
#> max values : 255, 255, 255, 256, 256, 256
controller$push(
name = "combine",
command = marshal(terra::rast(purrr::map(rast_list, unmarshal))),
data = list(rast_list = rast_list, marshal = marshal, unmarshal = unmarshal)
)
controller$wait(mode = "all")
result <- controller$pop()
result$result |> map(unmarshal)
#> [[1]]
#> class : SpatRaster
#> dimensions : 77, 101, 6 (nrow, ncol, nlyr)
#> resolution : 1, 1 (x, y)
#> extent : 0, 101, 0, 77 (xmin, xmax, ymin, ymax)
#> coord. ref. : Cartesian (Meter)
#> source(s) : memory
#> names : a_1, a_2, a_3, b_1, b_2, b_3
#> min values : 0, 0, 0, 1, 1, 1
#> max values : 255, 255, 255, 256, 256, 256
Created on 2024-04-12 with reprex v2.1.0
This was caused by a marshaling bug in targets
: https://github.com/ropensci/targets/issues/1266. Fixed in https://github.com/ropensci/targets/pull/1267.
Confirmed that this works now! Thanks @wlandau!
I'm encountering a bug when trying to combine a list of rasters created by dynamic branching. It seems related to marshaling, since the error message mentions
wrap()
and I only get the error with multiplecrew
workers, but not sure.Created on 2024-04-09 with reprex v2.1.0