httpstan.models
¶
Compile a Stan model extension module given code written in Stan.
These functions manage the process of compiling a Python extension module from C++ code generated and loading the resulting module.
Module Contents¶
Functions¶
|
Calculate model name from Stan program code. |
|
Load an existing model-specific stan::services extension module. |
|
Compile a model-specific stan::services extension module. |
Attributes¶
- httpstan.models.PACKAGE_DIR¶
- httpstan.models.logger¶
- httpstan.models.calculate_model_name(program_code: str) str [source]¶
Calculate model name from Stan program code.
Names look like this:
models/2uxewutp
. Name uses a hash of the concatenation of the following:UTF-8 encoded Stan program code
UTF-8 encoded string recording the httpstan version
UTF-8 encoded string identifying the system platform
UTF-8 encoded string identifying the system bit architecture
UTF-8 encoded string identifying the Python version
UTF-8 encoded string identifying the Python executable
- Parameters
program_code – Stan program code.
- Returns
model name
- Return type
- httpstan.models.import_services_extension_module(model_name: str) types.ModuleType [source]¶
Load an existing model-specific stan::services extension module.
- Parameters
model_name –
- Returns
loaded module handle.
- Return type
module
- Raises
KeyError – Model not found.
- async httpstan.models.build_services_extension_module(program_code: str, extra_compile_args: Optional[List[str]] = None) str [source]¶
Compile a model-specific stan::services extension module.
Since compiling an extension module takes a long time, compilation takes place in a different thread.
Messages generated by the compiler—normally sent to stderr—are collected and saved. These messages are returned by the function.
Returns compiler messages.
This is a coroutine function.
IMPORTANT NOTE: This function builds the extension module in the cache directory, making it available for later import`ing. This “side-effect” is why there are no functions called `load_services_extension_module and dump_services_extension_module.