-
Notifications
You must be signed in to change notification settings - Fork 55
Pickle API: Avoid static Series hack, allow multiple Series #1633
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
Merged
franzpoeschel
merged 8 commits into
openPMD:dev
from
franzpoeschel:unpickle-multiple-series
Jul 23, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
de34714
Defer iteration parsing
franzpoeschel 640cfbd
Add first attempt of createOwningCopy
franzpoeschel bbc29ed
Continue...
franzpoeschel f39d69e
seems to work??
franzpoeschel 1fa97ac
Reenable the Python tests
franzpoeschel 71c7f75
Add pickling for Iteration and Series too
franzpoeschel 5cba031
Add pickle support for Series and Iteration
franzpoeschel 0f99488
Document new internal function
franzpoeschel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,9 +20,12 @@ | |
| */ | ||
| #include "openPMD/backend/Attributable.hpp" | ||
| #include "openPMD/Iteration.hpp" | ||
| #include "openPMD/ParticleSpecies.hpp" | ||
| #include "openPMD/RecordComponent.hpp" | ||
| #include "openPMD/Series.hpp" | ||
| #include "openPMD/auxiliary/DerefDynamicCast.hpp" | ||
| #include "openPMD/auxiliary/StringManip.hpp" | ||
| #include "openPMD/backend/Attribute.hpp" | ||
|
|
||
| #include <algorithm> | ||
| #include <complex> | ||
|
|
@@ -505,4 +508,53 @@ void Attributable::linkHierarchy(Writable &w) | |
| writable().parent = &w; | ||
| setDirty(true); | ||
| } | ||
|
|
||
| namespace internal | ||
| { | ||
| template <typename T> | ||
| T &makeOwning(T &self, Series s) | ||
|
Comment on lines
+514
to
+515
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a nice doxygen string here :D |
||
| { | ||
| /* | ||
| * `self` is a handle object such as RecordComponent or Mesh (see | ||
| * instantiations below). | ||
| * These objects don't normally keep alive the Series, i.e. as soon as | ||
| * the Series is destroyed, the handle becomes invalid. | ||
| * This function modifies the handle such that it actually keeps the | ||
| * Series alive and behaves otherwise identically. | ||
| * First, get the internal shared pointer of the handle. | ||
| */ | ||
| std::shared_ptr<typename T::Data_t> data_ptr = self.T::getShared(); | ||
| auto raw_ptr = data_ptr.get(); | ||
| /* | ||
| * Now, create a new shared pointer pointing to the same address as the | ||
| * actual pointer and replace the old internal shared pointer by the new | ||
| * one. | ||
| */ | ||
| self.setData(std::shared_ptr<typename T::Data_t>{ | ||
| raw_ptr, | ||
| /* | ||
| * Here comes the main trick. | ||
| * The new shared pointer stores (and thus keeps alive) two items | ||
| * via lambda capture in its destructor: | ||
| * 1. The old shared pointer. | ||
| * 2. The Series. | ||
| * It's important to notice that these two items are only stored | ||
| * within the newly created handle, and not internally within the | ||
| * actual openPMD object model. This means that no reference cycles | ||
| * can occur. | ||
| */ | ||
| [s_lambda = std::move(s), | ||
| data_ptr_lambda = std::move(data_ptr)](auto const *) { | ||
| /* no-op, the lambda captures simply go out of scope */ | ||
| }}); | ||
| return self; | ||
| } | ||
|
|
||
| template RecordComponent &makeOwning(RecordComponent &, Series); | ||
| template MeshRecordComponent &makeOwning(MeshRecordComponent &, Series); | ||
| template Mesh &makeOwning(Mesh &, Series); | ||
| template Record &makeOwning(Record &, Series); | ||
| template ParticleSpecies &makeOwning(ParticleSpecies &, Series); | ||
| template Iteration &makeOwning(Iteration &, Series); | ||
| } // namespace internal | ||
| } // namespace openPMD | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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