rgpycrumbs.uma

UMA AOTI package preparation for rgpot’s UmaPot.

rgpot scripts/export_uma_aoti.py compiles one UMA checkpoint, for one system, into an AOTInductor .pt2 that UmaPot loads. This package keys those compiles, caches them, and runs the exporter only on a miss.

An AOTI export freezes per-atom buffers at the example system’s size, and merge_mole folds the composition, charge and spin into the weights, so a package is keyed by the exact composition, never by the fairchem reduced composition, which accepts systems the compiled graph then aborts on. Spin defaults to the minimal multiplicity for the electron parity, and an explicit spin is validated against that parity. The rest of the key (see AotiKey) covers the model, dtype, static-shape options and the compiler side.

The library is standard library only; torch and fairchem are needed by the exporter, which runs in the interpreter of the rgpycrumbs uma prepare-aoti script.

Added in version 1.12.0.

Submodules

Attributes

Classes

CacheEntry

One package in the cache and what its sidecar says about it.

AotiKey

Identity of one compiled UMA package.

ExportEnv

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

Prepared

Outcome of prepare_uma_aoti().

Functions

default_cache_dir(→ pathlib.Path)

$RGPYCRUMBS_UMA_CACHE, else $XDG_CACHE_HOME/rgpycrumbs/uma.

embedded_metadata(→ dict[str, Any])

Metadata torch embedded in the package, as rgpot's loader reads it.

embedded_mismatches(→ list[str])

Fields where a package's embedded metadata disagrees with key.

entries(→ list[CacheEntry])

Every .pt2 in the cache, sorted by name.

find_entry(→ CacheEntry)

Resolve a path, a file name, a stem, or a unique stem prefix or digest.

lookup(→ pathlib.Path | None)

Return the cached package for key, or None on a miss.

package_path(→ pathlib.Path)

remove(→ bool)

Delete one entry under its key lock. False when it is being prepared.

sidecar_path(→ pathlib.Path)

probe_env(→ rgpycrumbs.uma._key.ExportEnv)

Return the ExportEnv of python (default: this interpreter).

aoti_key(→ AotiKey)

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

electron_count(→ int)

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

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

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

hill_formula(→ str)

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

minimal_spin(→ int)

Minimal spin multiplicity consistent with electron parity.

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

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

validate_spin(→ None)

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

prepare_uma_aoti(→ Prepared)

Return the package for this system, exporting it on a miss.

resolve_exporter(→ pathlib.Path)

Locate rgpot scripts/export_uma_aoti.py.

Package Contents

class rgpycrumbs.uma.CacheEntry[source]

One package in the cache and what its sidecar says about it.

path: pathlib.Path
sidecar: dict[str, Any] | None
property key: rgpycrumbs.uma._key.AotiKey | None
property stem: str
property size: int
rgpycrumbs.uma.default_cache_dir() → pathlib.Path[source]

$RGPYCRUMBS_UMA_CACHE, else $XDG_CACHE_HOME/rgpycrumbs/uma.

rgpycrumbs.uma.embedded_metadata(pt2: pathlib.Path) → dict[str, Any][source]

Metadata torch embedded in the package, as rgpot’s loader reads it.

The exporter passes its runtime contract through aot_inductor.metadata; torch stores it, plus its own AOTI_* device fields, as string values in <name>/data/aotinductor/<model>/*_metadata.json. This reads the archive directly, so it needs no torch.

rgpycrumbs.uma.embedded_mismatches(meta: collections.abc.Mapping[str, Any], key: rgpycrumbs.uma._key.AotiKey) → list[str][source]

Fields where a package’s embedded metadata disagrees with key.

Embedded values are strings (torch stores str(value)). Every package records z_set and the traced input shapes. rgpot’s exporter also embeds natoms, the per-element counts (JSON of atomic number to count), and the model, torch_version and fairchem_version that compiled it; rgpot’s UmaPot refuses an input whose counts differ. Those fields are checked when present, so a package from an older exporter still passes on the element set and the traced atom count.

rgpycrumbs.uma.entries(cache_dir: pathlib.Path) → list[CacheEntry][source]

Every .pt2 in the cache, sorted by name.

rgpycrumbs.uma.find_entry(cache_dir: pathlib.Path, name: str) → CacheEntry[source]

Resolve a path, a file name, a stem, or a unique stem prefix or digest.

rgpycrumbs.uma.lookup(cache_dir: pathlib.Path, key: rgpycrumbs.uma._key.AotiKey) → pathlib.Path | None[source]

Return the cached package for key, or None on a miss.

A hit needs the package and a sidecar whose stored key equals key field by field, so a digest collision can never return the wrong package.

rgpycrumbs.uma.package_path(cache_dir: pathlib.Path, key: rgpycrumbs.uma._key.AotiKey) → pathlib.Path[source]
rgpycrumbs.uma.remove(cache_dir: pathlib.Path, entry: CacheEntry, *, wait: bool = False) → bool[source]

Delete one entry under its key lock. False when it is being prepared.

rgpycrumbs.uma.sidecar_path(pt2: pathlib.Path) → pathlib.Path[source]
rgpycrumbs.uma.probe_env(cache_dir: pathlib.Path, *, python: str | None = None, device: str = 'cpu') → rgpycrumbs.uma._key.ExportEnv[source]

Return the ExportEnv of python (default: this interpreter).

rgpycrumbs.uma.KEY_SCHEMA = 1[source]
class rgpycrumbs.uma.AotiKey[source]

Identity of one compiled UMA package.

counts: tuple[tuple[int, int], Ellipsis]
charge: int
spin: int
task: str
model: str
dtype: str
molecular_box: str
batch_max: int
device: str
target: str
torch: str
fairchem: str
schema: int = 1
property formula: str
property natoms: int
property z_set: list[int]
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.

class rgpycrumbs.uma.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
target: str
torch: str
fairchem: str
rgpycrumbs.uma.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.

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

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

rgpycrumbs.uma.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.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.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.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.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.

class rgpycrumbs.uma.Prepared[source]

Outcome of prepare_uma_aoti().

path: pathlib.Path
key: rgpycrumbs.uma._key.AotiKey
hit: bool
compile_seconds: float | None = None
command: list[str] = []
rgpycrumbs.uma.prepare_uma_aoti(atomic_numbers: collections.abc.Iterable[int], *, charge: int = 0, spin: int | None = None, task: str = 'omol', model: str = 'uma-s-1p1', device: str = 'cpu', molecular_box: float = 0.0, batch_max: int = 0, cache_dir: pathlib.Path | None = None, atoms_path: pathlib.Path | None = None, exporter: pathlib.Path | None = None, python: str | None = None, env: rgpycrumbs.uma._key.ExportEnv | None = None, force: bool = False, dry_run: bool = False) → Prepared[source]

Return the package for this system, exporting it on a miss.

spin=None derives the minimal multiplicity from electron parity. python is the interpreter that runs the exporter (default: this one) and env its probed compiler side (default: probe it). A miss takes the key’s lock, so concurrent callers for one key run the exporter once and the rest return its package. The finished package is checked against the key through its embedded metadata before it is installed.

rgpycrumbs.uma.resolve_exporter(explicit: str | os.PathLike[str] | None = None) → pathlib.Path[source]

Locate rgpot scripts/export_uma_aoti.py.

Order: explicit, $RGPOT_EXPORT_UMA, PATH, then scripts/export_uma_aoti.py in the working directory or a parent (an rgpot checkout).