Handler#

Handler executing in topological order#

Currently, all handlers execute in topological order. The handler provides detailed message when exceptions occur during individual node execution.

mmodel.handler.BasicHandler(graph, returns, ...)

Basic handler, use the dictionary as a data class.

BasicHandler executes each node and stores the result in a dictionary. All intermediate values are preserved in the dictionary.

mmodel.handler.MemHandler(graph, returns)

Memory optimized handler, delete intermediate values when necessary.

mmodel.handler.MemData(data, counter)

Modified dictionary that checks the counter every time a value is accessed.

MemHandler calculates each input parameter usage. Then, the instance executes each node and stores the result in a custom dictionary MemData. The number of times a value is used in the graph is initialized with MemData object. Each time a key is accessed (used as input for a node), the object calculates the remaining number. If it is zero (no longer needed for the sequent nodes), the value of the key is deleted. The behavior has a very small overhead and reduces peak memory usage.

mmodel.handler.H5Handler(graph, returns, fname)

H5 Handler, saves all calculation values to an h5 file.

mmodel.handler.H5Data(data, fname, gname)

Data class to interact with underlying h5 file.

H5Handler executes each node and stores the result in an h5 file. For each node execution, the parameters are read from the h5 file. Each instance call stores values in the same h5 file, with a subgroup in the format of “name_time_uuid”. The naming scheme makes sure the h5 subgroup entries are unique for each instance run.

Note

For values that are object type and cannot be stored as an H5 database, the string of the object is stored as an attribute.

handler module#

class mmodel.handler.TopologicalHandler(graph, returns: list, **datacls_kwargs)[source]#

Bases: object

Base class for executing graph nodes in topological order.

“Returns” specifies the output order. If there is only one return the value is outputted, otherwise a tuple is outputted. This behavior is similar to the Python function.

The topological handler assumes each node has exactly one output.

Parameters:
  • name (str) – name of the handler (same as the model instance)

  • graph (networkx.digraph) – graph

  • returns (list) – handler returns order The list should have the same or more elements than the graph returns. See Model constructor definition.

DataClass()#

Return whether the object is callable (i.e., some kind of function).

Note that classes are callable, as are instances of classes with a __call__() method.

finish(data, returns)[source]#

Finish execution.

node_exception(data, node_data, node, node_attr)[source]#

Exception handler for individual nodes.

Overwrite this function for different exception formatting.

run_node(data, node, node_attr)[source]#

Run the individual node.

class mmodel.handler.MemHandler(graph, returns: list)[source]#

Bases: TopologicalHandler

Memory optimized handler, delete intermediate values when necessary.

The process works by keeping a record of the parameter counter. See MemData class for more details.

DataClass#

alias of MemData

class mmodel.handler.BasicHandler(graph, returns: list, **datacls_kwargs)[source]#

Bases: TopologicalHandler

Basic handler, use the dictionary as a data class.

DataClass#

alias of dict

class mmodel.handler.H5Handler(graph, returns, fname: str, gname: str = '')[source]#

Bases: TopologicalHandler

H5 Handler, saves all calculation values to an h5 file.

Parameters:
  • fname (str) – h5 file name

  • gname (str) – group name for the data entry

DataClass#

alias of H5Data