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 tests for frontendbugs – Making copies of the Series object will result in strange behavior #804

Closed

Conversation

franzpoeschel
Copy link
Contributor

This adds tests (currently failing) for the issues discussed in #534.

@franzpoeschel franzpoeschel changed the title Add tests for frontend maladies Add tests for frontendbugs – Making copies of the Series object will result in strange behavior Oct 23, 2020
{
openPMD::Series series(
"sample%T.json", openPMD::AccessType::CREATE );
series_ptr = std::unique_ptr< openPMD::Series >(
Copy link
Member

Choose a reason for hiding this comment

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

just for modern C++, new-free style:

Suggested change
series_ptr = std::unique_ptr< openPMD::Series >(
series_ptr = std::make_unique< openPMD::Series >( series );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oo, I keep forgetting we're allowed to use C++14 now :)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, we did not officially switch yet - dang I always forget this is missing in C++11.
Soon - how far is PIConGPU in dev?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right, I confused both of them. PIConGPU is now running on C++14. So I'm keeping the raw constructors for now?

Copy link
Member

Choose a reason for hiding this comment

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

Problem solved - you can now use C++14 #825 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, updated

test/SerialIOTest.cpp Outdated Show resolved Hide resolved
* series goes out of scope before series_ptr
* destructor should only do a flush after both of them go out of
* scope, but it will currently run directly after this comment
* since no iteration has been written yet, an error will be thrown
Copy link
Member

@ax3l ax3l Oct 23, 2020

Choose a reason for hiding this comment

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

perfect description, thank you! ✨
looks like we should add reference counting or forbid the Series copy constructor...

Not sure how useful an alias for a Series in form of a handle object truly is. I would rather expect that if I copy a series that I can do things like bp to h5 conversion or so. We could implement such things via a .copy("new_name.ending") method later on that then returns a truly new Series object.

What do you think?

Copy link
Contributor Author

@franzpoeschel franzpoeschel Oct 23, 2020

Choose a reason for hiding this comment

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

I'm still liking the idea of having a clear separation of:

  1. Non-copyable shared internal resources
  2. Copyable handles that are exposed to user code and that have shared pointers to the internal resources.

This way, we could put the flushing destructor on the internal Series and things would be fine.

Currently, all of our objects just hide any member variable that need to be shared between instances behind shared pointers, which results in bugs like this.
Also, having actual internal classes for non-copyable resources would allow us to have proper upwards pointers through the openPMD hierarchies. Because, currently Writable::parent just goes to a copyable handle, and that concerns not only Series but all of our objects inheriting from Attributable. The issue is fortunately hard enough to trigger, but I should maybe try to find a way to make it fail for classes other than Series too...

Not sure how useful an alias for a Series in form of a handle object

All other classes that represent entities in the openPMD hierarchies are designed as handles, too, (sharing similar issues as argued above), so it's a question of consistency imo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or forbid the Series copy constructor...

Until we get to it, this would likely be a sane thing to do. (This is what I temporarily did when writing the openPMD plugin for PIConGPU in order to avoid this problem). Breaking change tho

Copy link
Member

@ax3l ax3l Nov 3, 2020

Choose a reason for hiding this comment

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

I agree with your rationale above.

Yes, deleting the copy constructor would just be a quick-fix, because it is in fact broken and will likely catch bugs if someone used this on two alive instances of the same Series. For deleting this, we also need to define a Move constructor in Series and Attributable #790

@ax3l ax3l mentioned this pull request Nov 3, 2020
3 tasks
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this pull request Feb 18, 2021
This is stolen from PR openPMD#804.
This PR fixes the issues from that one, so those tests are passing now.
@franzpoeschel
Copy link
Contributor Author

I've cherry-picked this test into #886 now. The tests are passing there.

franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this pull request Feb 19, 2021
This is stolen from PR openPMD#804.
This PR fixes the issues from that one, so those tests are passing now.
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this pull request Feb 19, 2021
This is stolen from PR openPMD#804.
This PR fixes the issues from that one, so those tests are passing now.
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this pull request Feb 19, 2021
This is stolen from PR openPMD#804.
This PR fixes the issues from that one, so those tests are passing now.
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this pull request Feb 24, 2021
This is stolen from PR openPMD#804.
This PR fixes the issues from that one, so those tests are passing now.
ax3l pushed a commit that referenced this pull request Feb 25, 2021
* Remove shortcuts from Attributable into Writable members

Fix invasive tests

* Split Attributable into internal and external class

Make AttributableImpl destructor virtual

Rename Attributable -> LegacyAttributable

Use Attributable::retrieveSeries for Writable::flushSeries

* Split Series into internal and external class

Make BASEPATH a member of SeriesImpl

Documentation for Series

* Use an owning copy of Series in ReadIterations

* Add tests for frontend maladies

This is stolen from PR #804.
This PR fixes the issues from that one, so those tests are passing now.

* Alias AttributableImpl to Attributable

* Make constructors of *Impl classes protected

* Add documentation for the PIMPL pattern
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.

None yet

2 participants