V1Operation

polyaxon.polyflow.operations.operation.V1Operation(version=None, kind=None, name=None, description=None, tags=None, presets=None, queue=None, cache=None, termination=None, plugins=None, schedule=None, events=None, hooks=None, dependencies=None, trigger=None, conditions=None, skip_on_upstream_skip=None, matrix=None, joins=None, params=None, run_patch=None, patch_strategy=None, is_preset=None, is_approved=None, template=None, build=None, cost=None, path_ref=None, hub_ref=None, dag_ref=None, url_ref=None, component=None)

An operation is how Polyaxon executes a component by passing parameters, connections, and a run environment.

With an operation users can:

  • Pass the parameters for required inputs or override the default values of optional inputs.
  • Patch the definition of the component to set environments, initializers, and resources.
  • Set termination logic and retries.
  • Set trigger logic to start a component in a pipeline context.
  • Parallelize or map the component over a matrix of parameters.
  • Put an operation on a schedule.
  • Subscribe a component to events to trigger executions automatically.

After resolution and compilation, Polyaxon will prepare an executable that will be scheduled on Kubernetes:

polyaxonfile operation

YAML usage

operation:
  version: 1.1
  kind: operation
  patchStrategy:
  isPreset:
  isApproved:
  name:
  description:
  tags:
  presets:
  queue:
  cache:
  termination:
  plugins:
  events:
  actions:
  hooks:
  params:
  build:
  runPatch:
  hubRef:
  dagRef:
  pathRef:
  component:
  template:

Python usage

from polyaxon.polyflow import (
    V1Build, V1Cache, V1Component, V1Hook, V1Param, V1Plugins, V1Operation, V1Termination
)
from polyaxon.schemas import V1PatchStrategy
operation = V1Operation(
    patch_strategy=V1PatchStrategy.REPLACE,
    name="test",
    description="test",
    tags=["test"],
    presets=["test"],
    queue="test",
    cache=V1Cache(...),
    termination=V1Termination(...),
    plugins=V1Plugins(...),
    events=["event-ref1", "event-ref2"],
    hooks=[V1Hook(...)],
    outputs={"param1": V1Param(...), ...},
    build=V1Build(...),
    component=V1Component(...),
)

Fields

version

The polyaxon specification version to use to validate the operation.

operation:
  version: 1.1

kind

The kind signals to the CLI, client, and other tools that this is an operation.

If you are using the python client to create an operation, this field is not required and is set by default.

operation:
  kind: component

patchStrategy

Defines how the compiler should handle keys that are defined on the component, or how to merge multiple presets when using the override behavior -f.

There are four strategies:

  • replace: replaces all keys with new values if provided.
  • isnull: only applies new values if the keys have empty/None values.
  • post_merge: applies deep merge where newer values are applied last.
  • pre_merge: applies deep merge where newer values are applied first.

isPreset

This is a flag to tell if this operation must be validated or is only a preset that will be used with the override behavior to inject extra information to the main operation specification.

For instance a user might want to define a scheduling behavior that applies to several operations. One way to do that is to set the environment section on every operation. But sometimes the same scheduling behavior makes sense for several operations and components. In that case, the user can define an operation preset to extract that logic:

isPreset: true
runPatch:
  environment:
    nodeSelector:
      node_label: node_value

and use the override behavior to inject that section dynamically:

polyaxon run -f component -f scheduling-preset.yaml

Note: Please check this in-depth section about presets.

name

The name to use for this operation run, if provided, it will override the component's name otherwise the name of the component will be used if it exists.

operation:
  name: test

description

The description to use for this operation run, if provided, it will override the component's description otherwise the description of the component will be used if it exists.

operation:
  description: test

tags

The tags to use for this operation run, if provided, it will override the component's tags otherwise the tags of the component will be used if it exists.

operation:
  tags: [test]

presets

The presets to use for this operation run, if provided, it will override the component's presets otherwise the presets of the component will be used if it exists.

operation:
  presets: [test]

queue

The queue to use for this operation run, if provided, it will override the component's queue otherwise the queue of the component will be used if it exists.

operation:
  queue: agent-name/queue-name

If the agent name is not specified, Polyaxon will resolve the name of the queue based on the default agent.

operation:
  queue: queue-name

cache

The cache to use for this operation run, if provided, it will override the component's cache otherwise the cache of the component will be used if it exists.

operation:
  cache:
    disable: false
    ttl: 100

termination

The termination to use for this operation run, if provided, it will override the component's termination otherwise the termination of the component will be used if it exists.

operation:
  termination:
    maxRetries: 2

plugins

The plugins to use for this operation run, if provided, it will override the component's plugins otherwise the plugins of the component will be used if it exists.

operation:
  name: debug
  ...
  plugins:
    auth: false
    collectLogs: false
  ...

params

The params to pass to the component, they will be validated against the inputs/outputs. If a parameter is passed and the component does not define a corresponding inputs/outputs, a validation error will be raised unless the param has the contextOnly flag enabled.

operation:
  params:
    param1: {value: 1.1}
    param2: {value: test}
    param3: {ref: ops.upstream-operation, value: outputs.metric}
  ...

build

Note: Please check V1Build for more details.

This section defines if this operation should build a container before starting the main logic. If the build section is provided, Polyaxon will set the main operation to a pending state until the build is done and then it will use the resulting docker image for starting the main container.

operation:
  ...
  build:
    hubRef: kaniko
  ...

### runPatch

The run patch provides a way to override information about the component's run section,
for example the container's resources or the environment section.

The run patch is a dictionary that can modify most of the runtime information and
will be resolved against the corresponding run kind:

 * [V1Job](/docs/experimentation/jobs/): for running batch jobs, model training experiments, data processing jobs, ...  
 * [V1Service](/docs/experimentation/services/): for running tensorboards, notebooks, streamlit, custom services or an API.  
 * [V1TFJob](/docs/experimentation/distributed/tf-jobs/): for running distributed Tensorflow training job.  
 * [V1PytorchJob](/docs/experimentation/distributed/pytorch-jobs/): for running distributed Pytorch training job.
 * [V1MPIJob](/docs/experimentation/distributed/mpi-jobs/): for running distributed MPI job.  
 * [V1Spark](/docs/experimentation/distributed/spark-jobs/): for running a spark Application.
 * [V1Dask](/docs/experimentation/distributed/dask-jobs/): for running a Dask job.
 * [V1Dag](/docs/automation/flow-engine/specification/): for running a DAG/workflow.

For example, fi we define a generic component for running Jupyter Notebook:

```yaml
version: 1.1
kind: component
name: notebook
run:
  kind: service
  ports: [8888]
  container:
    image: "jupyter/tensorflow-notebook"
    command: ["jupyter", "lab"]
    args: [
      "--no-browser",
      "--ip=0.0.0.0",
      "--port={{globals.ports[0]}}",
      "--allow-root",
      "--NotebookApp.allow_origin=*",
      "--NotebookApp.trust_xheaders=True",
      "--NotebookApp.token=",
      "--NotebookApp.base_url={{globals.base_url}}",
      "--LabApp.base_url={{globals.base_url}}"
    ]

This component is generic, and does not define resources requirements, if for instance this component is hosted on github and you don't want to modify the component while at the same time you want to request a GPU for the notebook, you can patch the run:

version: 1.1
kind: operation
urlRef: https://raw.githubusercontent.com/org/repo/master/components/notebook.yaml
runPatch:
  container:
    resources:
      limits:
        nvidia.com/gpu: 1

By applying a run patch you can effectively share components while having full control over customizable details.

hubRef

Polyaxon provides a Component Hub for hosting versioned components with an access control system to improve the productivity of your team.

To run a component hosted on Polyaxon Component Hub, you can use hubRef

version: 1.1
kind: operation
hubRef: myComponent:v1.1
...

dagRef

If you building a dag and you have a component that can be used by several operation, you can define a component and reuse it in all operations using dagRef. Please check Polyaxon automation's flow engine section for more details.

urlRef

You can host your components on an accessible url, e.g github, and reference those components without downloading the data manually.

version: 1.1
kind: operation
urlRef: https://raw.githubusercontent.com/org/repo/master/components/my-component.yaml
...

Please note that you can only use this reference when using the CLI tool.

pathRef

In many situations, components can be placed in different folders within a project, e.g. data-processing, data-exploration, ml-modeling, ...

You can define operations without the need to change the directory by referencing a path to that component:

version: 1.1
kind: operation
pathRef: ../data-processing/component-clean.yaml
...

Please note that you can only use this reference when using the CLI tool.

component

If you are still in the development phase or if you are building a singleton operation that can be executed in a unique way, you can define the component inline inside the operation:

version: 1.1
kind: operation
component:
  run:
     kind: job
     container:
       image: foo:latest
       command: train --lr=0.01
...

isApproved

This is a flag to trigger human validation before queuing and scheduling an operation. the default behavior is True even when the field is not set, i.e. no validation is required. To require a human validation prior to scheduling an operation, you can set this field to False.

isApproved: false

Cost

A field to define the cost of running the operation, the value is a float and should map to a convention of a cost estimation in your team or it can map directly to the cost of using the environment where the operation is running.

cost: 2.2