rgpycrumbs.uma._key

Cache key of one UMA AOTI package.

A package is reusable only when every input that shaped the compiled graph matches: the exact composition, charge, spin multiplicity and task head (merge_mole folds them into the weights), the checkpoint, the tracing dtype and the static-shape options (molecular box, band size), and the compiler side (device, its CPU ISA or CUDA compute capability, and the torch and fairchem versions).

Attributes

Classes

ExportEnv

Compiler side of a package: what the exporting interpreter builds for.

AotiKey

Identity of one compiled UMA package.

Functions

exact_counts(→ tuple[tuple[int, int], Ellipsis])

Return (Z, count) pairs, sorted by Z, without reduction.

reduced_counts(→ tuple[tuple[int, int], Ellipsis])

Return gcd-reduced (Z, count) pairs, sorted by Z.

hill_formula(→ str)

Hill-order formula of (Z, count) pairs, e.g. CHN or C2H2.

electron_count(→ int)

Total electrons of the system: sum(Z) - charge.

minimal_spin(→ int)

Minimal spin multiplicity consistent with electron parity.

validate_spin(→ None)

Raise when spin cannot hold the system's electron count.

canonical_float(→ str)

Stable text for a float option: 25.0 and 25 both give 25.

_safe(→ str)

aoti_key(→ AotiKey)

Build the package key for a system and an export environment.

Module Contents

rgpycrumbs.uma._key.KEY_SCHEMA = 1[source]
rgpycrumbs.uma._key.TARGET_FIELDS = ('AOTI_MACHINE', 'AOTI_CPU_ISA', 'AOTI_COMPUTE_CAPABILITY')[source]
rgpycrumbs.uma._key._SYMBOLS[source]
rgpycrumbs.uma._key.exact_counts(atomic_numbers: collections.abc.Iterable[int]) → tuple[tuple[int, int], Ellipsis][source]

Return (Z, count) pairs, sorted by Z, without reduction.

An AOTI export freezes per-atom buffers at the example system’s size, so a package compiled for C2H2 aborts inside the compiled graph when fed C4H4 even though fairchem merge_mole treats the two as the same reduced composition. The cache key therefore uses the exact composition, never the gcd-reduced one.

rgpycrumbs.uma._key.reduced_counts(atomic_numbers: collections.abc.Iterable[int]) → tuple[tuple[int, int], Ellipsis][source]

Return gcd-reduced (Z, count) pairs, sorted by Z.

Fairchem merge_mole compares reduced compositions: C2H2 and C4H4 both reduce to ((1, 1), (6, 1)). This is the model-side equivalence for expert merging; it is NOT sufficient to reuse an AOTI package (see exact_counts()).

rgpycrumbs.uma._key.hill_formula(counts: collections.abc.Iterable[tuple[int, int]]) → str[source]

Hill-order formula of (Z, count) pairs, e.g. CHN or C2H2.

rgpycrumbs.uma._key.electron_count(atomic_numbers: collections.abc.Iterable[int], *, charge: int = 0) → int[source]

Total electrons of the system: sum(Z) - charge.

rgpycrumbs.uma._key.minimal_spin(atomic_numbers: collections.abc.Iterable[int], *, charge: int = 0) → int[source]

Minimal spin multiplicity consistent with electron parity.

Even electron count gives a singlet (1); odd gives a doublet (2).

rgpycrumbs.uma._key.validate_spin(atomic_numbers: collections.abc.Iterable[int], *, charge: int = 0, spin: int = 1) → None[source]

Raise when spin cannot hold the system’s electron count.

Multiplicity is 2S + 1: an even electron count admits only odd multiplicities, an odd count only even ones, and N electrons reach at most N + 1. A mismatch (for example a 23-electron radical declared a singlet) selects an unphysical PES from a spin-conditioned model.

rgpycrumbs.uma._key.canonical_float(value: float) → str[source]

Stable text for a float option: 25.0 and 25 both give 25.

class rgpycrumbs.uma._key.ExportEnv[source]

Compiler side of a package: what the exporting interpreter builds for.

device is cpu or cuda. target joins, with |, the fields torch records in the package metadata for the machine it compiled on (TARGET_FIELDS): the architecture, the CPU vector ISA and, for CUDA, the compute capability. A package built for another target fails to load or runs illegal instructions.

device: str[source]
target: str[source]
torch: str[source]
fairchem: str[source]
class rgpycrumbs.uma._key.AotiKey[source]

Identity of one compiled UMA package.

counts: tuple[tuple[int, int], Ellipsis][source]
charge: int[source]
spin: int[source]
task: str[source]
model: str[source]
dtype: str[source]
molecular_box: str[source]
batch_max: int[source]
device: str[source]
target: str[source]
torch: str[source]
fairchem: str[source]
schema: int = 1[source]
property formula: str[source]
property natoms: int[source]
property z_set: list[int][source]
as_dict() → dict[str, Any][source]

JSON-ready form; from_dict() inverts it exactly.

classmethod from_dict(data: collections.abc.Mapping[str, Any]) → AotiKey[source]
canonical() → str[source]
digest() → str[source]

80-bit hex digest of every field.

stem() → str[source]

File stem: readable prefix plus the digest of the full key.

omol-CHN-q0-s1-uma-s-1p1-cpu-<digest>. The prefix is for people; the digest is what separates two keys.

rgpycrumbs.uma._key._safe(text: str) → str[source]
rgpycrumbs.uma._key.aoti_key(atomic_numbers: collections.abc.Iterable[int], env: ExportEnv, *, charge: int = 0, spin: int | None = None, task: str = 'omol', model: str = 'uma-s-1p1', dtype: str = 'float32', molecular_box: float = 0.0, batch_max: int = 0) → AotiKey[source]

Build the package key for a system and an export environment.

spin=None derives the minimal multiplicity from electron parity; an explicit spin is validated against it. batch_max of 0 and 1 both mean a single-system package.