classifier#

Functions

group_by_invariants(diagrams, invariant_funcs)

Group diagrams by shared invariant values.

save_invariants(diagrams, invariant_funcs, path)

Compute and save invariants for diagrams.

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 follows dict.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.

save_invariants(diagrams, invariant_funcs, path, parallel=True, max_workers=None)#

Compute and save invariants for diagrams.

Two modes:
  • parallel=True: treat path as a directory and write one file per diagram.

  • parallel=False: treat path as a single file and write a combined table.

Parameters:
  • diagrams (Iterable[Any]) – Iterable of diagram-like objects.

  • invariant_funcs (Mapping[str, Callable[[Any], Any]] | Callable[[Any], Any]) –

    • Mapping {name: func} for multi-invariant output.

    • Single callable for single-invariant output.

  • path (str | Path) – Directory (parallel) or file path (sequential).

  • parallel (bool) – Use process pool and per-diagram files when True.

  • max_workers (int | None) – Number of workers; defaults to os.cpu_count().

Raises:
  • ValueError – If parallel is True and path is not a directory.

  • ValueError – If parallel is False and path already exists as a directory.

Return type:

None