group_by_invariants#
- group_by_invariants(diagrams, invariant_funcs, parallel=True, max_workers=None)#
Group diagrams by shared invariant values.
- Parameters:
diagrams (Iterable[Any]) – Iterable of diagram-like objects.
invariant_funcs (Mapping[str, Callable[[Any], Any]] | Callable[[Any], Any]) –
If a mapping
{name: func}
, group by multiple invariants. The key is a tuple((name, value), ...)
(order followsdict.items()
).If a single callable, group by that invariant value.
parallel (bool) – Compute invariants in parallel using processes.
max_workers (int | None) – Number of workers; defaults to
os.cpu_count()
.
- Returns:
Mapping from invariant key(s) to a list of diagrams.
- Return type:
dict[Any, list[Any]]
Notes
Functions must be picklable for process pools (no lambdas/closures).
Exceptions in worker functions are swallowed; the offending diagram is skipped.