neuralqx.utils.symmetries.graph_symmetries module¶
- class GraphSymmetries(edges, *, max_permutation_edges=10, allow_key_permutations=True, max_total_key_permutations=16384)¶
Bases:
objectCompute permutations, cycles, and automorphisms of an oriented multigraph with parallel edges.
The input edges are oriented and may include parallel edges distinguished by an integer key. For structural computations (permutations / cycles / automorphisms), edge orientation is ignored by converting edges to a canonical, orientation-agnostic form (via
_canon_edge). However, the original oriented domain is preserved for indexing and for the concrete permutation objects returned.- Key permutations:
If
allow_key_permutationsis enabled, automorphisms may additionally permute the keys within each unordered vertex pair, i.e. within each multiedge bucket connecting the same two vertices. This can greatly increase the number of automorphisms, so a capmax_total_key_permutationsis used to avoid combinatorial blow-up.
The class lazily computes and caches:
permutations: edge permutations (up to a size cap)cycles: cyclic shifts of the canonical edge orderingautomorphisms: structure-preserving vertex maps (plus optional within-pair key permutations)graph_symmetries: concatenation of the above
- Parameters:
edges (
Iterable[Tuple[int,int,int]]) – Iterable of oriented keyed edges. Orientation is ignored for structure but preserved in the returned symmetry objects’ domain.max_permutation_edges (
int) – If the number of unique canonical edges exceeds this value,permutationsreturns only the identity (avoids factorial growth).allow_key_permutations (
bool) – If True, automorphisms include permutations of keys within each unordered vertex pair when there are multiple parallel edges.max_total_key_permutations (
int) – Upper bound on the total number of combinations of per-pair key permutations for a given vertex automorphism. If this cap is exceeded, key permutations fall back to identity per pair.
- Raises:
ValueError – If no edges are provided, or if duplicate keys occur within an unordered vertex pair.
- property permutations: List[Permutation]¶
Lazily compute and return edge permutations on the canonical edge set.
The returned list always includes the identity permutation. If the number of canonical edges
nis at mostmax_permutation_edges, alln!permutations are generated (excluding the identity which is already included). Ifnexceeds the cap, only the identity permutation is returned to avoid combinatorial blow-up.- Returns:
List of
Permutationobjects acting on the stored domain.
- property cycles: List[Cycle]¶
Lazily compute and return cyclic shifts of the canonical edge ordering.
For
ncanonical edges, this producesncycles, where thek-th cycle maps edge positionito position(i + k) mod nin the canonical ordering.- Returns:
List of
Cycleobjects.
- property automorphisms: List[Automorphism]¶
Lazily compute and return automorphisms of the multigraph.
Automorphisms are computed by enumerating candidate vertex permutations subject to pruning:
Vertices are bucketed by a permutation-invariant signature derived from incident multiedge structure (see
_compute_vertex_invariants()).Only within-bucket vertex permutations are combined (cartesian product across buckets).
Each candidate vertex map is checked for structure preservation (including key multisets per unordered pair).
If
allow_key_permutationsis True, then for each vertex automorphism, all admissible permutations of parallel-edge keys within each mapped unordered vertex pair are also enumerated. The total number of key-permutation combinations is capped bymax_total_key_permutations, if exceeded, key permutations fall back to the identity per pair.The identity automorphism is guaranteed to be included.
- Returns:
List of
Automorphismobjects.
- property graph_symmetries: List[object]¶
Return all computed graph symmetries as a single list.
This is the concatenation of
permutations,cycles, andautomorphismsin that order. The result is cached after first construction.- Returns:
List containing permutations, cycles, and automorphisms.
- property edges: List[Tuple[int, int, int]]¶
Return canonical, orientation-agnostic unique edges in deterministic order.
These edges represent the structural edge set used for symmetry computations. To iterate edges in a way that respects the original oriented input, iterate over the emitted Permutation/Cycle/Automorphism objects (which carry
domainbuilt from the oriented input).- Returns:
List of canonical edges.
- property vertices: List[int]¶
Return the sorted list of vertices present in the canonical edge set.
- Returns:
List of vertex ids in deterministic order.
- make_permutation_from_order(new_order, name='custom')¶
Build a
Permutationfrom a provided ordering of the canonical edge set.The provided
new_ordermust be a permutation ofedgesup to canonicalization. Oriented versions are allowed, only their canonical forms are used for validity and mapping.- Parameters:
- Return type:
- Returns:
A
Permutationmapping the current canonical ordering tonew_order.- Raises:
ValueError – If
new_orderis not a permutation of the canonical edge set.