pygsti.protocols.treenode.TreeNode#
- class TreeNode(possible_child_name_dirs, child_values=None)#
Bases:
objectA base class for representing an object that lives “at” a filesystem directory.
- Parameters:
possible_child_name_dirs (dict) – A dictionary with string keys and values that maps possible child names (keys of this TreeNode) to directory names (where those keys are stored).
child_values (dict, optional) – A dictionary of child values (may be other TreeNode objects).
Methods
__init__(possible_child_name_dirs[, ...])from_dir(dirname[, parent, name])Load a
TreeNodefrom the data rooted at dirname.items()An iterator over the (child_name, child_node) pairs of this node.
keys()An iterator over the keys (child names) of this tree node.
prune_tree(paths[, paths_are_sorted])Prune the tree rooted here to include only the given paths, discarding all other leaves & branches.
Dictionary paths leading to data objects/nodes beneath this one.
view(keys_to_keep)Get a "view" of this tree node that only has a subset of this node's children.
write(dirname[, parent])Write this tree node to a directory.
- classmethod from_dir(dirname, parent=None, name=None)#
Load a
TreeNodefrom the data rooted at dirname.- Parameters:
dirname (str or Path) – The directory path to load from.
parent (TreeNode, optional) – This node’s parent node, if it’s already loaded.
name (immutable, optional) – The name of this node, usually a string or tuple. Almost always the key within parent that refers to the loaded node (this can be different from the directory name).
- items()#
An iterator over the (child_name, child_node) pairs of this node.
- keys()#
An iterator over the keys (child names) of this tree node.
- prune_tree(paths, paths_are_sorted=False)#
Prune the tree rooted here to include only the given paths, discarding all other leaves & branches.
- Parameters:
paths (list) – A list of tuples specifying the paths to keep.
paths_are_sorted (bool, optional) – Whether paths is sorted (lexicographically). Setting this to True will save a little time.
- Returns:
A view of this node and its descendants where unwanted children have been removed.
- Return type:
- underlying_tree_paths()#
Dictionary paths leading to data objects/nodes beneath this one.
- Returns:
A list of tuples, each specifying the tree traversal to a child node. The first tuple is the empty tuple, referring to this (root) node.
- Return type:
list
- view(keys_to_keep)#
Get a “view” of this tree node that only has a subset of this node’s children.
- Parameters:
keys_to_keep (iterable) – A sequence of key names to keep.
- Return type: