Skip to content

Commit 975dd58

Browse files
committed
Add logging to operators that otherwise stay silent
1 parent cc36e41 commit 975dd58

File tree

6 files changed

+217
-67
lines changed

6 files changed

+217
-67
lines changed

sotodlib/toast/ops/bias_cut.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ def __init__(self, **kwargs):
9898
@function_timer
9999
def _exec(self, data, detectors=None, **kwargs):
100100
log = Logger.get()
101+
wcomm = data.comm.comm_world
102+
timer0 = Timer()
103+
timer0.start()
104+
105+
if detectors is None:
106+
log.info_rank(f"Applying {type(self).__name__}", comm=wcomm)
107+
else:
108+
log.debug_rank(f"Applied {type(self).__name__}", comm=wcomm)
101109

102110
bg_key = f"{self.detcal_prefix}bg"
103111
r_tes_key = f"{self.detcal_prefix}r_tes"
@@ -201,6 +209,11 @@ def _exec(self, data, detectors=None, **kwargs):
201209
continue
202210
ob.update_local_detector_flags(bias_flags)
203211

212+
if detectors is None:
213+
log.info_rank(f"Applied {type(self).__name__} in", comm=wcomm, timer=timer0)
214+
else:
215+
log.debug_rank(f"Applied {type(self).__name__} in", comm=wcomm, timer=timer0)
216+
204217
def _finalize(self, data, **kwargs):
205218
return
206219

sotodlib/toast/ops/dark_templates.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Copyright (c) 2025 by the parties listed in the AUTHORS file.
1+
# Copyright (c) 2025-2026 by the parties listed in the AUTHORS file.
22
# All rights reserved. Use of this source code is governed by
33
# a BSD-style license that can be found in the LICENSE file.
44

55
import os
66
import pickle
77
import re
88
import warnings
9-
from time import time
9+
from time import time, sleep
1010

1111
import h5py
1212
import numpy as np
@@ -16,7 +16,7 @@
1616
from toast import qarray as qa
1717
from toast.mpi import MPI, Comm, MPI_Comm
1818
from toast.observation import default_values as defaults
19-
from toast.timing import function_timer
19+
from toast.timing import function_timer, Timer
2020
from toast.traits import Int, Unicode, trait_docs
2121
from toast.utils import Environment, Logger
2222
from toast.ops import Operator
@@ -161,6 +161,13 @@ def _exec(self, data, detectors=None, **kwargs):
161161
log = Logger.get()
162162
wcomm = data.comm.comm_world
163163
gcomm = data.comm.comm_group
164+
timer0 = Timer()
165+
timer0.start()
166+
167+
if detectors is None:
168+
log.info_rank(f"Applying {type(self).__name__}", comm=wcomm)
169+
else:
170+
log.debug_rank(f"Applied {type(self).__name__}", comm=wcomm)
164171

165172
if (wcomm is None or wcomm.rank == 0) and self.cache_dir is not None:
166173
os.makedirs(self.cache_dir, exist_ok=True)
@@ -206,8 +213,27 @@ def _exec(self, data, detectors=None, **kwargs):
206213
f"{fname_cache}",
207214
comm=gcomm,
208215
)
209-
with open(fname_cache, "rb") as f:
210-
cached_dark_tod = pickle.load(f)
216+
# Loading the file will fail if another process is
217+
# writing it. We will try up to 6 times and wait
218+
# 10 seconds between each try
219+
n_try_max = 3
220+
for n_try in range(n_try_max):
221+
try:
222+
with open(fname_cache, "rb") as f:
223+
cached_dark_tod = pickle.load(f)
224+
except EOFError:
225+
if n_try == n_try_max - 1:
226+
log.warning(
227+
f"EOF at {fname_cache}, will overwrite"
228+
)
229+
break
230+
else:
231+
log.warning(
232+
f"EOF at {fname_cache}, waiting for 10 seconds"
233+
)
234+
sleep(10)
235+
continue
236+
break # success
211237
else:
212238
fname_cache = None
213239

@@ -338,6 +364,11 @@ def _exec(self, data, detectors=None, **kwargs):
338364
dark_templates["det_to_key"] = det_to_key
339365
ob[self.template_name] = dark_templates
340366

367+
if detectors is None:
368+
log.info_rank(f"Applied {type(self).__name__} in", comm=wcomm, timer=timer0)
369+
else:
370+
log.debug_rank(f"Applied {type(self).__name__} in", comm=wcomm, timer=timer0)
371+
341372
return
342373

343374
def _finalize(self, data, **kwargs):

sotodlib/toast/ops/housekeeping_templates.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Copyright (c) 2025 by the parties listed in the AUTHORS file.
1+
# Copyright (c) 2025-2026 by the parties listed in the AUTHORS file.
22
# All rights reserved. Use of this source code is governed by
33
# a BSD-style license that can be found in the LICENSE file.
44

55
import os
66
import pickle
77
import re
88
import warnings
9-
from time import time
9+
from time import time, sleep
1010

1111
import h5py
1212
import numpy as np
@@ -16,7 +16,7 @@
1616
from toast import qarray as qa
1717
from toast.mpi import MPI, Comm, MPI_Comm
1818
from toast.observation import default_values as defaults
19-
from toast.timing import function_timer
19+
from toast.timing import function_timer, Timer
2020
from toast.traits import Int, Unicode, trait_docs
2121
from toast.utils import Environment, Logger
2222
from toast.ops import Operator
@@ -162,6 +162,14 @@ def _exec(self, data, detectors=None, **kwargs):
162162
"""
163163
log = Logger.get()
164164
gcomm = data.comm.comm_group
165+
wcomm = data.comm.comm_world
166+
timer0 = Timer()
167+
timer0.start()
168+
169+
if detectors is None:
170+
log.info_rank(f"Applying {type(self).__name__}", comm=wcomm)
171+
else:
172+
log.debug_rank(f"Applied {type(self).__name__}", comm=wcomm)
165173

166174
if self.hkkey is None:
167175
msg = f"You must set the `hkkey` trait before applying "
@@ -194,8 +202,27 @@ def _exec(self, data, detectors=None, **kwargs):
194202
f"{fname_cache}",
195203
comm=gcomm,
196204
)
197-
with open(fname_cache, "rb") as f:
198-
hkfields = pickle.load(f)
205+
# Loading the file will fail if another process is
206+
# writing it. We will try up to 6 times and wait
207+
# 10 seconds between each try
208+
n_try_max = 6
209+
for n_try in range(n_try_max):
210+
try:
211+
with open(fname_cache, "rb") as f:
212+
hkfields = pickle.load(f)
213+
except EOFError:
214+
if n_try == n_try_max - 1:
215+
log.warning(
216+
f"EOF at {fname_cache}, will overwrite"
217+
)
218+
break
219+
else:
220+
log.warning(
221+
f"EOF at {fname_cache}, waiting for 10 seconds"
222+
)
223+
sleep(10)
224+
continue
225+
break # success
199226
else:
200227
fname_cache = None
201228

@@ -326,6 +353,11 @@ def _exec(self, data, detectors=None, **kwargs):
326353
hktemplates["det_to_key"] = det_to_key
327354
ob[self.template_name] = hktemplates
328355

356+
if detectors is None:
357+
log.info_rank(f"Applied {type(self).__name__} in", comm=wcomm, timer=timer0)
358+
else:
359+
log.debug_rank(f"Applied {type(self).__name__} in", comm=wcomm, timer=timer0)
360+
329361
return
330362

331363
def _finalize(self, data, **kwargs):

0 commit comments

Comments
 (0)