neuralqx.utils.misc.graph module¶
- find_corner_vertex_keyed(edge_pair)¶
Find the common (corner) vertex where two keyed edges meet.
Each edge is assumed to be in keyed form
(a, b, k), whereaandbare the endpoint vertices andkis an edge key (e.g. to distinguish parallel edges). The key component is ignored when determining adjacency.The function returns
(True, v)if the two edges share exactly one common vertexv. Otherwise it returns(True, False).
- get_vertices_from_minimal_loop(minimal_loops)¶
Extract the unique vertices traversed by one or more minimal loops (keyed-edge format).
Minimal loops are expected to be sequences of keyed edges
(a, b, k). The keykis ignored and only endpoints(a, b)are used to collect vertices. For each provided loop, the returned vertex list is sorted and duplicates are removed.
- get_common_base_vertex(triangulation_pair)¶
Return the common base vertices of a pair of triangulations/minimal loops.
The input is a pair of minimal loops in keyed-edge representation. The function extracts the vertex sets of each loop and returns the intersection (the vertices common to both).
- get_edges_at_base_vertex(minimal_loop, base_vertex)¶
Return the pair of edges in a minimal loop that meet at a given base vertex.
The minimal loop is provided in keyed-edge representation. The function iterates over all unordered pairs of edges and returns the first pair whose corner vertex (shared endpoint, ignoring keys) equals
base_vertex.
- get_reversed_keyed_edge(edge, as_list=False)¶
Reverse a keyed edge while keeping the key in the last position.
For an edge
(a, b, k), the reversed keyed edge is(b, a, k). Ifas_listis True, the result is returned as a list instead of a tuple.
- get_triplets_key(edges, vertex)¶
Enumerate all ordered edge triplets incident to a given vertex (keyed-edge format).
The function filters the provided keyed edges to those connected to
vertex(membership checked against the endpoint portion of the edge, i.e.edge[:-1]), then returns all length-3 permutations of those incident edges.
- reorder_edge_triplet_key(edge_triplet, base_vertex)¶
Orient a keyed edge triplet so each edge has the desired direction relative to
base_vertex.The triplet is interpreted positionally:
edge_triplet[0]is treated as an outgoing edge and is oriented to start atbase_vertex.edge_triplet[1]is treated as an incoming edge and is oriented to end atbase_vertex.edge_triplet[2]is treated as a segment edge and is oriented to start atbase_vertex.
Whenever an edge must be reversed to satisfy the orientation constraint, a factor of
-1is accumulated. The returned sign is the product of these factors.- Parameters:
- Return type:
- Returns:
Tuple
(reordered_triplet, sign)wherereordered_tripletis the reoriented triplet andsignis+1or-1.
- find_minimal_loops_with_edges_key(minimal_loop_list, edge_pair)¶
Find all minimal loops that contain a specified pair of keyed edges (up to orientation).
The function checks each minimal loop in
minimal_loop_listand includes it if both edges inedge_pairappear in the loop either in the same orientation or reversed (endpoint-flipped, key preserved).- Parameters:
- Return type:
- Returns:
List of minimal loops that contain both edges in the pair (considering both orientations).
- Raises:
ValueError – If the two edges in
edge_pairrefer to the same edge (possibly reversed).
- reorder_minimal_loop_key(minimal_loop, edge_pair)¶
Reorder and reorient a keyed minimal loop to start/end with a specified edge pair.
Given a minimal loop (a cyclic sequence of keyed edges) and a pair of keyed edges
[start, end], this function constructs a new path that:begins with
start,follows the loop in consistent orientation by matching consecutive endpoints, and
ends with
end,
while reversing intermediate edges as needed so that each edge starts at the current vertex. The function ensures the chosen
endedge is oriented to share the base vertex with the start edge (i.e. the start’s first vertex matches the end’s second vertex), if not,endis reversed before path construction.- Parameters:
- Return type:
- Returns:
Reordered minimal loop (list of keyed edges) starting with
startand ending withend.- Raises:
ValueError – If the remaining edges cannot be connected into a continuous path.
- detect_edge_orientation_key(graph, edge, graph_shift)¶
Determine holonomy operator type for an edge relative to an underlying graph orientation.
The edge is shifted by
graph_shift(usingneuralqx.utils.misc.arithmetic.minus_key()) and checked for membership ingraph.edges. If present, the edge is classified as"creation", otherwise it is classified as"annihilation".- Parameters:
- Return type:
- Returns:
Either
"creation"or"annihilation".
- create_dressed_minimal_loop_key(graph, minimal_loop, graph_shift)¶
Attach holonomy-operator metadata to each edge in a keyed minimal loop.
For each edge in
minimal_loop, the function determines the operator type usingdetect_edge_orientation_key()and returns a new “dressed” representation where each entry is a pair:the keyed edge as a tuple
(a, b, k), anda metadata dict containing
{"type": <creation|annihilation>, "key": k}.
- Parameters:
- Return type:
- Returns:
Dressed minimal loop as a list of
((a, b, k), metadata)entries.
- count_contributing_triplets_key(levi_civita_dict, triplets)¶
Count edge triplets with positive Levi-Civita contribution.
The function counts how many edge triplets in
tripletshave Levi-Civita valueε(e₁, e₂, e₃) = +1according tolevi_civita_dict. Triplets are stringified asstr(tuple(triplet))for lookup.This count is used as the contributing-triplets factor (often denoted
T) in regularized Euclidean Thiemann-type constructions.
- get_ml_graph_shift_key(minimal_loop, mapping, adjoint=False)¶
Split a dressed minimal loop into holonomy and adjoint-holonomy edge lists.
The input
minimal_loopis expected to be in “dressed” form where each element contains a keyed edge and a metadata dict with a"type"field. Edges tagged as"creation"are collected under"h"and all others under"ha"after applyingmappingto the keyed edge.If
adjointis True, the roles of"h"and"ha"are swapped in the returned dict.- Parameters:
minimal_loop (
list[tuple[int,int,dict]]) – Dressed minimal loop entries of the form(edge, meta)wheremeta["type"]indicates operator type.mapping (
callable) – Callable applied to each keyed edge prior to insertion into the output lists.adjoint (
bool) – If True, swap the returned lists under keys"h"and"ha".
- Return type:
- Returns:
Dict with keys
"h"and"ha"containing the mapped edge lists.
- get_true_edge_triplet(edge_list, G)¶
Reorient an edge triplet so every edge is present in
G.edges.For each edge in
edge_list, the function checks membership inG.edges. If the edge is not present, it is replaced by its reversed keyed form (endpoint-flipped, key preserved).
- reduce_permutations(perms)¶
Reduce a list of 3-edge permutations by identifying swap-equivalent entries.
Given permutations of triplets
(a, b, c), this function removes duplicates where the last edgecis the same and the first two edges are swapped, i.e. it keeps only one of(a, b, c)and(b, a, c)for each pair.- Parameters:
perms (
List) – List of ordered triplets (permutations) of three edges.- Returns:
Filtered list where swap-equivalent triplets differing only by the order of the first two edges have been removed.