Skip to content

Commit

Permalink
Merge pull request #363 from jinyan1214/recovery
Browse files Browse the repository at this point in the history
Recovery
  • Loading branch information
fmckenna authored Jan 21, 2025
2 parents 73fd035 + 7e78ae9 commit 61828c9
Show file tree
Hide file tree
Showing 32 changed files with 3,562 additions and 1,651,764 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,9 @@ fmkTest.sh
.vscode

.coverage
modules/performREC/pyrecodes/pyrecodes*
modules/performREC/pyrecodes/residual_demand_traffic_simulator/projects*


applications.*
modules/performREC/pyrecodes/pyrecodes/*
1 change: 1 addition & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ add_subdirectory(Workflow)
add_subdirectory(tools)
add_subdirectory(performanceAssessment)
add_subdirectory(systemPerformance)
add_subdirectory(performREC)
108 changes: 78 additions & 30 deletions modules/Workflow/WorkflowApplications.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"Name": "INP_FILE",
"ExecutablePath": "applications/createAIM/INP_FILE/INP_FILE.py",
"ApplicationSpecificInputs": [
{
{
"id": "assetSourceFile",
"type": "path",
"description": "path to asset database file"
Expand Down Expand Up @@ -1228,8 +1228,19 @@
"Applications": [
{
"Name": "REWETRecovery",
"ExecutablePath": "applications/systemPerformance/REWEt/REWET_Wrapper.py",
"ApplicationSpecificInputs": []
"ExecutablePath": "applications/systemPerformance/REWET/REWET_Wrapper.py",
"ApplicationSpecificInputs": [
{
"id": "assetSourceFile",
"type": "path",
"description": "path to asset database file"
},
{
"id": "inputDir",
"type": "path",
"description": "path to input directory"
}
]
},
{
"Name": "ResidualDemand",
Expand Down Expand Up @@ -1264,32 +1275,6 @@
}
]
},
"SystemPerformanceApplications":{
"API": {
"Inputs": [
],
"Outputs": [
]
},
"Applications": [
{
"Name": "REWETRecovery",
"ExecutablePath": "applications/systemPerformance/REWET/REWET_Wrapper.py",
"ApplicationSpecificInputs": [
{
"id": "assetSourceFile",
"type": "path",
"description": "path to asset database file"
},
{
"id": "inputDir",
"type": "path",
"description": "path to input directory"
}
]
}
]
},
"PerformanceApplications": {
"API": {
"Inputs": [],
Expand All @@ -1313,5 +1298,68 @@
]
}
]
},
"RecoveryApplications": {
"API": {
"Inputs": [],
"Outputs": []
},
"Applications": [
{
"Name": "Pyrecodes",
"ExecutablePath": "applications/performREC/pyrecodes/run_pyrecodes.py",
"ApplicationSpecificInputs": [
{
"id": "Realization",
"type": "string",
"description": "Realizations."
},
{
"id": "systemConfigFile",
"type": "path",
"description": "Path to pyrecodes system configuration file."
},
{
"id": "componentLibraryFile",
"type": "path",
"description": "Path to pyrecodes component library file."
},
{
"id": "localityGeojsonFile",
"type": "path",
"description": "Path to the geojson file that defines locality (Optional)."
},
{
"id": "INPFile",
"type": "path",
"description": "Path to INPfile."
},
{
"id": "r2dRunDir",
"type": "path",
"description": "R2D run directory containing the results.",
"default": "seqRUN"
},
{
"id": "parallelType",
"type": "string",
"description": "How parallel runs: options seqRUN, parSETUP, parRUN.",
"default": "mpiexec"
},
{
"id": "mpiexec",
"type": "string",
"description": "How mpi runs, e.g. ibrun, mpirun, mpiexec.",
"default": "mpiexec"
},
{
"id": "numP",
"type": "string",
"description": "If parallel, how many jobs to start with mpiexec option.",
"default": 8
}
]
}
]
}
}
}
3 changes: 1 addition & 2 deletions modules/Workflow/rWHALE.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ def main( # noqa: C901, D103
#
# add recovery
#

# WF.perform_recovery_simulation(asset_files.keys())
WF.perform_recovery_simulation()

WF.compile_r2d_results_geojson(asset_files)

Expand Down
89 changes: 85 additions & 4 deletions modules/Workflow/whale/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,13 +884,13 @@ def _register_app_type(self, app_type, app_dict, sub_app=''): # noqa: C901
# Check to ensure the applications key is provided in the input
if app_in == None: # noqa: E711
return
err = "Need to provide the 'Application' key in " + app_type
err = "Need to provide the 'Application' key in " + app_type #TODO ANYONE: DELETE THIS. USELESS! (ADDED BY SINA)
raise WorkFlowInputError(err)

# Check to see if the app type is in the application registry
app_type_obj = self.app_registry.get(app_type)

if app_in == None: # noqa: E711
if app_in == None: # noqa: E711 #TODO ANYONE: DELETE THIS. USELESS! (ADDED BY SINA)
return

if app_in == 'None':
Expand All @@ -907,7 +907,7 @@ def _register_app_type(self, app_type, app_dict, sub_app=''): # noqa: C901
+ app_in
)
print('Error', app_in) # noqa: T201
raise WorkFlowInputError(err)
raise WorkFlowInputError(err) #TODO ANYONE: DELETE THIS. USELESS!(ADDED BY SINA)

appData = app_dict['ApplicationData'] # noqa: N806
#
Expand Down Expand Up @@ -1639,6 +1639,87 @@ def perform_system_performance_assessment(self, asset_type):
log_div()
return True

def perform_recovery_simulation(self):
# Make sure that we are in the run directory before we run recovery
# Every other path will be relative to the Run Directory (result dir)
os.chdir(self.run_dir)
# Check if system performance is requested
if 'Recovery' in self.workflow_apps:
performance_app = self.workflow_apps['Recovery']
else:
log_msg(
'No Recovery application to run.',
prepend_timestamp=False,
)
log_div()
return False

if performance_app.rel_path is None:
log_msg(
'No Recovery application to run.',
prepend_timestamp=False,
)
log_div()
return False

log_msg(
'Performing Recovery Application',
prepend_timestamp=False,
)
log_div()

app_command_list = performance_app.get_command_list(
app_path=self.app_dir_local
)

if self.parType == 'parSETUP':
pass
# log_msg(
# '\nParallel settings for Recovery Simulation',
# prepend_timestamp=False,
# )
# app_command_list.append('--par')


app_command_list.append('--input')
app_command_list.append(self.input_file)

with open(self.input_file, "rt") as f:
input_file = json.load(f)

if "WaterDistributionNetwork" in input_file["Applications"]["Assets"]:
wdn_apps = input_file["Applications"]["Assets"]["WaterDistributionNetwork"]
if wdn_apps["Application"] == "INP_FILE":
inp_file_name = wdn_apps["ApplicationData"]["inpFile"]
inp_file_name = resolve_path(inp_file_name, self.reference_dir)

app_command_list.append('--INPFile')
app_command_list.append(inp_file_name)

command = create_command(app_command_list)

log_msg('Output: ', prepend_timestamp=False, prepend_blank_space=False)
log_msg(
f'\n{command}\n',
prepend_timestamp=False,
prepend_blank_space=False,
)

result, returncode = run_command(command)
log_msg(
f'\n{result}\n',
prepend_timestamp=False,
prepend_blank_space=False,
)

log_msg(
'Recover Simulation Application Completed',
prepend_timestamp=False,
)

log_div()
return True

def perform_regional_event(self):
"""Run an application to simulate a regional-scale hazard event.
Expand Down Expand Up @@ -2212,7 +2293,7 @@ def preprocess_inputs( # noqa: C901
try:
if command.startswith('python'):
if platform.system() == 'Windows':
driver_script += 'if %errorlevel% neq 0 exit /b -1 \n' # noqa: F821, F841
driver_script += 'if %errorlevel% neq 0 exit /b -1 \n' #TODO ANYONE: This variable is not defined. Check This please. (Added by Sina)
else:
pass

Expand Down
2 changes: 1 addition & 1 deletion modules/performREC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
simcenter_add_python_script(SCRIPT transportation.py)
add_subdirectory(pyrecodes)
add_subdirectory(pyrecodes)
8 changes: 8 additions & 0 deletions modules/performREC/pyrecodes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
simcenter_add_python_script(SCRIPT __init__.py)
simcenter_add_python_script(SCRIPT constants.py)
simcenter_add_python_script(SCRIPT main.py)
simcenter_add_python_script(SCRIPT run_pyrecodes.py)
simcenter_add_python_script(SCRIPT utilities.py)
add_subdirectory(rewet_API)
add_subdirectory(residual_demand_API)
# add_subdirectory(rewet_result)
Binary file removed modules/performREC/pyrecodes/None_0.bin
Binary file not shown.
Loading

0 comments on commit 61828c9

Please sign in to comment.