Skip to content

Commit d4d8b35

Browse files
authored
Find and use the active logger in the grandparent ensemble classs (#141)
1 parent 6c3d17f commit d4d8b35

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

ensemble/ensemble.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,23 @@ def __init__(self, keys_en: dict, sim, redund_sim=None):
8181
# Save name for (potential) pickle dump/load
8282
self.pickle_restart_file = 'emergency_dump'
8383

84-
# initiallize the restart. Standard is no restart
84+
# Initiallize the restart. Standard is no restart
8585
self.restart = False
8686

87+
# Get the active logger
88+
self.logger = logging.getLogger(__name__)
89+
8790
# If it is a restart run, we do not need to initialize anything, only load the self info. that exists in the
8891
# pickle save file. If it is not a restart run, we initialize everything below.
8992
if ('restart' in self.keys_en) and (self.keys_en['restart'] == 'yes'):
9093
# Initiate a restart run
91-
self.logger('\033[92m--- Restart run initiated! ---\033[92m')
94+
self.logger.info('\033[92m--- Restart run initiated! ---\033[92m')
9295
# Check if the pickle save file exists in folder
9396
try:
9497
assert (self.pickle_restart_file in [
9598
f for f in os.listdir('.') if os.path.isfile(f)])
9699
except AssertionError as err:
97-
self.logger('The restart file "{0}" does not exist in folder. Cannot restart!'.format(
100+
self.logger.info('The restart file "{0}" does not exist in folder. Cannot restart!'.format(
98101
self.pickle_restart_file))
99102
raise err
100103

@@ -312,7 +315,7 @@ def calc_prediction(self, enX=None, save_prediction=None):
312315
if len(list_crash) > 1:
313316
print(
314317
'\n\033[1;31mERROR: All started simulations has failed! We dump all information and exit!\033[1;m')
315-
self.logger(
318+
self.logger.info(
316319
'\n\033[1;31mERROR: All started simulations has failed! We dump all information and exit!\033[1;m')
317320
sys.exit(1)
318321
return success
@@ -333,7 +336,7 @@ def calc_prediction(self, enX=None, save_prediction=None):
333336
f"has been replaced by ensemble member {element}! ---\033[92m"
334337
)
335338
print(msg)
336-
self.logger(msg)
339+
self.logger.info(msg)
337340
if enX.shape[1] > 1:
338341
enX[:, list_crash[index]] = deepcopy(self.enX[:, element])
339342
en_pred[list_crash[index]] = deepcopy(en_pred[element])
@@ -365,7 +368,7 @@ def run_on_HPC(self, enX, batch_size=None, **kwargs):
365368

366369
# Split the ensemble into batches of 500
367370
if batch_size >= 1000:
368-
self.logger(f'Cannot run batch size of {batch_size}. Set to 1000')
371+
self.logger.info(f'Cannot run batch size of {batch_size}. Set to 1000')
369372
batch_size = 1000
370373
en_pred = []
371374
batch_en = [np.arange(start, start + batch_size) for start in
@@ -499,7 +502,7 @@ def calc_ml_prediction(self, enX=None):
499502
if len(list_crash) > 1:
500503
print(
501504
'\n\033[1;31mERROR: All started simulations has failed! We dump all information and exit!\033[1;m')
502-
self.logger(
505+
self.logger.info(
503506
'\n\033[1;31mERROR: All started simulations has failed! We dump all information and exit!\033[1;m')
504507
sys.exit(1)
505508
return success
@@ -522,7 +525,7 @@ def calc_ml_prediction(self, enX=None):
522525
f"has been replaced by ensemble member {element}! ---\033[92m"
523526
)
524527
print(msg)
525-
self.logger(msg)
528+
self.logger.info(msg)
526529
if enX[level].shape[1] > 1:
527530
enX[level][:, list_crash[index]] = deepcopy(enX[level][:, element])
528531

0 commit comments

Comments
 (0)