stanbkt.utils.compile_stan_model#

stanbkt.utils.compile_stan_model(stan_file, cpp_options=None, stanc_options=None, print_fn=None)#

Compile or reuse a cached Stan executable and return a CmdStan model.

Parameters:
  • stan_file (str | PathLike[str]) – Path to the entry-point Stan source file.

  • cpp_options (dict[str, Any] | None) – C++ compiler options forwarded to CmdStanPy.

  • stanc_options (dict[str, Any] | None) – Stan compiler options forwarded to CmdStanPy.

  • print_fn (Callable | None)

Returns:

Model instance backed by a cached compiled executable.

Return type:

CmdStanModel

Raises:

RuntimeError – If CmdStanPy finishes compilation without reporting an executable path.

Notes

Compilation is performed inside a temporary directory so the exe is never written into the installed package tree (e.g. site-packages inside a venv). Only the compiled executable is stored in the platform cache directory; Stan source files are not cached.

CmdStanPy mutates the stanc_options / cpp_options dicts it receives (adding include-paths based on the Stan file location). This function always passes shallow copies so the caller’s dicts are never modified.