pygsti.layouts.prefixtable.Tree#

class Tree(roots=None)#

Bases: object

Container class for storing a tree structure (technically a forest, as there can be multiple roots).

Parameters:

roots (list of RootNode, optional (default None)) – List of roots for this tree structure.

Methods

__init__([roots])

add_root(root_node)

Add a root node to the tree.

calculate_cost()

Calculate the total cost of the tree, including root costs and promotion costs for child nodes.

count_nodes()

Count the total number of nodes in the tree.

get_root_node(value)

Get the root node associated with the input value.

print_tree()

Print the entire tree structure.

remove_root(root_node)

Remove a root node from the tree.

to_networkx_graph()

Convert the tree to a NetworkX directed graph with node and edge attributes.

total_orig_indices()

Calculate the total number of original indices for all root nodes and their descendants.

traverse()

Traverse the entire tree in pre-order and return a list of node values.

add_root(root_node)#

Add a root node to the tree.

Parameters:

root_node (RootNode) – The root node to be added.

calculate_cost()#

Calculate the total cost of the tree, including root costs and promotion costs for child nodes. See RootNode and ChildNode.

count_nodes()#

Count the total number of nodes in the tree.

get_root_node(value)#

Get the root node associated with the input value. If that node is not present, return None.

Parameters:

value (any) – The value to search for in the root nodes.

Returns:

The root node with the specified value, or None if not found.

Return type:

RootNode or None

print_tree()#

Print the entire tree structure.

remove_root(root_node)#

Remove a root node from the tree.

Parameters:

root_node (RootNode) – The root node to be removed.

to_networkx_graph()#

Convert the tree to a NetworkX directed graph with node and edge attributes.

Returns:

The NetworkX directed graph representation of the tree.

Return type:

networkx.DiGraph

total_orig_indices()#

Calculate the total number of original indices for all root nodes and their descendants.

traverse()#

Traverse the entire tree in pre-order and return a list of node values.

Returns:

A list of node values in pre-order traversal.

Return type:

list