From d5bef6714328b56d93d8e23ae4cf16114669bf37 Mon Sep 17 00:00:00 2001 From: James Spencer Date: Wed, 21 Feb 2024 11:00:06 +0000 Subject: [PATCH] Drop unused H5Writer wrapper around pytables. PiperOrigin-RevId: 608923518 Change-Id: Idf0b95be4790997ecec94d53e059809bc840b6a3 --- ferminet/utils/writers.py | 70 +-------------------------------------- setup.py | 1 - 2 files changed, 1 insertion(+), 70 deletions(-) diff --git a/ferminet/utils/writers.py b/ferminet/utils/writers.py index da0e682..8ccf7ac 100644 --- a/ferminet/utils/writers.py +++ b/ferminet/utils/writers.py @@ -15,10 +15,9 @@ import contextlib import os -from typing import Mapping, Optional, Sequence +from typing import Optional, Sequence from absl import logging -import tables class Writer(contextlib.AbstractContextManager): @@ -78,70 +77,3 @@ def write(self, t: int, **data): def __exit__(self, exc_type, exc_val, exc_tb): self._file.close() - - -class H5Writer(contextlib.AbstractContextManager): - """Write data to HDF5 files.""" - - def __init__(self, - name: str, - schema: Mapping[str, Sequence[int]], - directory: str = '', - index_key: str = 't', - compression_level: int = 5): - """Initialise H5Writer. - - Args: - name: file name for CSV. - schema: dict of keys, corresponding to each data item . All data is - assumed ot be 32-bit floats. - directory: directory path to write file to. - index_key: name of (integer) key used to index each entry. - compression_level: compression level (0-9) used to compress HDF5 file. - """ - self._path = os.path.join(directory, name) - self._schema = schema - self._index_key = index_key - self._description = {} - self._file = None - self._complevel = compression_level - - def __enter__(self): - if not self._schema: - return self - pos = 1 - self._description[self._index_key] = tables.Int32Col(pos=pos) - for key, shape in self._schema.items(): - pos += 1 - self._description[key] = tables.Float32Col(pos=pos, shape=shape) - if not os.path.isdir(os.path.dirname(self._path)): - os.mkdir(os.path.dirname(self._path)) - self._file = tables.open_file( - self._path, - mode='w', - title='Fermi Net Data', - filters=tables.Filters(complevel=self._complevel)) - self._table = self._file.create_table( - where=self._file.root, name='data', description=self._description) - return self - - def write(self, index: int, data): - """Write data to HDF5 file. - - Args: - index: iteration index. - data: dict of arrays to write to file. Only elements with keys in the - schema are written. - """ - if self._file: - h5_data = (index,) - for key in self._description: - if key != self._index_key: - h5_data += (data[key],) - self._table.append([h5_data]) - self._table.flush() - - def __exit__(self, exc_type, exc_val, exc_tb): - if self._file: - self._file.close() - self._file = None diff --git a/setup.py b/setup.py index b9d8c1f..80e785a 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,6 @@ 'pyscf', 'pyblock', 'scipy', - 'tables', 'typing_extensions', ]