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

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

# %% ../../src/pipeline/callbacks.ipynb 2
from ..imports import *
from operator import attrgetter, itemgetter

# %% ../../src/pipeline/callbacks.ipynb 4
class CancelFitException(Exception): pass
class CancelBatchException(Exception): pass
class CancelEpochException(Exception): pass

# %% ../../src/pipeline/callbacks.ipynb 5
class Callback(): order=0

# %% ../../src/pipeline/callbacks.ipynb 6
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)
