nvflare.fuel.utils.tree_utils module
- class Forest[source]
Bases:
objectA forest contains one or more trees. Each entry in “self.roots” is the unique name of the root object. The “self.nodes” a dict of: name => Node. You can get the Node from an object name.
Constructor of Forest
- class Node(obj: Any, parent)[source]
Bases:
objectDefinition of Nodes that are elements of trees. The “self.obj” is the object associated with the node; The “self.parent” is the parent Node; The “self.children” is a list of child Nodes.
Constructor of Node
- Parameters:
obj – the object to be associated with the node
parent – parent node of the node
- build_forest(objs: List[Any], get_name_f, get_fqn_f, **kwargs) Forest[source]
Builds a Forest from a list of objects. Each object must have a unique “name” and unique “fqn”. This function builds trees based on the FQNs of the objects.
- Parameters:
objs – objects for which to build the forest
get_name_f – the function to get object name
get_fqn_f – the function to get object fqn
**kwargs – kwargs to be passed to get_name_f and get_fqn_f
Returns: a Forest object
- build_path(obj: Any, get_name_f, get_parent_f, **kwargs)[source]
Build tree path for the specified object, which can be of any type. It is assumed that the object is already in an object tree. The tree path of an object is the list of objects that are traversed from the root to the object.
Objects must have unique names.
- Parameters:
obj – the object that the path will be built for
get_name_f – the function that returns object name
get_parent_f – the function that returns the object’s parent object
**kwargs – kwargs to be passed to the get_name_f and get_parent_f
Returns: a tuple of (error, path).
- forest_to_dict(forest: Forest, get_name_f, **kwargs) dict[source]
Output the forest into a dict that shows the structure of the forest.
- Parameters:
forest – the forest to output
get_name_f – function to get object name
**kwargs – kwargs passed to get_name_f
Returns: a dict that shows the structure of the forest