Skip to content

Commit

Permalink
Merge pull request #11705 from KratosMultiphysics/core/project-serial…
Browse files Browse the repository at this point in the history
…ization-flags-fix

[Hotfix][Core] Project serialization fix
  • Loading branch information
rubenzorrilla authored Oct 23, 2023
2 parents cea1d71 + aa3e288 commit 5bf5e40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions kratos/python/add_serializer_to_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ void AddSerializerToPython(pybind11::module& m)
.def("LoadFromBeginning",SerializerLoadFromBeginning<Model>)
.def("Save",SerializerSave<Model>)

.def("Load",SerializerLoad<Flags>)
.def("LoadFromBeginning",SerializerLoadFromBeginning<Flags>)
.def("Save",SerializerSave<Flags>)

.def("Set", &Serializer::Set)
.def("Print", SerializerPrint)
;
Expand Down
17 changes: 13 additions & 4 deletions kratos/python_scripts/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def Save(self, save_folder_path: pathlib.Path, checkpoint_file_path: pathlib.Pat
with open(save_folder_path / checkpoint_file_path, 'wb+') as checkpoint_file:
# Serialize current model and stages
serializer = KratosMultiphysics.StreamSerializer()
serializer.Set(KratosMultiphysics.Serializer.SHALLOW_GLOBAL_POINTERS_SERIALIZATION)

serializer_flags = KratosMultiphysics.Serializer.SHALLOW_GLOBAL_POINTERS_SERIALIZATION
serializer.Set(serializer_flags)

serializer.Save("SerializerFlags", serializer_flags) # Save the serializer flags (will be required for the loading)
serializer.Save("Model", self.__model)
stage_names_list = []
stage_instances_list = []
Expand Down Expand Up @@ -115,12 +117,19 @@ def Load(self, loading_path: pathlib.Path) -> None:
for module_name in loaded_data["required_modules"]:
importlib.import_module(module_name)

# Load and prepare serializer
# This means to set the serializer flags before using it
serializer = loaded_data["serializer"]
serializer_flags = KratosMultiphysics.Flags()
serializer.Load("SerializerFlags", serializer_flags)
serializer.Set(serializer_flags)

# Load model
loaded_data["serializer"].Load("Model", self.__model)
serializer.Load("Model", self.__model)

# Load stages
for stage_name, stage_instance in zip(loaded_data["stage_names"], loaded_data["stage_instances"]):
stage_instance.Load(loaded_data["serializer"]) # Take stage instance and restore it to its status before serialization
stage_instance.Load(serializer) # Take stage instance and restore it to its status before serialization
self.__active_stages[stage_name] = stage_instance # Append current stage instance to the active stages list

# Load output data dictionary
Expand Down

0 comments on commit 5bf5e40

Please sign in to comment.