Utilities Module#

Utility functions for the MacroStat model.

The macrostat.util module consists of the following classes

autodocs

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

batchprocessing

Batch processing functionionality

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

Make a model description from a Behavior class.

This function takes a Behavior class and returns a 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. It then saves the docs to a file if an output file is provided.

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

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

  • docstyle (str, default "latex") – The type of documentation to make

  • title (str, optional) – The title of the 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. Only for LaTeX

Returns:

The model description.

Return type:

str

Examples

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

Run all of the tasks in parallel using the ProcessPoolExecutor.