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

Pickle API: Avoid static Series hack, allow multiple Series #1633

Merged
merged 8 commits into from
Jul 23, 2024

Conversation

franzpoeschel
Copy link
Contributor

@franzpoeschel franzpoeschel commented Jun 12, 2024

Close #1458

Theoretically, it should be possible to modify our public API such that each handle, not only the Series handle would keep alive the Series, but that would require some greater internal restructuring.

Instead, this PR avoids the problem of finding a place to store the Series not by putting it in a static variable, but by hiding it inside the returned value's destructor. This does not lead to a reference cycle because the returned handle is a non-owning shared pointer whose destructor lambda owns all actual data. As soon as the handle is let go, the destructor is run and the owned objects are freed.

  • We could still use static (or better thread_local) to cache the latest opened Series for workflows that unpickle lots of single objects
  • Maybe take the chance to introduce pickling for Series and Iteration

@pordyna Can you check if this helps your use case?

@franzpoeschel franzpoeschel requested a review from ax3l June 12, 2024 13:55
@franzpoeschel franzpoeschel added this to the 0.16.0 milestone Jun 12, 2024
@franzpoeschel franzpoeschel force-pushed the unpickle-multiple-series branch 2 times, most recently from e5ea191 to 010cacd Compare June 17, 2024 13:18
@franzpoeschel franzpoeschel force-pushed the unpickle-multiple-series branch 2 times, most recently from c465a65 to d04a687 Compare June 18, 2024 11:31
Copy link
Contributor

@pordyna pordyna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franzpoeschel Just tested and it works. I can now change series within one kernel instance.
Btw. I didn't new that, but one can install the api from a specific branch with pip like this pip install git+https://github.com/franzpoeschel/openPMD-api.git@unpickle-multiple-series, pretty cool.

@franzpoeschel
Copy link
Contributor Author

Nice, thank you for testing this!

Btw. I didn't new that, but one can install the api from a specific branch with pip like this pip install git+https://github.com/franzpoeschel/openPMD-api.git@unpickle-multiple-series, pretty cool.

I didn't know that either. But I guess it means that you need to install ADIOS2 or HDF5 manually before that since they have no Pip packages? We usually just build them into the Wheel, but that doesn't help when compiling manually.

@pordyna
Copy link
Contributor

pordyna commented Jun 20, 2024

I didn't know that either. But I guess it means that you need to install ADIOS2 or HDF5 manually before that since they have no Pip packages? We usually just build them into the Wheel, but that doesn't help when compiling manually.

I have installed adios2, hdf5, and blosc with conda. But see, https://pypi.org/project/adios2/ there is adios on pypi.

@franzpoeschel
Copy link
Contributor Author

I have installed adios2, hdf5, and blosc with conda. But see, https://pypi.org/project/adios2/ there is adios on pypi.

Ah right, they actually have a package by now. Maybe we should add this as an optional dependency in our Pip-package @ax3l

@franzpoeschel franzpoeschel mentioned this pull request Jul 11, 2024
3 tasks
@ax3l ax3l self-assigned this Jul 16, 2024
Comment on lines +497 to +515
template <typename T>
T &makeOwning(T &self, Series s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a nice doxygen string here :D


namespace internal
{
template <typename T>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe document the idea here with a little inline comment

// for DASK.
static auto series = openPMD::Series(filename, Access::READ_ONLY);
return seriesAccessor(series, group);
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's isolate this to a separate PR which goes into the 0.17 development branch

@franzpoeschel franzpoeschel force-pushed the unpickle-multiple-series branch 2 times, most recently from 645519d to 1a18e76 Compare July 17, 2024 08:41
@franzpoeschel franzpoeschel requested a review from ax3l July 23, 2024 13:56
@franzpoeschel franzpoeschel merged commit 74fdc47 into openPMD:dev Jul 23, 2024
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pickle w/o Statics
3 participants