Grouper.utils module
- Grouper.utils.convert_edges_to_nodetype(G)
Convert the edge representation in a graph to use node types instead of node IDs.
- Parameters:
G (nx.DiGraph) – The input graph.
- Returns:
A new graph with the converted edge representation.
- Return type:
nx.DiGraph
- Grouper.utils.convert_to_nx(G)
Convert a GroupGraph to a networkx graph.
- Parameters:
G (GroupGraph) – The GroupGraph to convert.
- Returns:
The networkx representation of the GroupGraph.
- Return type:
- Grouper.utils.data_to_gg_edge(data, max_ports)
Convert PyG data to GroupGraph edges.
- class Grouper.utils.nxGroupGraph(node_types=None)
Bases:
DiGraphA graph with ports as parts of nodes that can be connected to other ports.
- add_edge(node_port_1, node_port_2)
Add an edge between two nodes in the GroupGraph.
- Parameters:
node_port_1 (Tuple[Any, Any]) – Tuple of node and port on the first node.
node_port_2 (Tuple[Any, Any]) – Tuple of node and port on the second node.
- Raises:
AttributeError – If a node has no free ports or if nodes or ports are not present in the Graph.
- Return type:
- add_node(nodeID, node_type, smarts, hubs)
Add a node to the GroupGraph.
- make_undirected()
Convert the GroupGraph to an undirected graph.
Adds bonds and updates edge ports accordingly.
- n_free_ports(nodeID)
Get the number of free ports on a node.
- to_PyG_Data(node_descriptor_generator, max_ports=0)
Convert the GroupGraph to a PyG Data representation.
- Parameters:
- Returns:
PyG Data representation.
- Return type:
torch_geometric.data.Data
- Grouper.utils.parse_vcolg_line(line)
Parse a single line of vcolg’s terse-format (
-T) output.vcolg writes one connected colored graph per line as
n_vertices n_edges c_0 c_1 … c_{n-1} v0 w0 v1 w1 … vE wE
with the colors and the edge list separated by two spaces. There’s no port information — only which two nodes are bonded — so the caller is responsible for resolving port assignments downstream if they want a fully-formed GroupGraph.
- Parameters:
line (str) – A single line of vcolg output produced with
-Tand-mK.- Returns:
(n_vertices, colors, edges) –
n_verticesis the number of nodes;colors[i]is the color (= group index, 0-based) of nodei;edgesis the list of(src_node, dst_node)pairs. No port information is included.- Return type:
- Raises:
ValueError – If the line doesn’t match vcolg’s expected format (missing the two-space header/edge separator, or the edge list has an odd number of integers).
Examples
from Grouper.utils import parse_vcolg_line # A 3-node 2-edge path with all three nodes the same color: n, colors, edges = parse_vcolg_line("3 2 0 0 0 0 1 1 2") # n == 3 # colors == [0, 0, 0] # edges == [(0, 1), (1, 2)]
Notes
The parser is intentionally minimal: it does not validate that the colors fit within any specific palette size, nor that the edge endpoints reference valid node indices. Downstream code can layer those checks on top depending on what it’s doing.