-
Notifications
You must be signed in to change notification settings - Fork 52
Python: fix load_chunk to temporary #913
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1706,9 +1706,22 @@ def writeFromTemporaryStore(self, E_x): | |
if found_numpy: | ||
E_x.store_chunk(np.array([[4, 5, 6]], dtype=np.dtype("int")), | ||
[1, 0]) | ||
|
||
data = np.array([[1, 2, 3]], dtype=np.dtype("int")) | ||
E_x.store_chunk(data) | ||
|
||
data2 = np.array([[7, 8, 9]], dtype=np.dtype("int")) | ||
E_x.store_chunk(np.repeat(data2, 198, axis=0), | ||
[2, 0]) | ||
|
||
def loadToTemporaryStore(self, r_E_x): | ||
# not catching the return value shall not result in a use-after-free: | ||
r_E_x.load_chunk() | ||
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. @franzpoeschel it looks like these tests does not trigger the issue we were concerned about. Maybe the GC zeroes out the data it frees or we are otherwise lucky... But then we should see this throw: https://github.com/openPMD/openPMD-api/blob/0.13.1/include/openPMD/RecordComponent.hpp#L334-L335 Do you have another Python snippet we could add in the test here that demonstrates the 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. I'd say this is likely a combination of (1) the rather small dataset that we test this on, (2) the fact that 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. https://github.com/franzpoeschel/openPMD-api/tree/topic-pyStoreChunkInMem-increaseBuffersize 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. Great hint, thank you - increasing the tested memory triggers the issue reliably :) |
||
# we keep a reference on the data until we are done flush()ing | ||
d = r_E_x[()] | ||
del d | ||
return | ||
ax3l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def writeFromTemporary(self, ext): | ||
name = "../samples/write_from_temporary_python." + ext | ||
write = io.Series( | ||
|
@@ -1718,7 +1731,7 @@ def writeFromTemporary(self, ext): | |
|
||
DS = io.Dataset | ||
E_x = write.iterations[0].meshes["E"]["x"] | ||
E_x.reset_dataset(DS(np.dtype("int"), [2, 3])) | ||
E_x.reset_dataset(DS(np.dtype("int"), [200, 3])) | ||
self.writeFromTemporaryStore(E_x) | ||
gc.collect() # trigger removal of temporary data to check its copied | ||
|
||
|
@@ -1731,16 +1744,20 @@ def writeFromTemporary(self, ext): | |
|
||
r_E_x = read.iterations[0].meshes["E"]["x"] | ||
if read.backend == 'ADIOS2': | ||
self.assertEqual(len(r_E_x.available_chunks()), 2) | ||
self.assertEqual(len(r_E_x.available_chunks()), 3) | ||
else: | ||
self.assertEqual(len(r_E_x.available_chunks()), 1) | ||
r_d = r_E_x[()] | ||
self.loadToTemporaryStore(r_E_x) | ||
gc.collect() # trigger removal of temporary data to check its copied | ||
|
||
read.flush() | ||
|
||
if found_numpy: | ||
np.testing.assert_allclose( | ||
r_d, | ||
np.array([[1, 2, 3], [4, 5, 6]], dtype=np.dtype("int")) | ||
r_d[:3, :], | ||
np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], | ||
dtype=np.dtype("int")) | ||
) | ||
|
||
def testWriteFromTemporary(self): | ||
|
Uh oh!
There was an error while loading. Please reload this page.