Recorder

class csdl_alpha.src.recorder.Recorder(inline=False, debug=False, expand_ops=False, auto_hierarchy=False)[source]

The Recorder class assembles CSDL variables and operations into a computational graph.

Attributes
managerManager

The global manager object that manages the recorders.

active_graph_nodeTree

The currently active graph node.

active_namespaceNamespace

The currently active namespace node.

active_graphGraph

The currently active graph.

Methods

count_operations([n])

Prints the most common operations in the graph. Args: n: The number of operations to print.

count_origins([n, mode, type])

Count the origins of nodes in the active graph and prints to console. This method counts the origins of nodes in the active graph based on the specified mode and type. The origins can be counted based on the function, file, or line where the node originated from. Parameters ---------- n : int, optional The number of origins to display, by default 10. mode : str, optional The mode to count the origins. Valid options are 'function', 'file', or 'line', by default 'function'. type : str | object, optional The type of nodes to count the origins. Valid options are 'operation', 'variable', or 'all', by default 'operation'. Raises ------ ValueError If an invalid mode or type is provided.

execute()

Executes the current active graph inline and updates all variable values

find_variable_by_name(*names)

Given strings, returns the variables with the given names.

gather_insights()

UNTESTED!

get_root_graph()

Gets the root graph.

print_graph_structure()

prints graph tree structure like:

print_largest_variables([n])

Prints the largest variables in the graph. Args: n: The number of variables to print.

save_graph([filename])

Saves the graph to file

start()

Activates the recorder.

stop()

Deactivates the recorder.

visualize_adjacency_matrix()

Visualizes the adjacency matrix of the graph.

visualize_graph([filename, visualize_style, ...])

Visualizes the graph.

visualize_hierarchical

count_operations(n=10)[source]

Prints the most common operations in the graph. Args:

n: The number of operations to print.

count_origins(n=10, mode='function', type='operation')[source]

Count the origins of nodes in the active graph and prints to console. This method counts the origins of nodes in the active graph based on the specified mode and type. The origins can be counted based on the function, file, or line where the node originated from. Parameters ———- n : int, optional

The number of origins to display, by default 10.

modestr, optional

The mode to count the origins. Valid options are ‘function’, ‘file’, or ‘line’, by default ‘function’.

typestr | object, optional

The type of nodes to count the origins. Valid options are ‘operation’, ‘variable’, or ‘all’, by default ‘operation’.

Raises

ValueError

If an invalid mode or type is provided.

execute()[source]

Executes the current active graph inline and updates all variable values

find_variable_by_name(*names)[source]

Given strings, returns the variables with the given names.

Parameters
namesstr

The names of the variables to find.

Returns
tuple[Variable]

The variables with the given names in the order they were provided.

Raises
KeyError

If no variable with a given name is found.

KeyError

If multiple variables with the same given name are found.

TypeError

If strings not given.

gather_insights()[source]

UNTESTED!

get_root_graph()[source]

Gets the root graph.

Returns:

The root graph.

print_graph_structure()[source]

prints graph tree structure like:

root
graph1

graph2

graph3

graph4 graph5

print_largest_variables(n=10)[source]

Prints the largest variables in the graph. Args:

n: The number of variables to print.

save_graph(filename='graph')[source]

Saves the graph to file

Parameters
filenamestr, optional

filename to save to, by default ‘graph’

start()[source]

Activates the recorder.

stop()[source]

Deactivates the recorder.

visualize_adjacency_matrix()[source]

Visualizes the adjacency matrix of the graph.

visualize_graph(filename='image', visualize_style='namespace', trim_loops=False, format='svg')[source]

Visualizes the graph. - ‘namespace’ visualizes the top-level graph where nodes are grouped by namespace - ‘hierarchical’ visualizes all graphs including subgraph operations for debugging. Always saves as a .svg file.

Parameters
filenamestr, optional

The filename to save the visualization to, by default ‘image’

visualize_stylestr, optional

The style of visualization, by default ‘namespace’

trim_loopsbool, optional

Whether to trim loops, by default False

formatstr, optional

The format of the visualization, by default ‘svg’