Skip to content

Record_Component.make_empty()#538

Merged
ax3l merged 2 commits intoopenPMD:devfrom
franzpoeschel:topic-makeEmpty-python
Oct 28, 2020
Merged

Record_Component.make_empty()#538
ax3l merged 2 commits intoopenPMD:devfrom
franzpoeschel:topic-makeEmpty-python

Conversation

@franzpoeschel
Copy link
Contributor

See this PR, this adds bindings for Python accordingly.

@ax3l ax3l self-requested a review July 25, 2019 16:15
@ax3l
Copy link
Member

ax3l commented Jul 25, 2019

Please also add tests :)

@ax3l ax3l changed the title Add Python bindings for RecordComponent::makeEmpty() Record_Component::make_empty() Jul 25, 2019
@ax3l ax3l changed the title Record_Component::make_empty() Record_Component.make_empty() Jul 25, 2019
@ax3l ax3l self-assigned this Jul 25, 2019
@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch 4 times, most recently from cc4495b to b59f84f Compare July 30, 2019 15:34
@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch 3 times, most recently from 37157c4 to 6cf9888 Compare July 30, 2019 20:28
@franzpoeschel franzpoeschel changed the title Record_Component.make_empty() [WIP] Record_Component.make_empty() Jul 30, 2019
@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch 2 times, most recently from c117b6c to 7c84fa6 Compare July 31, 2019 10:24
@franzpoeschel
Copy link
Contributor Author

The datatype tests apparently fail for the HDF5 backend. I don't think this is a bug with the current PR.

@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch 2 times, most recently from 4b6ff6e to 67df907 Compare July 31, 2019 12:11
@ax3l
Copy link
Member

ax3l commented Aug 2, 2019

CMake backport issue in Spack is going to be fixed in spack/spack#12241
Just push again after the merge.

Maybe check already to Windows builds, they seem actually broken.

@ax3l
Copy link
Member

ax3l commented Aug 6, 2019

@franzpoeschel ping: please rebase

@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch from 67df907 to 5e84e9d Compare August 7, 2019 10:34
@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch 2 times, most recently from 68444d1 to ed938a0 Compare August 19, 2019 14:48
@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch 3 times, most recently from b43a6fb to 0a6377f Compare August 27, 2019 15:30
@franzpoeschel
Copy link
Contributor Author

franzpoeschel commented Aug 27, 2019

It seems there is an issue in the ADIOS1 backend, the recent commit has made the checks pass. Leaving this line inside

ms["double"][SCALAR].make_empty(np.dtype("double"), 21)

will create datasets that cannot even be processed by bpls (in either version of ADIOS).

EDIT: It seems that the reason for this behavior is the fact that ADIOS is apparently case insensitive, choosing another name for the field will apparently work. I will push a commit in a minute.

@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch 2 times, most recently from 6d75f3e to 9ae2120 Compare August 27, 2019 16:47
@ax3l
Copy link
Member

ax3l commented Aug 27, 2019

Huh, I wasn't aware of that :-o

* @param dimensions
* @return RecordComponent&
*/
RecordComponent& makeEmpty( Datatype, uint8_t dimensions );
Copy link
Member

Choose a reason for hiding this comment

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

Just an ascetic question: would it be better to have the Datatype last?
Also: doxygen does not describe both parameters (second name is missing, dt?)

Copy link
Contributor Author

@franzpoeschel franzpoeschel Apr 2, 2020

Choose a reason for hiding this comment

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

I am used to putting that parameter first since that's how switchType does it, so I did that without a lot of thinking. You mean because it would align better with the templated makeEmpty? I actually like the order that it has now, since you first specify the datatype (as template or as normal parameter), thus also specifying whether you use the templated makeEmpty or the non-template, and next you specify the dimensions.

rc.makeEmpty< float >( 3u );
rc.makeEmpty( Datatype::FLOAT, 3u);

Think that's pretty straightforward this way around?

I've completed the doxygen description.

Copy link
Member

@ax3l ax3l Apr 2, 2020

Choose a reason for hiding this comment

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

Okay, that looks legit as well.

@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch from 9ae2120 to 31ea01e Compare August 28, 2019 09:08
@ax3l
Copy link
Member

ax3l commented Aug 28, 2019

@franzpoeschel I fixed the one test that ran into timeouts with #558.
Please rebase this PR against the latest dev and and remove the [WIP] in the title when it's ready for review (looks like it).

@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch from 31ea01e to b516c9d Compare August 30, 2019 09:18
@ax3l
Copy link
Member

ax3l commented Nov 5, 2019

@franzpoeschel pls rebase me one more time :)

@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch from b516c9d to 81916d8 Compare November 7, 2019 07:25
@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch 5 times, most recently from d090e50 to 9403705 Compare April 2, 2020 14:51
*
* @param dt The datatype of which to create an empty dataset.
* @param dimensions The dimensionality of the dataset.
* @return RecordComponent&
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return RecordComponent&
* @return A reference to this RecordComponent.

Copy link
Member

Choose a reason for hiding this comment

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

Orthogonal question for a follow-up PR about the return type:
with handles implemented, could we make the code usage safer by returning in all those places just a RecordComponent instead of a RecordComponent&? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intent of returning this at all is chaining methods, right? So, things such as recordComponent.makeEmpty(3).setUnitSI(3.0).
By forcing a copy there, we would also needlessly force copying the contained shared_ptrs, which we already do somewhat excessively at times, so I'm not really convinced.

I'm in general not a huge fan of how C++ does references and the problems in returning references is one of the major reasons (especially implicit copying upon auto x = <reference>), but do you see a safety issue in our case?

Copy link
Member

@ax3l ax3l Apr 8, 2020

Choose a reason for hiding this comment

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

Yes, the idea is to chain methods.

I think copying a shared_ptr is okay if it prevents that a user can create a dangling reference (to RecordComponent). It makes the API safer and keeps the syntactic sugar of chaining.

@ax3l ax3l changed the title [WIP] Record_Component.make_empty() Record_Component.make_empty() Apr 2, 2020
@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch from 9403705 to 26a0255 Compare April 7, 2020 13:28
See also openPMD#529

Add a non-template overload to RecordComponent::makeEmpty

Add tests for previous commit

Refactor python binding to use non-template version of makeEmpty

Add python tests for make_empty

Add an overload to RecordComponent.make_empty for numpy datatypes

Add tests for numpy datatypes

Fix datatype tests

Only test fixed-sized types
@franzpoeschel franzpoeschel force-pushed the topic-makeEmpty-python branch from 26a0255 to 51d7e57 Compare October 19, 2020 12:19
@franzpoeschel
Copy link
Contributor Author

I think this one is finished @ax3l ;)

Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

Thank you, this looks great! 🚀 ✨

@ax3l ax3l added the api: new additions to the API label Oct 28, 2020
@ax3l ax3l merged commit 1318fae into openPMD:dev Oct 28, 2020
@franzpoeschel franzpoeschel deleted the topic-makeEmpty-python branch January 28, 2021 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: new additions to the API frontend: Python3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants