Utilities Module#

Utility functions for the MacroStat model.

The macrostat.util module consists of the following classes

latex_model_documentation

Utility functions for extracting and formatting docstring information from Behavior classes.

batchprocessing

Batch processing functionionality

macrostat.util.generate_latex_documentation(behavior_class: Type[Behavior], output_file: str = None, title: str = None, subsec: bool = True, preamble: str = None) str[source]#

Make a LaTeX model description from a Behavior class.

This function takes a Behavior class and returns a LaTeX model description by parsing the docstrings of the initialize() and the step() methods. It then copies the docstrings of those methods and all of the methods that they call. From each, it extracts the description and the equations section, and then formats them for LaTeX. It then saves the LaTeX code to a file if an output file is provided.

Parameters:
  • behavior_class (Type[Behavior]) – The Behavior class to make a LaTeX model description from.

  • output_file (str, optional) – The file to save the LaTeX model description to.

  • title (str, optional) – The title of the LaTeX model description.

  • subsec (bool, optional) – If True, add a subsection for each method. If False, just append the description and equations.

  • preamble (str, optional) – A string of LaTeX code to add to the preamble of the document, i.e. before the begin{document} command.

Returns:

The LaTeX model description.

Return type:

str

Examples

>>> from macrostat.models import get_model
>>> GL06SIM = get_model("GL06SIM")
>>> tex = generate_documentation(GL06SIM().behavior)
>>> print(tex)
macrostat.util.parallel_processor(tasks: list = [], worker: callable = <function timeseries_worker>, cpu_count: int = 1, tqdm_info: str = '')[source]#

Run all of the tasks in parallel using the ProcessPoolExecutor.

Parameters:
  • tasks (list[tuple]) – List of tasks to be processed in parallel. Each task should be a tuple

  • worker (callable) – Worker function to be used for the parallel processing. Each task will be passed to the worker function as a tuple

  • cpu_count (int (default=1)) – Number of CPUs to be used for the parallel processing.

  • tqdm_info (str (default="")) – Information to be displayed in the tqdm progress bar.

Returns:

List of tuple results from the worker function

Return type:

list