The $profiles() method returns a list of data frames with profiling data if any profiling data was written to the profile CSV files. See save_profile_files() to control where the files are saved.

Support for profiling Stan programs is available with CmdStan >= 2.26 and requires adding profiling statements to the Stan program.

profiles()

Value

A list of data frames with profiling data if the profiling CSV files were created.

Examples


# \dontrun{
# first fit a model using MCMC
mcmc_program <- write_stan_file(
  'data {
    int<lower=0> N;
    array[N] int<lower=0,upper=1> y;
  }
  parameters {
    real<lower=0,upper=1> theta;
  }
  model {
    profile("likelihood") {
      y ~ bernoulli(theta);
    }
  }
  generated quantities {
    array[N] int y_rep;
    profile("gq") {
      y_rep = bernoulli_rng(rep_vector(theta, N));
    }
  }
'
)
mod_mcmc <- cmdstan_model(mcmc_program)

data <- list(N = 10, y = c(1,1,0,0,0,1,0,1,0,0))
fit <- mod_mcmc$sample(data = data, seed = 123, refresh = 0)
#> Running MCMC with 4 sequential chains...
#> 
#> Chain 1 finished in 0.0 seconds.
#> Chain 2 finished in 0.0 seconds.
#> Chain 3 finished in 0.0 seconds.
#> Chain 4 finished in 0.0 seconds.
#> 
#> All 4 chains finished successfully.
#> Mean chain execution time: 0.0 seconds.
#> Total execution time: 0.6 seconds.
#> 

fit$profiles()
#> [[1]]
#>         name      thread_id  total_time forward_time reverse_time chain_stack
#> 1         gq 0x7ff858f85100 0.000442373  0.000442373  0.000000000           0
#> 2 likelihood 0x7ff858f85100 0.001250430  0.000907142  0.000343284        6721
#>   no_chain_stack autodiff_calls no_autodiff_calls
#> 1              0              0              1000
#> 2           6721           6721                 1
#> 
#> [[2]]
#>         name      thread_id  total_time forward_time reverse_time chain_stack
#> 1         gq 0x7ff858f85100 0.000468161  0.000468161  0.000000000           0
#> 2 likelihood 0x7ff858f85100 0.001255240  0.000911108  0.000344131        6792
#>   no_chain_stack autodiff_calls no_autodiff_calls
#> 1              0              0              1000
#> 2           6792           6792                 1
#> 
#> [[3]]
#>         name      thread_id  total_time forward_time reverse_time chain_stack
#> 1         gq 0x7ff858f85100 0.000458935  0.000458935  0.000000000           0
#> 2 likelihood 0x7ff858f85100 0.001356490  0.000992885  0.000363606        7163
#>   no_chain_stack autodiff_calls no_autodiff_calls
#> 1              0              0              1000
#> 2           7163           7163                 1
#> 
#> [[4]]
#>         name      thread_id  total_time forward_time reverse_time chain_stack
#> 1         gq 0x7ff858f85100 0.000489173  0.000489173  0.000000000           0
#> 2 likelihood 0x7ff858f85100 0.001301980  0.000949488  0.000352494        6979
#>   no_chain_stack autodiff_calls no_autodiff_calls
#> 1              0              0              1000
#> 2           6979           6979                 1
#> 
# }