Skip to content
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

Add a dummy ProjectHDFio class for generic to_dict() #1178

Merged
merged 7 commits into from
Nov 30, 2023
Merged

Add a dummy ProjectHDFio class for generic to_dict() #1178

merged 7 commits into from
Nov 30, 2023

Conversation

pmrv
Copy link
Contributor

@pmrv pmrv commented Aug 22, 2023

DummyHDFio implements a minimal subset of methods of ProjectHDFio to allow any object implementing HasHDF or the to_hdf/from_hdf convention to write itself into it. Afterwards a plain dict of everything stored to "HDF" can be obtained by DummyHDFio.to_hdf().

>>> hdf = DummyHDFio(Project(...), '/', {})
>>> obj = MyFancyObject()
>>> obj.to_hdf(hdf)
>>> hdf.to_dict()
{...}

@pmrv pmrv added the enhancement New feature or request label Aug 22, 2023
@pmrv pmrv requested a review from jan-janssen August 22, 2023 03:37
@pmrv
Copy link
Contributor Author

pmrv commented Aug 22, 2023

This is code copied over from tinybase. Originally my plan was to stabilize GenericStorage over in contrib and then move things here, but seeing that we already want functionality like this in atomistics I just pulled the dummy class for now. This exact implementation I've only tested for writing DataContainers, but from my testing in tinybase I expect this to work for most hdf objects.

pmrv added 3 commits August 27, 2023 03:39
DummyHDFio implements a minimal subset of methods of ProjectHDFio to
allow any object implementing HasHDF or the to_hdf/from_hdf convention
to write itself into it.  Afterwards a plain dict of everything stored
to "HDF" can be obtained by DummyHDFio.to_hdf().

>>> hdf = DummyHDFio(Project(...), '/', {})
>>> obj = MyFancyObject()
>>> obj.to_hdf(hdf)
>>> hdf.to_dict()
{...}
@pmrv
Copy link
Contributor Author

pmrv commented Aug 27, 2023

Last two commit also added support for to_object() and some bug fixes for Atoms, i.e. you can now something like

hdf = DummyHDFio(pr, '/')
cu = pr.create.structure.bulk('Cu')
cu.to_hdf(hdf, 'my_copper')
hdf['my_copper'].to_object() == cu

or maybe more interestingly

hdf = DummyHDFio(pr, '/')
cu = pr.create.structure.bulk('Cu')
cu.to_hdf(hdf, 'my_copper')
cu_dict = hdf.to_dict()
# transfer cu_dict to another machine via some executor or channel
cu == DummyHDFio(pr, '/', cu_dict)['my_copper'].to_object()

@stale
Copy link

stale bot commented Oct 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 15, 2023
@stale stale bot removed the stale label Nov 30, 2023
@pmrv pmrv added integration Start the integration tests with pyiron_atomistics/contrib for this PR format_black reformat the code using the black standard labels Nov 30, 2023
@pmrv pmrv merged commit 4649442 into main Nov 30, 2023
@delete-merged-branch delete-merged-branch bot deleted the genhdf branch November 30, 2023 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request format_black reformat the code using the black standard integration Start the integration tests with pyiron_atomistics/contrib for this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants