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()
A list of data frames with profiling data if the profiling CSV files were created.
# \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 likelihood 0x7ff85af4eb00 0.001158940 0.000848855 0.00031008 6721
#> 2 gq 0x7ff85af4eb00 0.000444795 0.000444795 0.00000000 0
#> no_chain_stack autodiff_calls no_autodiff_calls
#> 1 6721 6721 1
#> 2 0 0 1000
#>
#> [[2]]
#> name thread_id total_time forward_time reverse_time chain_stack
#> 1 likelihood 0x7ff85af4eb00 0.001207200 0.000885927 0.000321272 6792
#> 2 gq 0x7ff85af4eb00 0.000453808 0.000453808 0.000000000 0
#> no_chain_stack autodiff_calls no_autodiff_calls
#> 1 6792 6792 1
#> 2 0 0 1000
#>
#> [[3]]
#> name thread_id total_time forward_time reverse_time chain_stack
#> 1 likelihood 0x7ff85af4eb00 0.001181750 0.000860407 0.000321346 6835
#> 2 gq 0x7ff85af4eb00 0.000418544 0.000418544 0.000000000 0
#> no_chain_stack autodiff_calls no_autodiff_calls
#> 1 6835 6835 1
#> 2 0 0 1000
#>
#> [[4]]
#> name thread_id total_time forward_time reverse_time chain_stack
#> 1 likelihood 0x7ff85af4eb00 0.001272150 0.000927098 0.000345053 6955
#> 2 gq 0x7ff85af4eb00 0.000416536 0.000416536 0.000000000 0
#> no_chain_stack autodiff_calls no_autodiff_calls
#> 1 6955 6955 1
#> 2 0 0 1000
#>
# }