ropensci / stantargets

Reproducible Bayesian data analysis pipelines with targets and cmdstanr
https://docs.ropensci.org/stantargets
Other
47 stars 9 forks source link

Expose .cores argument for summary #52

Closed stuvet closed 1 year ago

stuvet commented 2 years ago

Prework

Proposal

posterior::summarise_draws has a .cores option which offers big speedups for summarising larger posteriors. Currently it is not accessible via summary_args.

It'd be very helpful to expose a summary_cores option to tar_stan_summary and tar_stan_mcmc, which could default to 1 to match posterior::summarise_draws defaults. In my fork I've included parallel::detectCores triggered by summary_cores = NULL. I was half way through submitting it as a PR, but saw the prework so raised here first. Currently tested with tar_make_future on slurm (need to set appropriate ncpus in the default resources if called from tar_stan_mcmc).

Happy to submit it as a PR if you'd like, but you may forsee problems that I can't.

Thanks

wlandau commented 2 years ago

Sounds great to me. Would you open a PR? Would be great to have summary_cores argument wherever there is summary_args, which includes the gq, mle, and vb functions as well as the mcmc ones.

stuvet commented 2 years ago

Ah yes, I didn't think about the other options, but I'm just starting to use gq & it'll be very welcome here too. I'll add them all & submit in a sec.

wlandau commented 1 year ago

@stuvet, I actually think you can supply the number of cores to the summary_args argument, e.g. tar_stan_mcmc_rep_summary(..., summary_args = list(.cores = 4)). The summary_args argument populates the ... argument of the summary() method of CmdStanFit objects, which then gets forwarded to posterior::summarize_draws().