improver.calibration.rainforest_compilation module#

RainForests model compilation plugin.

class CompileRainForestsModel(model_config_dict, toolchain='gcc', verbose=False, parallel_comp=0)[source]#

Bases: BasePlugin

Class to compile RainForests tree models

__init__(model_config_dict, toolchain='gcc', verbose=False, parallel_comp=0)[source]#

Initialise the options used when compiling models.

Parameters:
  • model_config_dict (dict[int, dict[str, dict[str, str]]]) – Dictionary describing the high-level RainForests model structure; - top level key describes the lead-hour, - next level key describes the threshold, - corresponding values locate the associated model file.

  • toolchain (str) – Toolchain to use for Treelite model compilation. ‘gcc’ (default), ‘msvc’, ‘clang’ or a specific variation of clang or gcc (e.g. ‘gcc-7’).

  • verbose (bool) – Print verbose output during compilation

  • parallel_comp (int) – Enables parallel compilation to reduce time and memory consumption. Value is the number of processes to use. Defaults to 0 (no parallel compilation)

Dictionary is of format:

{
“24”: {
“0.000010”: {

“lightgbm_model”: “<path_to_lightgbm_model_object>”, “treelite_model”: “<path_to_treelite_model_object>”

}, “0.000050”: {

“lightgbm_model”: “<path_to_lightgbm_model_object>”, “treelite_model”: “<path_to_treelite_model_object>”

}, “0.000100”: {

“lightgbm_model”: “<path_to_lightgbm_model_object>”, “treelite_model”: “<path_to_treelite_model_object>”

},

}

The keys specify the lead times and model threshold values, while the associated values are the path to the corresponding tree-model objects for that lead time and threshold.

_abc_impl = <_abc._abc_data object>#
_compile_model(lightgbm_path, output_path)[source]#

Compile a lightgbm model with Treelite.

Parameters:
  • lightgbm_path (Path) – Path to LightGBM Booster file.

  • output_path (Path) – Path where the compiled Treelite predictor file will be created.

Return type:

None

process(allow_missing=False)[source]#

Compile all configured LightGBM models with Treelite.

Parameters:

allow_missing (bool) – If False (default), throws an error if any LightGBM models are missing. If True, any missing LightGBM files will be ignored.

Return type:

None

Iterates through all lead times and thresholds in the model config dictionary and compiles the corresponding LightGBM models to Treelite predictors.