nvalchemi.data.AtomicDataZarrReader#

class nvalchemi.data.AtomicDataZarrReader(store, *, pin_memory=False, include_index_in_metadata=True, fields=None)[source]#

Reader for loading AtomicData from Zarr stores.

This reader provides random-access loading of AtomicData samples from Zarr stores created by AtomicDataZarrWriter. It supports soft-deleted samples via the samples_mask and provides efficient random access using pointer arrays.

The Zarr store layout expected is:

dataset.zarr/
+-- meta/                       # Pointer arrays + masks
|   +-- atoms_ptr               # int64 [N+1] -- cumulative node counts
|   +-- edges_ptr               # int64 [N+1] -- cumulative edge counts
|   `-- samples_mask            # bool [N] -- False = deleted sample
|
+-- core/                       # AtomicData fields
|   +-- atomic_numbers          # int64 [V_total]
|   +-- positions               # float32 [V_total, 3]
|   `-- ...
|
`-- custom/                     # User-defined arrays (optional)
Parameters:
  • store (StoreLike) – Any zarr-compatible store: filesystem path (str or Path), or a zarr Store instance (LocalStore, MemoryStore, FsspecStore, etc.), StorePath, or a dict for in-memory buffer storage.

  • pin_memory (bool, default=False) – If True, place tensors in pinned (page-locked) memory for faster async CPU->GPU transfers.

  • include_index_in_metadata (bool, default=True) – If True, include sample index in the metadata dict.

  • fields (Sequence[str] | None, default=None) – Optional ordered selection of fields returned for each sample. When provided, every name must exist in the store. The selection is copied to an immutable tuple and applied before chunk-locality planning.

_store#

The underlying zarr store reference.

Type:

StoreLike

Examples

>>> from nvalchemi.data.datapipes.backends.zarr import AtomicDataZarrReader
>>> reader = AtomicDataZarrReader(store="dataset.zarr")
>>> data_dict, metadata = reader[0]  # returns dict and metadata
>>> atomic_data = AtomicDataZarrReader.to_atomic_data(data_dict)
check_integrity()[source]#

Raise when the store’s arrays disagree about how many samples it holds.

An append interrupted between extending the pointers, masks, and field arrays and committing num_samples leaves them at different lengths, after which every sample past the torn one reads misaligned. Only array metadata is inspected, so no chunk is read.

Raises:
  • ValueError – If the store records no committed sample count, the atom or edge pointer is not non-decreasing from zero, the store declares a field it holds no array for, or a pointer, mask, or field array holds a number of rows other than the committed samples account for.

  • RuntimeError – If the reader has been closed.

Return type:

None

close()[source]#

Release the Zarr store reference and clean up resources.

Return type:

None

field_array(field)[source]#

Return the Zarr array backing field.

Parameters:

field (str) – Name of a field the store holds, at any level.

Returns:

The array under core/, custom/, or levels/<level>/.

Return type:

zarr.Array

Raises:
  • KeyError – If the store holds no array named field.

  • RuntimeError – If the reader has been closed.

property field_levels: dict[str, str]#

Per-field level classification from store metadata.

Returns:

Mapping of field name to a built-in alias or registered custom level name.

Return type:

dict[str, str]

get_metadata(index)[source]#

Return atom and edge counts from cached pointer arrays.

Parameters:

index (int) – Logical sample index. Negative values are supported.

Returns:

(num_atoms, num_edges) for the sample.

Return type:

tuple[int, int]

property level_schema: LevelSchema | None#

Return the persisted custom-level schema.

Returns:

An independent schema clone for a versioned custom-level store, or None for a legacy store.

Return type:

LevelSchema | None

level_sizes()[source]#

Return the number of rows every level of the store holds.

Returns:

"atom" and "edge" follow the atom and edge pointers, "system" has one row per stored sample, and each registered custom level follows its own pointer, or has one row per sample when it is uniform. A segmented custom level whose pointer was never written, because no field materialized it, is left out.

Return type:

dict[str, int]

property num_samples: int#

Number of samples the store holds, soft-deleted ones included.

Returns:

Length of meta/samples_mask; len(reader) counts only the active samples.

Return type:

int

refresh()[source]#

Reload cached pointer arrays, masks, and metadata from the store.

Call this method after external modifications to the Zarr store (e.g., appending or deleting samples via AtomicDataZarrWriter) to ensure the reader reflects the current state of the data.

Raises:
  • RuntimeError – If the reader has been closed.

  • ValueError – If a versioned custom-level layout is malformed.

  • KeyError – If any selected field is absent from the refreshed store.

Return type:

None

schema()[source]#

Return the level, dtype, and row shape of every field the store holds.

Dtypes come from the array metadata, so no chunk is read. The row shape leaves out the axis rows are stored along: the one a built-in field’s name assigns, and axis 0 for every custom array.

Returns:

One FieldSchema per stored field, keyed by field name.

Return type:

dict[str, FieldSchema]

Raises:

RuntimeError – If the reader has been closed.

property store: Store | StorePath | Path | str | dict[str, Any]#

Store reference this reader was opened with.

Returns:

The path, URI, or store object passed at construction, unchanged.

Return type:

StoreLike