Skip to content

Commit

Permalink
restore test for multi-grid simulation to
Browse files Browse the repository at this point in the history
  • Loading branch information
sunt05 committed Jul 12, 2024
1 parent fab285b commit f642861
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/supy/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def run_save_supy(
df_forcing_tstep, df_state_init_m, ind, save_state, n_yr, path_dir_temp
):
# run supy in serial mode
df_output, df_state_final, res_debug = run_supy_ser(
df_output, df_state_final = run_supy_ser(
df_forcing_tstep, df_state_init_m, save_state, n_yr
)
# save to path_dir_temp
Expand Down
86 changes: 44 additions & 42 deletions test/test_supy.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,48 +100,50 @@ def test_is_supy_running_multi_step(self):
self.assertTrue((test_non_empty and not df_state.isnull().values.any()))

# test if multi-grid simulation can run in parallel
# def test_is_supy_sim_save_multi_grid_par(self):
# print("\n========================================")
# print("Testing if multi-grid simulation can run in parallel...")
# n_grid = 4
# df_state_init, df_forcing_tstep = sp.load_SampleData()
# df_state_init = pd.concat([df_state_init for x in range(n_grid)])
# df_state_init.index = pd.RangeIndex(n_grid, name="grid")
# df_forcing_part = df_forcing_tstep.iloc[: 288 * 60]
# df_output, df_state = sp.run_supy(df_forcing_part, df_state_init)

# test_success_sim = np.all(
# [
# not df_output.empty,
# not df_state.empty,
# ]
# )

# with tempfile.TemporaryDirectory() as dir_temp:
# list_outfile = sp.save_supy(
# df_output,
# df_state,
# path_dir_save=dir_temp,
# site="pytest",
# logging_level=10,
# )

# test_success_save = np.all([isinstance(fn, Path) for fn in list_outfile])
# self.assertTrue(test_success_sim and test_success_save)

# # only print to screen on macOS due incompatibility on Windows
# if platform.system() == "Darwin":
# # capturedOutput = io.StringIO() # Create StringIO object
# # sys.stdout = capturedOutput # and redirect stdout.
# # Call function.
# n_grid = df_state_init.index.size
# print(f"Running time: {t_end-t_start:.2f} s for {n_grid} grids")
# # sys.stdout = sys.__stdout__ # Reset redirect.
# # Now works as before.
# # print("Captured:\n", capturedOutput.getvalue())

# test_non_empty = np.all([not df_output.empty, not df_state.empty,])
# self.assertTrue(test_non_empty)
def test_is_supy_sim_save_multi_grid_par(self):
print("\n========================================")
print("Testing if multi-grid simulation can run in parallel...")
n_grid = 4
df_state_init, df_forcing_tstep = sp.load_SampleData()
df_state_init = pd.concat([df_state_init for x in range(n_grid)])
df_state_init.index = pd.RangeIndex(n_grid, name="grid")
df_forcing_part = df_forcing_tstep.iloc[: 288 * 60]
t_start = time()
df_output, df_state = sp.run_supy(df_forcing_part, df_state_init)
t_end = time()

test_success_sim = np.all(
[
not df_output.empty,
not df_state.empty,
]
)

with tempfile.TemporaryDirectory() as dir_temp:
list_outfile = sp.save_supy(
df_output,
df_state,
path_dir_save=dir_temp,
site="pytest",
logging_level=10,
)

test_success_save = np.all([isinstance(fn, Path) for fn in list_outfile])
self.assertTrue(test_success_sim and test_success_save)

# only print to screen on macOS due incompatibility on Windows
if platform.system() == "Darwin":
# capturedOutput = io.StringIO() # Create StringIO object
# sys.stdout = capturedOutput # and redirect stdout.
# Call function.
n_grid = df_state_init.index.size
print(f"Running time: {t_end-t_start:.2f} s for {n_grid} grids")
# sys.stdout = sys.__stdout__ # Reset redirect.
# Now works as before.
# print("Captured:\n", capturedOutput.getvalue())

test_non_empty = np.all([not df_output.empty, not df_state.empty,])
self.assertTrue(test_non_empty)

# # test if single-tstep and multi-tstep modes can produce the same SUEWS results
# @skipUnless(flag_full_test, "Full test is not required.")
Expand Down

0 comments on commit f642861

Please sign in to comment.