Skip to content

model compiled with model methods fails to fit with future multisession #1090

@n-kall

Description

@n-kall

Describe the bug

Trying to precompile model methods via compile_model_methods = TRUE (to be used after fitting) causes the fits to fail if using future.plan(multisession)

Error in .Call(<pointer: (nil)>, data_path, seed) : 
  NULL value passed as symbol address

To Reproduce

library(cmdstanr)

library(future)
library(future.apply)

plan(multisession)

m <- cmdstan_model(
  write_stan_file(
    paste0(capture.output(print_example_program()), collapse = "")
  ),
  compile_model_methods = TRUE
)

dat <- list(N = 3, K = 1, y = c(1, 0, 0), X = matrix(c(1, 1, 1), nrow = 3))

future_lapply(1:3, function(x) m$sample(data = dat), future.seed = TRUE)

Expected behavior
Sampling should work as expected, or if additional arguments are needed (e.g. for globals?) then guidance in documentation could help

Operating system
ubuntu 24.04

CmdStanR version number
0.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions