-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open HDF5 file only once #1251
Open HDF5 file only once #1251
Conversation
Reduce the number of times the HDF5 file is opened from 77 to 46 - which is a 40% reduction. From the 46 remaining calls 7 are handled via the new |
|
@jan-janssen and I just discussed a slightly more formalized version of this that would add a new class HasStorageDict(ABC):
@abstractmethod
def _to_storage_dict(self):
pass
def type_storage_dict(self):
return {
"NAME": self.__name__,
"TYPE": str(type(self)),
}
def to_storage_dict(self):
data_dict = self.type_storage_dict()
data_dict.update(self._to_storage_dict())
return data_dict
@classmethod
@abstractmethod
def _from_storage_dict(cls, data_dict):
pass and expanding class HasHDF(HasStorageDict):
...
def _to_storage_dict(self):
hdf = DummyHDFio(...)
self.to_hdf(hdf)
return hdf.to_dict()
@classmethod
def _from_storage_dict(cls, data_dict):
hdf = DummyHDFio(..., data_dict)
obj = cls(**cls._from_hdf_args(hdf))
obj.from_hdf(hdf)
return obj Similarly every class HasStorageDict(ABC):
...
def to_hdf(self, hdf):
write_dict_to_hdf(hdf, self._to_storage_dict()) where write_dict_to_hdf comes also from this PR. (A mirroring read_dict_from_hdf seems to be still missing) This sort of setup would have the advantage that later we could plug in |
# Conflicts: # pyiron_base/interfaces/has_hdf.py
Example: