chariots.ops¶
operations are the atomic computation element of Chariots, you can use them to train models, preprocess your data, extract features and much more.
to create your own operations, you will need to subclass one of the base op classes:
create a minimalist operation by subclassing the BaseOp.
create an op that supports loading and saving by subclassing the LoadableOp class
create a machine learning operation by subclassing on of the machine learning ops (depending on your framework) like an sklearn op
-
class
chariots.pipelines.ops.
LoadableOp
(op_callbacks: Optional[List[chariots.pipelines.callbacks._op_callback.OpCallBack]] = None)[source]¶ Bases:
chariots.pipelines.ops._base_op.BaseOp
an operation that supports loading and saving. This means that when a pipeline tries to load a node using this kind of op, it will try to find the serialized bytes of the last saved version of this op and pass them to the load method of the op.
Similarly when the pipeline will try to save a node using this kind of operation, it will get the op’s serialized bytes by calling it’s serialize method (along with the op’s version)
to create your own loadable op, you will need to: - define the load and serialize method - define the execute method as for a normal op to define the behavior of your op
-
execute
(*args, **kwargs)[source]¶ main method to override. it defines the behavior of the op. In the pipeline the argument of the pipeline will be passed from the node with one argument per input (in the order of the input nodes)
-
-
class
chariots.pipelines.ops.
BaseOp
(op_callbacks: Optional[List[chariots.pipelines.callbacks._op_callback.OpCallBack]] = None)[source]¶ Bases:
object
The ops are the atomic computation units of the Chariots framework. Whereas a Node represents a slot in a pipeline and the interactions between that spot and the rest of the pipeline, the op will actually be doing the computation.
To subclass the BaseOp class and create a new Op, you need to override the execute method:
>>> class AddOp(BaseOp): ... number_to_add = 1 ... ... def execute(self, op_input): ... return op_input + self.number_to_add
and then you can execute the op alone:
>>> AddOp().execute(3) 4
or within a pipeline (that can be deployed)
>>> pipeline = Pipeline([Node(AddOp(), ["__pipeline_input__"], "__pipeline_output__")], "simple_pipeline") >>> runner.run(pipeline, 3) # of course you can use a `Chariots` server to serve our pipeline and op(s) 4
The BaseOp class is a versioned class (see the versioning module for more info).
so you can use VersionedField with it
>>> class AddOp(BaseOp): ... number_to_add = VersionedField(3, VersionType.MAJOR) ... ... def execute(self, op_input): ... return op_input + self.number_to_add >>> AddOp.__version__ <Version, major:36d3c, minor: 94e72, patch: 94e72> >>> AddOp.number_to_add 3
and changing the field will change the version:
>>> class AddOp(BaseOp): ... number_to_add = VersionedField(4, VersionType.MAJOR) ... ... def execute(self, op_input): ... return op_input + self.number_to_add >>> AddOp.__version__ <Version, major:8ad66, minor: 94e72, patch: 94e72>
- Parameters
op_callbacks – OpCallbacks objects to change the behavior of the op by executing some action before or after the op’execution
-
__init__
(op_callbacks: Optional[List[chariots.pipelines.callbacks._op_callback.OpCallBack]] = None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
after_execution
(args: List[Any], output: Any) → Any[source]¶ method used to create a one-off (compared to using a callback) custom behavior that gets executed after the the op itself
- Parameters
args – the arguments that were passed to the op
output – the output of the op
-
property
allow_version_change
¶ whether or not this op accepts to be loaded with the wrong version. this is usually False but is useful when loading an op for retraining
-
before_execution
(args: List[Any])[source]¶ method used to create a one-off (compared to using a callback) custom behavior that gets executed before the the op itself
- Parameters
args – the arguments that are going to be passed to the operation
-
execute
(*args, **kwargs)[source]¶ main method to override. it defines the behavior of the op. In the pipeline the argument of the pipeline will be passed from the node with one argument per input (in the order of the input nodes)
-
execute_with_all_callbacks
(args)[source]¶ executes the op itself alongside all it’s callbacks (op callbacks and before/after_execution methods)
- Parameters
args – the arguments to be passed to the execute method of the op
- Returns
the result of the op
-
property
name
¶ the name of the op. this is mainly use to find previous versions and saved ops of this op in the op_store_client
-
property
op_version
¶ the version the op uses to pass to the pipeline to identify itself. This differs from the __version__ method in that it can add some information besides the class Fields (for instance last training time for ML Ops)