Initializations Module

Provides initialization routines for models and data structures.

HMB.Initializations.CheckInstalledModules(modules)[source]

Check if the specified modules are installed and can be imported. This function attempts to import each module in the provided list and prints the result.

Parameters:

modules (list) – A list of module names (as strings) to check for installation.

HMB.Initializations.UpdateMatplotlibSettings(fontSize=16, dpi=720, figSize=None, silent=True, snsStyle='whitegrid')[source]

Update Matplotlib settings for better visualization. This function sets various parameters in Matplotlib to improve the appearance of plots. It configures figure resolution, font styles, grid settings, and line properties.

Parameters:
  • fontSize (int) – The default font size to use for plot elements.

  • dpi (int) – The dots per inch (DPI) setting for figure resolution.

  • figSize (tuple) – The default figure size (width, height) in inches. If None, the default Matplotlib size is used.

  • silent (bool) – If True, suppresses the output of the updated settings. If False, prints the updated settings to the console.

  • snsStyle (str) – The Seaborn style to set for the plots (e.g., “whitegrid”, “darkgrid”, “ticks”, etc.).

HMB.Initializations.SetMaxTextChunkSize(maxChunkSize=104857600)[source]

Set the maximum size for text chunks in PNG images. This is useful for controlling the size of metadata stored in PNG files.

HMB.Initializations.SetEnvironmentVariables(defaultThreads=6)[source]

Set environment variables to control the number of threads used by libraries like OpenBLAS, MKL, and OMP. This is useful for optimizing performance and avoiding excessive CPU usage.

HMB.Initializations.MaximizeThreads()[source]

Maximize the number of threads used by libraries like OpenBLAS, MKL, and OMP. This is useful for optimizing performance on multi-core CPUs.

HMB.Initializations.IgnoreWarnings()[source]

Suppress all warnings globally. This function uses the shutup library to suppress warnings from various libraries.

HMB.Initializations.SeedEverything(seed=42, deterministic=True, benchmark=True)[source]

Seed everything for reproducibility. This function sets the random seed for various libraries to ensure consistent results across runs.

Parameters:
  • seed (int) – The random seed to use for seeding.

  • deterministic (bool) – If True, sets cuDNN to be deterministic.

  • benchmark (bool) – If True, enables cuDNN benchmark mode.

HMB.Initializations.DoRandomSeeding(verbose=False)[source]

Perform random seeding for reproducibility. This function sets the random seed for various libraries to ensure consistent results across runs.

Parameters:

verbose (bool) – If True, prints the random seed used for seeding. This is useful for tracking the seed value in logs or outputs for reproducibility purposes.

HMB.Initializations.ShowGPUUtilization()[source]

Show GPU utilization using GPUtil. This function displays the current GPU usage statistics.

class HMB.Initializations.ShowGPUUtilizationThread(interval=120)[source]

Bases: Thread

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

stop()[source]
HMB.Initializations.PrintGPUSpecs()[source]
HMB.Initializations.EnsureCUDAAvailable(strict=True, which='pytorch', verbose=False)[source]

Ensure that CUDA is available for GPU computations. This function checks if CUDA is available and exits the program if not.

Parameters:
  • strict (bool) – If True, the program will exit if CUDA is not available.

  • which (str) – The library to check for CUDA availability (“pytorch” or “tensorflow”).

  • verbose (bool) – If True, prints additional information about the GPU and CUDA availability.

Returns:

True if CUDA is available, False otherwise.

Return type:

bool

HMB.Initializations.NLTKFindDownload(resource)[source]

Find and download the specified NLTK resource if it is not already available.

Parameters:

resource (str) – The name of the NLTK resource to find and download (e.g., “punkt”, “stopwords”, “wordnet”).

HMB.Initializations.DownloadNLTKPackages()[source]

Download necessary NLTK packages for text processing. This function ensures that the required NLTK resources are available for natural language processing tasks.

HMB.Initializations.IncreaseSysRecursionLimit(limit=10000)[source]

Increase the system recursion limit to allow deeper recursive calls. This is useful for algorithms that require deep recursion, such as certain tree or graph algorithms.

Parameters:

limit (int) – The new recursion limit to set.

HMB.Initializations.LoadEnglishModelSpacy(modelName='en_core_web_sm')[source]

Load the specified English model for spaCy. This function loads the specified spaCy model for natural language processing tasks.

Parameters:

modelName (str) – The name of the spaCy model to load (e.g., “en_core_web_sm”, “en_core_web_md”, “en_core_web_lg”).

HMB.Initializations.ClearTensorFlowSession()[source]

Clear the TensorFlow session to free up resources. This is useful for resetting the state of TensorFlow and releasing GPU memory.