Skip to content

Commit 80bb295

Browse files
committed
Reduced storage of stats during runs
1 parent 31a65ac commit 80bb295

File tree

6 files changed

+58
-16
lines changed

6 files changed

+58
-16
lines changed

pySDC/core/convergence_controller.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@ def post_step_processing(self, controller, S, **kwargs):
292292
"""
293293
pass
294294

295+
def post_run_processing(self, controller, S, **kwargs):
296+
"""
297+
Do whatever you want to after the run here.
298+
299+
Args:
300+
controller (pySDC.Controller): The controller
301+
S (pySDC.Step): The current step
302+
303+
Returns:
304+
None
305+
"""
306+
pass
307+
295308
def prepare_next_block(self, controller, S, size, time, Tend, **kwargs):
296309
"""
297310
Prepare stuff like spreading step sizes or whatever.

pySDC/implementations/controller_classes/controller_MPI.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def run(self, u0, t0, Tend):
160160
for hook in self.hooks:
161161
hook.post_run(step=self.S, level_number=0)
162162

163+
for C in [self.convergence_controllers[i] for i in self.convergence_controller_order]:
164+
C.post_run_processing(self, self.S, comm=self.comm)
165+
163166
comm_active.Free()
164167

165168
return uend, self.return_stats()

pySDC/implementations/controller_classes/controller_nonMPI.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def run(self, u0, t0, Tend):
171171
for hook in self.hooks:
172172
hook.post_run(step=S, level_number=0)
173173

174+
for S in self.MS:
175+
for C in [self.convergence_controllers[i] for i in self.convergence_controller_order]:
176+
C.post_run_processing(self, S, MS=MS_active)
177+
174178
return uend, self.return_stats()
175179

176180
def restart_block(self, active_slots, time, u0):

pySDC/projects/GPU/configs/base_config.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,33 @@ def get_initial_condition(self, P, *args, restart_idx=0, **kwargs):
145145
else:
146146
return P.u_exact(t=0), 0
147147

148-
def get_previous_stats(self, P, restart_idx):
149-
if restart_idx == 0:
150-
return {}
151-
else:
152-
hook = self.get_LogToFile()
153-
path = LogStats.get_stats_path(hook, counter_offset=0)
154-
with open(path, 'rb') as file:
155-
return pickle.load(file)
156-
157148
def get_LogToFile(self):
158149
return None
159150

160151

161152
class LogStats(ConvergenceController):
162153

163154
@staticmethod
164-
def get_stats_path(hook, counter_offset=-1):
165-
return f'{hook.path}/{hook.file_name}_{hook.format_index(hook.counter+counter_offset)}-stats.pickle'
155+
def get_stats_path(hook, counter_offset=-1, index=None):
156+
index = hook.counter + counter_offset if index is None else index
157+
return f'{hook.path}/{hook.file_name}_{hook.format_index(index)}-stats.pickle'
158+
159+
def merge_all_stats(self, controller):
160+
hook = self.params.hook
161+
162+
stats = {}
163+
for i in range(hook.counter):
164+
with open(self.get_stats_path(hook, index=i), 'rb') as file:
165+
_stats = pickle.load(file)
166+
stats = {**stats, **_stats}
167+
168+
stats = {**stats, **controller.return_stats()}
169+
return stats
170+
171+
def reset_stats(self, controller):
172+
for hook in controller.hooks:
173+
hook.reset_stats()
174+
self.logger.debug('Reset stats')
166175

167176
def setup(self, controller, params, *args, **kwargs):
168177
params['control_order'] = 999
@@ -188,4 +197,13 @@ def post_step_processing(self, controller, S, **kwargs):
188197
with open(path, 'wb') as file:
189198
pickle.dump(stats, file)
190199
self.log(f'Stored stats in {path!r}', S)
200+
self.reset_stats(controller)
191201
self.counter = hook.counter
202+
203+
def post_run_processing(self, controller, *args, **kwargs):
204+
stats = self.merge_all_stats(controller)
205+
206+
def return_stats():
207+
return stats
208+
209+
controller.return_stats = return_stats

pySDC/projects/GPU/run_experiment.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@ def run_experiment(args, config, **kwargs):
4646

4747
u0, t0 = config.get_initial_condition(prob, restart_idx=args['restart_idx'])
4848

49-
previous_stats = config.get_previous_stats(prob, restart_idx=args['restart_idx'])
50-
5149
uend, stats = controller.run(u0=u0, t0=t0, Tend=config.Tend)
5250

53-
combined_stats = {**previous_stats, **stats}
54-
combined_stats = filter_stats(combined_stats, comm=config.comm_world)
51+
combined_stats = filter_stats(stats, comm=config.comm_world)
5552

5653
if config.comm_world.rank == config.comm_world.size - 1:
5754
path = f'data/{config.get_path()}-stats-whole-run.pickle'

pySDC/projects/GPU/tests/test_configs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ def logging_condition(L):
8383
LogToFile.logging_condition = logging_condition
8484
return LogToFile
8585

86-
args = {'procs': [1, 1, 1], 'useGPU': False, 'res': -1, 'logger_level': 15, 'restart_idx': restart_idx}
86+
args = {
87+
'procs': [1, 1, 1],
88+
'useGPU': False,
89+
'res': -1,
90+
'logger_level': 15,
91+
'restart_idx': restart_idx,
92+
'mode': 'run',
93+
}
8794
config = VdPConfig(args)
8895
run_experiment(args, config)
8996

0 commit comments

Comments
 (0)