Skip to content

Commit 21cbc4d

Browse files
paulf81Copilot
andauthored
Feature/clean up logging (#177)
* remove time_log_interval * unite on progress_update_interval * minor update * Update hercules/hercules_model.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update hercules/hercules_model.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a9e9fef commit 21cbc4d

2 files changed

Lines changed: 6 additions & 16 deletions

File tree

docs/h_dict.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ The `h_dict` is a Python dictionary that contains all the configurations for eac
2424
| `name` | str | Simulation name | - |
2525
| `description` | str | Simulation description | - |
2626
| `output_file` | str | Output CSV file path | "outputs/hercules_output.csv" |
27-
| `time_log_interval` | int | Logging interval in steps | - |
28-
| `log_every_n` | int | Log every N simulation steps (default: 1) | 1 |
27+
| `log_every_n` | int | Log every N simulation steps to output log (default: 1) | 1 |
2928
| `external_data` | dict | External data configuration | - |
3029
| `external_data_file` | str | External data file path (deprecated, use `external_data` instead) | - |
3130
| `controller` | dict | Controller configuration | - |

hercules/hercules_model.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,11 @@ def __init__(self, input_file):
114114
self.step = 0
115115
self.n_steps = int(self.total_simulation_time / self.dt)
116116

117-
# How often to update the user on current simulation time
118-
# In simulated time
119-
if "time_log_interval" in self.h_dict:
120-
self.time_log_interval = self.h_dict["time_log_interval"]
121-
else:
122-
self.time_log_interval = 600 # seconds
123-
self.step_log_interval = self.time_log_interval / self.dt
124-
125-
# Round to step_log_interval to be an integer greater than 0
126-
self.step_log_interval = np.max([1, np.round(self.step_log_interval)])
117+
# Set progress_update_interval to log 10 times per simulation
118+
self.progress_update_interval = self.n_steps / 10
127119

128-
# Calculate progress bar update interval (independent of verbose logging)
129-
# Update every 1% of completion or every 100 steps, whichever is more frequent
130-
self.progress_update_interval = min(max(1, self.n_steps // 100), 100)
120+
# Round progress_update_interval to be an integer greater than 0
121+
self.progress_update_interval = np.max([1, np.round(self.progress_update_interval)])
131122

132123
# Save start time UTC (zero_time_utc is redundant since time=0 corresponds to starttime_utc)
133124
# starttime_utc is required and should already be set, but ensure it's still present
@@ -503,7 +494,7 @@ def run(self):
503494
for self.step in range(self.n_steps):
504495
# Log the current time
505496
if self.verbose:
506-
if (self.step % self.step_log_interval == 0) or first_iteration:
497+
if (self.step % self.progress_update_interval == 0) or first_iteration:
507498
self.logger.info(f"Simulation time: {self.time} (ending at {self.endtime})")
508499
self.logger.info(f"Step: {self.step} of {self.n_steps}")
509500
percent_complete = 100 * self.step / self.n_steps

0 commit comments

Comments
 (0)