Internal API Reference¶
The following documents the internal API of CmdStanPy. No guarantees are made about backwards compatibility between minor versions and refactors are expected. If you find yourself needing something exposed here, please open an issue requesting it be added to the public API.
Classes¶
InferenceMetadata¶
- class cmdstanpy.stanfit.InferenceMetadata(config)[source]¶
CmdStan configuration and contents of output file parsed out of the Stan CSV file header comments and column headers. Assumes valid CSV files.
RunSet¶
- class cmdstanpy.stanfit.RunSet(args, chains=1, *, chain_ids=None, time_fmt='%Y%m%d%H%M%S', one_process_per_chain=True)[source]¶
Encapsulates the configuration and results of a call to any CmdStan inference method. Records the method return code and locations of all console, error, and output files.
RunSet objects are instantiated by the CmdStanModel class inference methods which validate all inputs, therefore “__init__” method skips input checks.
- Parameters:
- cmd(idx)[source]¶
Assemble CmdStan invocation. When running parallel chains from single process (2.28 and up), specify CmdStan arg num_chains and leave chain idx off CSV files.
- property method: Method¶
CmdStan method used to generate this fit.
CompilerOptions¶
- class cmdstanpy.compilation.CompilerOptions(*, stanc_options=None, cpp_options=None, user_header=None)[source]¶
User-specified flags for stanc and C++ compiler.
- Parameters:
- stanc_options - stanc compiler flags, options
- cpp_options - makefile options
- Type:
NAME=value
- user_header - path to a user .hpp file to include during compilation
- add(new_opts)[source]¶
Adds options to existing set of compiler options.
- Parameters:
new_opts (CompilerOptions) –
- Return type:
None
- add_include_path(path)[source]¶
Adds include path to existing set of compiler options.
- Parameters:
path (str) –
- Return type:
None
- validate()[source]¶
Check compiler args. Raise ValueError if invalid options are found.
- Return type:
None
- validate_cpp_opts()[source]¶
Check cpp compiler args. Raise ValueError if bad config is found.
- Return type:
None
- validate_stanc_opts()[source]¶
Check stanc compiler args and consistency between stanc and C++ options. Raise ValueError if bad config is found.
- Return type:
None
CmdStanArgs¶
- class cmdstanpy.cmdstan_args.CmdStanArgs(model_name, model_exe, chain_ids, method_args, data=None, seed=None, inits=None, output_dir=None, sig_figs=None, save_latent_dynamics=False, save_profile=False, refresh=None)[source]¶
Container for CmdStan command line arguments. Consists of arguments common to all methods and and an object which contains the method-specific arguments.
- Parameters:
model_name (str) –
method_args (Union[SamplerArgs, OptimizeArgs, GenerateQuantitiesArgs, VariationalArgs, LaplaceArgs, PathfinderArgs]) –
save_latent_dynamics (bool) –
save_profile (bool) –
SamplerArgs¶
- class cmdstanpy.cmdstan_args.SamplerArgs(iter_warmup=None, iter_sampling=None, save_warmup=False, thin=None, max_treedepth=None, metric=None, step_size=None, adapt_engaged=True, adapt_delta=None, adapt_init_phase=None, adapt_metric_window=None, adapt_step_size=None, fixed_param=False, num_chains=1)[source]¶
Arguments for the NUTS adaptive sampler.
- Parameters:
OptimizeArgs¶
- class cmdstanpy.cmdstan_args.OptimizeArgs(algorithm=None, init_alpha=None, iter=None, save_iterations=False, tol_obj=None, tol_rel_obj=None, tol_grad=None, tol_rel_grad=None, tol_param=None, history_size=None, jacobian=False)[source]¶
Container for arguments for the optimizer.
LaplaceArgs¶
PathfinderArgs¶
- class cmdstanpy.cmdstan_args.PathfinderArgs(init_alpha=None, tol_obj=None, tol_rel_obj=None, tol_grad=None, tol_rel_grad=None, tol_param=None, history_size=None, num_psis_draws=None, num_paths=None, max_lbfgs_iters=None, num_draws=None, num_elbo_draws=None, save_single_paths=False, psis_resample=True, calculate_lp=True)[source]¶
Container for arguments for Pathfinder.
VariationalArgs¶
- class cmdstanpy.cmdstan_args.VariationalArgs(algorithm=None, iter=None, grad_samples=None, elbo_samples=None, eta=None, adapt_iter=None, adapt_engaged=True, tol_rel_obj=None, eval_elbo=None, output_samples=None)[source]¶
Arguments needed for variational method.
- Parameters: