Skip to content

Page built on Mar 17 2022 for version 0.5.0.

Hubit

Components described below are available directly from the 'hubit' package. Therefore, the model class can be imported as from hubit import HubitModel.

HubitModel

results: FlatData property readonly

Get model results as FlatData

Returns:

Type Description
FlatData

Results for the model instance.

clear_cache(self)

Clear the model cache. Will delete the serialized model cache from the disk if it exists.

from_file(model_file_path, output_path='./', name='NA') classmethod

Creates a HubitModel from a configuration file.

Parameters:

Name Type Description Default
model_file_path str

The location of the model file.

required
output_path str

Path where results should be saved

'./'
name str

Model name

'NA'

Returns:

Type Description
HubitModel

Hubit model object as defined in the specified model file

get(self, query, use_multi_processing=False, validate=False, use_results='none')

Get the response corresponding to the query

On Windows this method should be guarded by if __name__ == '__main__': if use_multi_processing is True

Parameters:

Name Type Description Default
query List[str]

Sequence of strings that complies with Query.

required
use_multi_processing bool

Flag indicating if the respose should be generated using (async) multiprocessing.

False
validate bool

Flag indicating if the query should be validated prior to execution. If True a dry-run of the model will be executed.

False
use_results str

Should previously saved results be used. If use_results is set to "current" the results set on the model instance will be used as-is i.e. will not be recalculated. If use_results is set to "cached" cached results will be used if they exists. If use_results is set to "none" no previously calculated results will be used.

'none'

Exceptions:

Type Description
HubitModelNoInputError

If no input is set on the model.

HubitModelNoResultsError

If use_results = "current" but no results are present on the model.

HubitError

If the specified use_results option is not known.

Returns:

Type Description
Dict[str, Any]

The response

get_many(self, query, input_values_for_path, skipfun=None, nproc=None)

Perform a full factorial sampling of the input points specified in input_values_for_path.

On Windows calling this method should be guarded by if __name__ == '__main__':

Parameters:

Name Type Description Default
query List[str]

Sequence of strings that complies with Query.

required
input_values_for_path Dict[str, Any]

Dictionary with string keys that each complies with HubitQueryPath. The corresponding values should be an iterable with elements representing discrete values for the attribute at the path. For each factor combination an input data object (FlatData) will be created and passed to skipfun.

required
skipfun Any

Callable that takes the flattened input for each factor combination as the only argument. If the skip function returns True the factor combination represented by the input data object is skipped. The default skipfun corresponding to skipfun=None always returns False.

None
nproc Any

Number of processes to use. If None a suitable default is used.

None

Exceptions:

Type Description
HubitModelNoInputError

If not input is set.

Returns:

Type Description
Tuple

Tuple of lists (responses, flat_inputs, flat_results). flat_inputs and flat_results both have elements of type FlatData

get_results(self)

Get model results as FlatData

Returns:

Type Description
FlatData

Results for the model instance.

has_cached_results(self)

Check if the model has cached results

Returns:

Type Description
bool

The result of the check

log(self)

Get the model log

Returns:

Type Description
HubitLog

HubitLog object

mpaths_for_qpath_fields_only(self, qpath)

Find model paths that match the query. The match is evaluated only based on field names

render(self, query=[], file_idstr='')

Create graph representing the model or the query and save the image to the model output_path.

Parameters:

Name Type Description Default
query List[str]

Sequence of strings that complies with Query. If not provided (or is empty) the model is rendered. If a non-empty query is provided that query is rendered, which requires the input data be set.

[]
file_idstr str

Identifier appended to the image file name.

''

set_component_caching(self, component_caching)

Set component worker caching on/off.

Parameters:

Name Type Description Default
component_caching bool

True corresponds to worker caching being on.

required

set_input(self, input_data)

Set the (hierarchical) input on the model.

Parameters:

Name Type Description Default
input_data Dict[str, Any]

Input data as a freely formatted, serializable dictionary.

required

Returns:

Type Description
HubitModel

Hubit model with input set.

set_model_caching(self, caching_mode)

Set the model caching mode.

Parameters:

Name Type Description Default
caching_mode str

Valid options are: "none", "incremental", "after_execution". If "none" model results are not cached. If "incremental" results are saved to disk whenever a component worker finishes its workload. If the caching_mode is set to "after_execution" the results are saved to disk when all component workers have finished their workloads.

required

Results caching is useful when you want to avoid spending time calculating the same results multiple times. A use case for "incremental" caching is when a calculation is stopped (computer shutdown, keyboard interrupt, exception raised) before the response has been generated. In such cases the calculation can be restarted from the cached results. The overhead introduced by caching makes it especially useful for CPU bound models. A use case for "after_execution" caching is when writing the result data incrementally is a bottleneck.

Warning. Cached results are tied to the content of the model configuration file and the model input. Hubit does not check if any of the underlying calculation code has changed. Therefore, using results caching while components are in development is not recommended.

Hubit's behavior in four parameter combinations is summarized below. "Yes" in the Write column corresponds to setting the caching level to either "incremental" or "after_execution" using the set_model_caching method. "No" in the Write column corresponds to caching level "none". "Yes" in the Read column corresponds use_results="cached" in the get method while "No" corresponds to use_results="none".

Write Read Behavior
Yes Yes Any cached results for the model are loaded. These results will be saved (incrementally or after execution) and may be augmented in the new run depending on the new query
Yes No Model results are cached incrementally or after execution. These new results overwrite any existing results cached for the model
No Yes Any cached results for the model are loaded. No new results are cached and therefore the cached results will remain the same after execution.
No No No results are cached and no results are loaded into the model

set_results(self, results_data)

Set the (hierarchical) results on the model.

Parameters:

Name Type Description Default
results_data Dict[str, Any]

Results data as a freely formatted, serializable dictionary.

required

Returns:

Type Description
HubitModel

Hubit model with input set

validate(self, query=[])

Validate a model or query. Will validate as a query if query are provided.

Parameters:

Name Type Description Default
query List[str]

Sequence of strings that complies with Query.

[]

Exceptions:

Type Description
HubitModelNoInputError

If not input is set.

HubitModelValidationError

If validation fails.

Returns:

Type Description
bool

True if validation was successful.

clear_hubit_cache()

Clear the cache for all models. Will delete all serialized model cache from the disk.