# AUTOGENERATED! DO NOT EDIT! File to edit: ../../src/pipeline/callbacks.ipynb.

# %% auto #0
__all__ = ['CancelFitException', 'CancelBatchException', 'CancelEpochException', 'Callback', 'run_cbs']

# %% ../../src/pipeline/callbacks.ipynb #06272f6f-b4e3-4504-a90a-feebbf6ad821
from ..imports import *
from operator import attrgetter, itemgetter

# %% ../../src/pipeline/callbacks.ipynb #3f9e18f9-4d9f-4165-baeb-982dc4d60af9
class CancelFitException(Exception): pass
class CancelBatchException(Exception): pass
class CancelEpochException(Exception): pass

# %% ../../src/pipeline/callbacks.ipynb #36032308-bd0e-4409-9db0-9d89fc258e5a
class Callback(): order=0

# %% ../../src/pipeline/callbacks.ipynb #5395ac61-82d2-4da8-a665-3c4ad3ae8df5
def run_cbs(cbs, method_nm, pipeline=None):
    if not exists(cbs): return
    for cb in sorted(cbs, key=attrgetter('order')):
        method = getattr(cb, method_nm, None)
        if method: method(pipeline)
