Skip to content

Commit 8cfe1bc

Browse files
committed
gp learner now supports raising GPLearnerAbortException
useful to immediately abort the full learning process for example from within a user_callback_per_generation
1 parent bdb01c0 commit 8cfe1bc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

gp_learner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@
8282
logger.info('init gp_learner')
8383

8484

85+
class GPLearnerException(Exception):
86+
pass
87+
88+
89+
class GPLearnerAbortException(GPLearnerException):
90+
"""Exception base class to be raised to abort whole GP Learner."""
91+
pass
92+
93+
94+
class GPLearnerTestPatternFoundException(GPLearnerAbortException):
95+
"""Exception to be thrown when a test pattern is found.
96+
97+
This exception is used in eval mode to enable early termination as soon as
98+
a test pattern (to be searched) ends up in the results of one generation.
99+
Early termination here allows not wasting additional time for the full
100+
run to complete. It skips out of the code immediately, re-raising the
101+
exception for external (eval) handling.
102+
"""
103+
pass
104+
105+
85106
def f_measure(precision, recall, beta=config.F_MEASURE_BETA):
86107
"""Calculates the f1-measure from precision and recall."""
87108
if precision + recall <= 0:
@@ -1178,6 +1199,11 @@ def find_graph_pattern_coverage(
11781199
)
11791200
break
11801201
run += 1
1202+
except GPLearnerAbortException as e:
1203+
# this exception is only raised to intentionally abort the whole
1204+
# learning process. Don't run auto-retry.
1205+
logger.info('gp learner was aborted intentionally: %r', e)
1206+
raise
11811207
except Exception as e:
11821208
error_count += 1
11831209
logger.error('uncaught exception in run %d' % run)

0 commit comments

Comments
 (0)