- tpcp.make_action_safe(action_method: Callable[Concatenate[AlgorithmT, P], AlgorithmT]) Callable[Concatenate[AlgorithmT, P], AlgorithmT] [source]#
Mark a method as an “action” and apply a set of runtime checks to prevent implementation errors.
This decorator marks a method as action. Each algorithm is expected to have at least one action method. For pipelines this action method is called “run”. This means, when implementing a custom action or run method, it must always be wrapped in this decorator.
Besides registering the method, the following things are checked at runtime:
The action method must return
self(or at least an instance of the algorithm or pipeline)
The action method must set result attributes on the pipeline
All result attributes must have a trailing
_in their name
The action method must not modify the input parameters of the pipeline
In general, we recommend to just apply this decorator to all custom action methods. The runtime overhead is usually small enough to not make a difference.
>>> from tpcp import Algorithm, make_action_safe >>> class MyAlgorithm(Algorithm): ... ... @make_action_safe ... def detect(self, data, sampling_rate_hz): ... ... ... return self
Algorithms - A real world example: QRS-Detection
The final QRS detection algorithms