gpt_graph.core.group

Classes

Group([nodes, node_graph, filter_cri, ...])

class gpt_graph.core.group.Group(nodes=None, node_graph=None, filter_cri=None, group_key=None, parent_filter_cri=None, parent_group_key=None, name=None, type=None, gid=None, if_yield=None)[source]
__init__(nodes=None, node_graph=None, filter_cri=None, group_key=None, parent_filter_cri=None, parent_group_key=None, name=None, type=None, gid=None, if_yield=None)[source]
initialize()[source]

Set nodes and contains back to original empty state.

clone(if_copy_nodes=False)[source]

Create a deep copy of the Group instance, excluding nodes, contains, prototype, and clones resembles Component.clone

reset_uuid(if_recursive=False)[source]
run(filter_cri=None, group_key=None, parent_filter_cri=None, parent_group_key=None, nodes=None, node_graph=None, if_refresh=None)[source]

Execute the grouping process on nodes based on various criteria.

Parameters: filter_cri (dict, optional): Criteria to filter nodes. group_key (str or dict, optional): Key or dictionary of functions to group nodes. parent_filter_cri (dict, optional): Criteria to filter parent nodes. parent_group_key (str, optional): Key to group parent nodes. nodes (list, optional): List of nodes to process. If None, uses filtered nodes. node_graph (object, optional): Graph object containing nodes and their relationships. if_refresh (bool, optional): Whether to refresh the node list using filter criteria.

Returns: list: List of Group objects representing the grouped nodes.

This method performs the following steps: 1. Updates instance attributes if new values are provided. 2. Filters and groups parent nodes if parent_filter_cri is specified. 3. Filters child nodes based on filter_cri or uses provided nodes. 4. Groups child nodes based on their parent groups or directly by group_key. 5. Further subdivides groups based on the specified group_key. 6. Creates Group objects for each final group of nodes.

The grouping can be based on parent-child relationships and/or node attributes. It supports both simple key-based grouping and complex grouping using custom functions.

Raises: ValueError: If node_graph is not provided and not set in the instance.

get_nodes(if_yield=None)[source]

used in Step.run to be input to the Step.cp_run_func, if the Group is added in Step.input_schema

Retrieve nodes from the group.

Args: if_yield (bool, optional): Whether to yield nodes iteratively.

Defaults to instance’s if_yield value.

Returns: If if_yield is True:

Single subgroup’s nodes or None when exhausted.

If if_yield is False:

List of all nodes from all subgroups.

Runs grouping process if nodes haven’t been processed yet.