Hooks
zenml.hooks
The hooks package exposes some standard hooks that can be used in ZenML.
Hooks are functions that run after a step has exited.
Attributes
__all__ = ['alerter_success_hook', 'alerter_failure_hook', 'resolve_and_validate_hook']
module-attribute
Functions
alerter_failure_hook(exception: BaseException) -> None
Standard failure hook that executes after step fails.
This hook uses any BaseAlerter
that is configured within the active stack to post a message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception
|
BaseException
|
Original exception that lead to step failing. |
required |
Source code in src/zenml/hooks/alerter_hooks.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
alerter_success_hook() -> None
Standard success hook that executes after step finishes successfully.
This hook uses any BaseAlerter
that is configured within the active stack to post a message.
Source code in src/zenml/hooks/alerter_hooks.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
resolve_and_validate_hook(hook: Union[HookSpecification, InitHookSpecification], hook_kwargs: Optional[Dict[str, Any]] = None, allow_exception_arg: bool = False) -> Tuple[Source, Optional[Dict[str, Any]]]
Resolves and validates a hook callback and its arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hook
|
Union[HookSpecification, InitHookSpecification]
|
Hook function or source. |
required |
hook_kwargs
|
Optional[Dict[str, Any]]
|
The arguments to pass to the hook. |
None
|
allow_exception_arg
|
bool
|
Whether to allow an implicit exception argument to be passed to the hook. |
False
|
Returns:
Type | Description |
---|---|
Source
|
Tuple of hook source and validated hook arguments converted to JSON-safe |
Optional[Dict[str, Any]]
|
values. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in src/zenml/hooks/hook_validators.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
Modules
alerter_hooks
Functionality for standard hooks.
Classes
Functions
alerter_failure_hook(exception: BaseException) -> None
Standard failure hook that executes after step fails.
This hook uses any BaseAlerter
that is configured within the active stack to post a message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception
|
BaseException
|
Original exception that lead to step failing. |
required |
Source code in src/zenml/hooks/alerter_hooks.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
alerter_success_hook() -> None
Standard success hook that executes after step finishes successfully.
This hook uses any BaseAlerter
that is configured within the active stack to post a message.
Source code in src/zenml/hooks/alerter_hooks.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
hook_validators
Validation functions for hooks.
Classes
Functions
load_and_run_hook(hook_source: Source, hook_parameters: Optional[Dict[str, Any]] = None, step_exception: Optional[BaseException] = None, raise_on_error: bool = False) -> Any
Loads hook source and runs the hook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hook_source
|
Source
|
The source of the hook function. |
required |
hook_parameters
|
Optional[Dict[str, Any]]
|
The parameters of the hook function. |
None
|
step_exception
|
Optional[BaseException]
|
The exception of the original step. |
None
|
raise_on_error
|
bool
|
Whether to raise an error if the hook fails. |
False
|
Returns:
Type | Description |
---|---|
Any
|
The return value of the hook function. |
Raises:
Type | Description |
---|---|
HookValidationException
|
If hook validation fails. |
RuntimeError
|
If the hook fails and raise_on_error is True. |
Source code in src/zenml/hooks/hook_validators.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
resolve_and_validate_hook(hook: Union[HookSpecification, InitHookSpecification], hook_kwargs: Optional[Dict[str, Any]] = None, allow_exception_arg: bool = False) -> Tuple[Source, Optional[Dict[str, Any]]]
Resolves and validates a hook callback and its arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hook
|
Union[HookSpecification, InitHookSpecification]
|
Hook function or source. |
required |
hook_kwargs
|
Optional[Dict[str, Any]]
|
The arguments to pass to the hook. |
None
|
allow_exception_arg
|
bool
|
Whether to allow an implicit exception argument to be passed to the hook. |
False
|
Returns:
Type | Description |
---|---|
Source
|
Tuple of hook source and validated hook arguments converted to JSON-safe |
Optional[Dict[str, Any]]
|
values. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in src/zenml/hooks/hook_validators.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|