Honor the CLI key specification in LMDBDataset#1
Open
lollcat wants to merge 2 commits into
Open
Conversation
`LMDBDataset.__getitem__` hardcoded `KeySpecification.from_defaults()`, so CLI key overrides such as `--total_charge_key` / `--total_spin_key` were silently ignored for `.aselmdb` / `.lmdb` datasets. Because the defaults map `total_charge <- "total_charge"` and `total_spin <- "total_spin"` (keys absent from OMol data, which stores `charge` / `spin`), every system was loaded as a neutral closed-shell singlet regardless of its true charge/spin. Thread `head_config.key_specification` through `load_dataset_for_path` into the `LMDBDataset` constructors, and honor it in `__getitem__` (falling back to the defaults when none is supplied, so existing behavior is unchanged). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Regression guard for the previous commit: a key spec built from --total_charge_key / --total_spin_key must reach the loaded data (and the defaults still apply when none is passed). Fails on the pre-fix code with total_charge defaulting to 0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
lollcat
force-pushed
the
fix/lmdb-key-specification
branch
from
July 7, 2026 18:07
c92b736 to
7905d38
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
LMDBDataset.__getitem__hardcodesKeySpecification.from_defaults()when building each config:So CLI key overrides such as
--total_charge_key/--total_spin_keyare silently ignored for.aselmdb/.lmdbdatasets —load_dataset_for_pathnever passes the parsed key specification toLMDBDataset, and__getitem__would ignore it even if it did.This bites OMol-style data. The defaults map
total_charge <- "total_charge"andtotal_spin <- "total_spin", but OMol stores these underdata["charge"]/data["spin"](surfaced byget_atomsasatoms.info["charge"]/["spin"]). The mapped keys are absent, sototal_charge/total_spinfall back to0.0/1.0— every system is loaded as a neutral closed-shell singlet, regardless of the flags on the command line.For example,
mace-foundations/mace_omol/mace-omol.shpasses--total_charge_key="charge" --total_spin_key="spin", but these currently have no effect on the LMDB path.Fix
Thread
head_config.key_specificationthroughload_dataset_for_pathinto theLMDBDatasetconstructors, and honor it in__getitem__— falling back toKeySpecification.from_defaults()when none is supplied, so existing behavior is unchanged.LMDBDatasetis the only on-the-fly reader that appliedconfig_from_atomswith a hardcoded spec; HDF5 datasets bake the key mapping in at write time.Tests
Two regression tests in
tests/test_lmdb_database.py, each writing a one-molecule.aselmdbwithdata={"charge": -1, "spin": 3}(the OMol layout) and asserting the key spec built from--total_charge_key=charge --total_spin_key=spinyieldstotal_charge == -1,total_spin == 3:test_lmdb_dataset_honors_key_specification— constructsLMDBDataset(..., key_specification=...)directly (also checks the no-spec default still gives0 / 1). Guards thelmdb_dataset.pyhalf; fails on pre-fix code (total_chargedefaults to0).test_load_dataset_for_path_forwards_key_specification— callsload_dataset_for_pathwith a minimalSimpleNamespace(head_name=..., key_specification=...). Guards therun_train_utils.pydispatch half; fails when only that half is reverted.Reproduction
Self-contained (synthesizes a one-molecule
.aselmdb, no external data):Before (develop):
After (this branch):
Checks
black(26.5.1) andisort(8.0.1): clean on the changed source files.pylintwith the repo's hook args:10.00/10on both changed files.pytest tests/test_lmdb_database.py: 3 passed (existing + 2 new).tests/test_data.py: 9 passed. Full suite collects (518 tests) with no import errors.tests/is excluded from the formatting hooks in.pre-commit-config.yaml, so the added test is not reformatted.