Skip to content

Commit

Permalink
Import suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenzorrilla committed Jul 11, 2023
1 parent f61a82e commit dd213d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions kratos/python_scripts/orchestrators/orchestrator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
import sys
import typing
import importlib
from typing import Dict, Optional

import KratosMultiphysics
from KratosMultiphysics.project import Project
Expand Down Expand Up @@ -119,7 +119,7 @@ def CreateStage(self, stage_name : str) -> AnalysisStage:

return stage_instance

def RunCurrentStagePreprocess(self, stage_name: str, data: typing.Optional[typing.Dict] = None):
def RunCurrentStagePreprocess(self, stage_name: str, data: Optional[Dict] = None):
"""This function executes the preprocess of current stage.
Note that the stage preprocess involves the execution of modelers and operations.
Expand All @@ -145,7 +145,7 @@ def RunCurrentStagePreprocess(self, stage_name: str, data: typing.Optional[typin
operation.Execute()
del operations_list

def RunCurrentStagePostprocess(self, stage_name: str, data: typing.Optional[typing.Dict] = None):
def RunCurrentStagePostprocess(self, stage_name: str, data: Optional[Dict] = None):
"""This function executes the postprocessing of current stage.
Note that the stage postprocess deliberately involves operations only.
Expand Down
19 changes: 9 additions & 10 deletions kratos/python_scripts/project.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import typing
import pickle
import pathlib
import importlib
from typing import Optional

import KratosMultiphysics
from KratosMultiphysics.analysis_stage import AnalysisStage
Expand All @@ -12,7 +12,7 @@ class Project:
This class has two main purposes. First one is to hold the multistage components (output data, active stages and model)
Second one is to perform the checkpoint save and load operations.
Member variables:
__settings -- Kratos parameters object with the multistage simulation settings
__output_data -- Dictionary containing the stages data retrieved from GetFinalData
Expand All @@ -37,22 +37,22 @@ def GetModel(self) -> KratosMultiphysics.Model:
'''Returns the current multistage simulation model.'''

return self.__model

def GetSettings(self) -> KratosMultiphysics.Parameters:
'''Returns the current multistage simulation settings.'''

return self.__settings

def GetOutputData(self) -> dict:
'''Returns the current multistage simulation output data container.'''

return self.__output_data

def GetActiveStages(self) -> dict:
'''Returns the current multistage simulation active stages dictionary.'''

return self.__active_stages

def AddActiveStage(self, stage_name: str, stage_instance: AnalysisStage) -> None:
'''Adds the provided stage instance to the active stages dictionary.'''

Expand All @@ -66,7 +66,7 @@ def RemoveActiveStage(self, stage_name : str) -> None:

del self.__active_stages[stage_name]

def Save(self, save_folder_path: pathlib.Path, checkpoint_file_path: pathlib.Path, output_settings_file_path: typing.Optional[pathlib.Path] = None) -> None:
def Save(self, save_folder_path: pathlib.Path, checkpoint_file_path: pathlib.Path, output_settings_file_path: Optional[pathlib.Path] = None) -> None:
'''Saves the Project current status.'''

# Set the list of modules (Kratos and non-Kratos) that have been added up to current save
Expand All @@ -86,7 +86,7 @@ def Save(self, save_folder_path: pathlib.Path, checkpoint_file_path: pathlib.Pat
stage_instance.Save(serializer) # Make stage instance pickable by serializing and deleting all Kratos objects
stage_names_list.append(stage_name) # Append current stage name
stage_instances_list.append(stage_instance) # Append current stage pickable instance

pickle.dump({
"serializer" : serializer,
"output_data" : self.__output_data,
Expand All @@ -100,7 +100,7 @@ def Save(self, save_folder_path: pathlib.Path, checkpoint_file_path: pathlib.Pat
if output_settings_file_path:
with open(save_folder_path / output_settings_file_path, 'w') as parameter_output_file:
parameter_output_file.write(self.__settings.PrettyPrintJsonString())

def Load(self, loading_path: pathlib.Path) -> None:
'''Loads a saved Project status into current one.'''

Expand All @@ -123,4 +123,3 @@ def Load(self, loading_path: pathlib.Path) -> None:

# Load output data dictionary
self.__output_data = loaded_data["output_data"]

0 comments on commit dd213d7

Please sign in to comment.