MCPcopy Create free account
hub / github.com/KratosMultiphysics/Kratos / Save

Method Save

kratos/python_scripts/project.py:69–106  ·  view source on GitHub ↗

Saves the Project current status.

(self, save_folder_path: pathlib.Path, checkpoint_file_path: pathlib.Path, output_settings_file_path: Optional[pathlib.Path] = None)

Source from the content-addressed store, hash-verified

67 del self.__active_stages[stage_name]
68
69 def Save(self, save_folder_path: pathlib.Path, checkpoint_file_path: pathlib.Path, output_settings_file_path: Optional[pathlib.Path] = None) -> None:
70 '''Saves the Project current status.'''
71
72 # Set the list of modules (Kratos and non-Kratos) that have been added up to current save
73 required_modules = list(sys.modules.keys())
74
75 # Create save folder
76 KratosMultiphysics.FilesystemExtensions.MPISafeCreateDirectories(save_folder_path)
77
78 # Save current status
79 with open(save_folder_path / checkpoint_file_path, 'wb+') as checkpoint_file:
80 # Serialize current model and stages
81 serializer = KratosMultiphysics.StreamSerializer()
82 serializer_flags = KratosMultiphysics.Serializer.SHALLOW_GLOBAL_POINTERS_SERIALIZATION
83 serializer.Set(serializer_flags)
84
85 serializer.Save("SerializerFlags", serializer_flags) # Save the serializer flags (will be required for the loading)
86 serializer.Save("Model", self.__model)
87 stage_names_list = []
88 stage_instances_list = []
89 for stage_name, stage_instance in self.__active_stages.items():
90 stage_instance.Save(serializer) # Make stage instance pickable by serializing and deleting all Kratos objects
91 stage_names_list.append(stage_name) # Append current stage name
92 stage_instances_list.append(stage_instance) # Append current stage pickable instance
93
94 pickle.dump({
95 "serializer" : serializer,
96 "output_data" : self.__output_data,
97 "stage_names" : stage_names_list,
98 "stage_instances" : stage_instances_list,
99 "required_modules" : required_modules
100 }, checkpoint_file, protocol=2)
101
102 # Output current settings
103 if KratosMultiphysics.ParallelEnvironment.GetDefaultDataCommunicator().Rank() == 0:
104 if output_settings_file_path:
105 with open(save_folder_path / output_settings_file_path, 'w') as parameter_output_file:
106 parameter_output_file.write(self.__settings.PrettyPrintJsonString())
107
108 def Load(self, loading_path: pathlib.Path) -> None:
109 '''Loads a saved Project status into current one.'''

Callers 2

SaveRestartMethod · 0.45
RunMethod · 0.45

Calls 12

keysMethod · 0.80
dumpMethod · 0.80
PrettyPrintJsonStringMethod · 0.80
listClass · 0.50
openFunction · 0.50
StreamSerializerMethod · 0.45
SetMethod · 0.45
itemsMethod · 0.45
appendMethod · 0.45
RankMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected