nvalchemi.data.Reader#

class nvalchemi.data.Reader(*, pin_memory=False, include_index_in_metadata=True)[source]#

Abstract base class for data readers.

Readers are intentionally simple and transactional:

  • Load data from a source (file, database, etc.)

  • Return (dict[str, torch.Tensor], metadata_dict) tuples with CPU tensors

  • No threading, no prefetching, no device transfers

Subclasses must implement _load_sample() and __len__().

Parameters:
  • pin_memory (bool, default=False) – If True, pin loaded tensors to page-locked memory for faster async CPU→GPU transfers.

  • include_index_in_metadata (bool, default=True) – If True, automatically add "index" to each sample’s metadata dict.

Examples

>>> class MyReader(Reader):
...     def _load_sample(self, index: int) -> dict[str, torch.Tensor]:
...         return {"x": torch.randn(3)}
...     def __len__(self) -> int:
...         return 10
>>> reader = MyReader()
>>> data, meta = reader[0]
close()[source]#

Release resources held by the reader.

Override in subclasses to close file handles, connections, etc.

Return type:

None

property field_names: list[str]#

Field names available in each sample.

Returns:

Field names.

Return type:

list[str]