Skip to contents

Serialises a pigauto_fit object to disk, including the torch model state, for later loading with load_pigauto(). Matching pigauto versions alone do not guarantee cross-version or cross-platform compatibility.

Usage

save_pigauto(fit, path, compress = TRUE)

Arguments

fit

pigauto_fit object, or a pigauto_result from impute (its $fit is saved).

path

character. File path to save to (recommended extension: .pigauto).

compress

logical. Use gzip compression (default TRUE).

Value

Invisible path.

Details

Use save_pigauto() and load_pigauto() as the package's save/load interface. For GNN fits containing torch tensors, native saveRDS() / readRDS() does not preserve a usable tensor state; this function serialises that state before saving. pigauto checks its package version after loading the tensors, but does not check R, torch/LibTorch, or operating-system compatibility. Retain the software environment used to save the fit and verify loading and predictions in the destination environment. GNN-off fits have an empty model state and do not use this tensor serialization path.

Examples

# \donttest{
data(avonet300, tree300)
tree <- ape::keep.tip(tree300, tree300$tip.label[seq_len(30L)])
traits <- avonet300[match(tree$tip.label, avonet300$Species_Key),
                     c("Mass", "Wing.Length"), drop = FALSE]
rownames(traits) <- tree$tip.label
traits$Mass[seq_len(3L)] <- NA_real_
fit <- impute(traits, tree, epochs = 5L, verbose = FALSE)$fit
#> Warning: Small validation set for 2 trait(s): Mass (n=2), Wing.Length (n=5). Calibrated gate and conformal scores will be noisy for these trait(s). 95% split-conformal coverage is NOT achievable for 2 trait(s) with fewer than 19 validation cells (Mass (n=2), Wing.Length (n=5)): the achievable ceiling is n_val / (n_val + 1), which only reaches 0.95 at n_val >= 19. See `?fit_pigauto` under 'Calibration at small n' for smoothing options.
path <- tempfile(fileext = ".pigauto")
suppressMessages(save_pigauto(fit, path))
fit2 <- load_pigauto(path)
# }