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.
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
[Core] Project-based multistage #11355
[Core] Project-based multistage #11355
Changes from 23 commits
bad13d2
b32fc3b
f7f3577
43e2b55
a234fcd
f8a818d
2c21077
9cc4215
aaa5072
9eabcab
8414844
ac27c3a
5975031
e1a4106
ca8d87a
886748f
48ac60b
8914914
275821b
3477001
af21953
2ef69aa
c5adf05
e45fe13
8b5dcdd
38e04c0
04a5093
1f19695
0d4d8a1
b915e77
528d9ea
57c7813
64bac3f
59390eb
396509c
85915a0
52fd8cc
652e5aa
6734444
535577d
9c3c6b8
f3d34e1
495b8bd
4243919
62e3e69
abf6843
41165dd
743d714
057a2ab
d4c3e35
32ae92f
765d021
41405d4
49dabec
f61a82e
dd213d7
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Why destroy them?
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.
If you don't destroy (i.e. assigning them to
None
) the non pure Python object the class wouldn't be pickable.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.
I don't get the point. A typical use case would be save and continue. No?
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.
Yes. But we are using Python
pickle
for doing so. Pickle is only capable to save / load pure Python types. Hence, we need to convert all Kratos objects to a pure Python type (this is what we do with our stream serializer). Then you "destroy" these objects in order to make the class Pickable. Let me try to write an example.We have a
MyStage
analysis stage class with whatever Kratos object e.g. a Newton-Raphson instance. At this point, the class is not pickable asself.strategy
cannot be dump. In order to do so, we call the stream serializer within theSave
method ofMyClass
to create a string "representing" it. At this point, theMyStage
is still not pickable asself.strategy
is not a Python type but a Kratos one. Then, we need to doself.strategy = None
after the stream serialization. At this point the clas IS pickable. This is what I meant by destroy. In pseudocode will be something likeThere 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.
https://pybind11.readthedocs.io/en/latest/advanced/classes.html#pickling-support
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.
We could skip
Load
ing everything back in afterSave
if all members of the analysis stage werepickle
able to begin with (i.e. the bindings define__setstate__
and__getstate__
). That means adding these extra bindings for every C++ type that may end up as a member of anAnalysisStage
.Yes that's a lot of work. However, it's just mundane copy-pasta work. We already have this functionality implemented with serializers, so we could just reuse them for the bindings:
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.
Just to say that I added more details to the docstring.
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.
This is what I understood
This is exactly my question: Why we should do self.cpp_class_instance=None? Would you please point me to the documentation in this respect?
And this is my direct concern. In the case of this PR the stage is already deleted. But this limits the usage very much.
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.
I can't point you to the docs, because this is just one possible roundabout solution to a problem we created for ourselves, so I don't think the docs would mention anything like this. The followings are just as valid solutions:
self.cpp_class_instance = 0
self.cpp_class_instance = "whatever"
self.cpp_class_instance = 6.0 * 1e23
self.cpp_class_instance = anything_that_is_pickleable
del self.cpp_class_instance
The point is to remove any un
pickle
able member.The proper (albeit more laborious) solution is to make our C++ types
pickle
able.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.
the thing is more delicate than simple copy-pasting.
Imagine you want to store a Model and then some other python object.
one way of doing this could be to create a serializer object in the pickle pybind call, write it to a string and then write the resulting char array to pickle.
the problem of this approach is that if we now want to have a different save for the second object, we don't have access to the serializer used to save the first object. We could generate a second StreamSerializer insance, however this implies that common things (like the kernel) would be serialized twice (and differently) in the first object and in the second.
What i am trying to say is that we need to first serialize all of the cpp objects USING THE FIRST SERIALIZER, and then write the serialized object using pickle. That is exactly what we are doing.
no doubts we could have a global serializer used in python ... however this complicates things quite a lot.
having said this, this is an implementation detail. If you like, let's open a different thread to discuss about that
This file was deleted.