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¶
One package in the cache and what its sidecar says about it. |
|
Identity of one compiled UMA package. |
|
Compiler side of a package: what the exporting interpreter builds for. |
|
Outcome of |
Functions¶
|
|
|
Metadata torch embedded in the package, as rgpot's loader reads it. |
|
Fields where a package's embedded metadata disagrees with |
|
Every |
|
Resolve a path, a file name, a stem, or a unique stem prefix or digest. |
|
Return the cached package for |
|
|
|
Delete one entry under its key lock. False when it is being prepared. |
|
|
|
Return the |
|
Build the package key for a system and an export environment. |
|
Total electrons of the system: sum(Z) - charge. |
|
Return |
|
Hill-order formula of |
|
Minimal spin multiplicity consistent with electron parity. |
|
Return gcd-reduced |
|
Raise when |
|
Return the package for this system, exporting it on a miss. |
|
Locate rgpot |
Package Contents¶
- class rgpycrumbs.uma.CacheEntry[source]¶
One package in the cache and what its sidecar says about it.
- path: pathlib.Path¶
- property key: rgpycrumbs.uma._key.AotiKey | None¶
- 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 ownAOTI_*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 recordsz_setand the traced input shapes. rgpot’s exporter also embedsnatoms, the per-elementcounts(JSON of atomic number to count), and themodel,torch_versionandfairchem_versionthat compiled it; rgpot’sUmaPotrefuses 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
.pt2in 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
keyfield 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
ExportEnvofpython(default: this interpreter).
- class rgpycrumbs.uma.AotiKey[source]¶
Identity of one compiled UMA package.
- 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]¶
- class rgpycrumbs.uma.ExportEnv[source]¶
Compiler side of a package: what the exporting interpreter builds for.
deviceiscpuorcuda.targetjoins, 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.
- 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=Nonederives the minimal multiplicity from electron parity; an explicitspinis validated against it.batch_maxof 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_moletreats 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.CHNorC2H2.
- 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_molecompares 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 (seeexact_counts()).
- rgpycrumbs.uma.validate_spin(atomic_numbers: collections.abc.Iterable[int], *, charge: int = 0, spin: int = 1) None[source]¶
Raise when
spincannot hold the system’s electron count.Multiplicity is
2S + 1: an even electron count admits only odd multiplicities, an odd count only even ones, andNelectrons reach at mostN + 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¶
- 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=Nonederives the minimal multiplicity from electron parity.pythonis the interpreter that runs the exporter (default: this one) andenvits 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, thenscripts/export_uma_aoti.pyin the working directory or a parent (an rgpot checkout).