class_docstr: A Task is composed of an execution step and zero or more outputs.
  Tasks are executed in the context of a TaskGroup, which, in turn, can
  be run by a Session.
  
  Task outputs are fetched by the session at the end of the run.
  
  The recommended way of creating a task is by using `net_builder.ops`.
  Example:
  
      from net_builder import ops
      with Node('trainer'), Task(name='my_task', num_instances=2):
          with ops.task_init():
              globl = ops.Const(0)
          with ops.task_instance_init():
              local = ops.Const(0)
          with ops.loop(100):
              ops.Copy(globl, local)
          with ops.task_instance_exit():
              ops.Add([globl, local], [globl])
          with ops.task_exit():
              ops.Mul([globl, globl], [globl])
  
  The task above will create 2 instances that will run in parallel.
  Each instance will copy `local` to `globl` 100 times, Then Add `local`
  to `globl` once. The `Mul` will only execute once, after all the instances
  of the task have finished.
class_docstr_tok: ["A","Task","is","composed","of","an","execution","step","and","zero","or","more","outputs",".","Tasks","are","executed","in","the","context","of","a","TaskGroup",",","which",",","in","turn",",","can","be","run","by","a","Session",".","Task","outputs","are","fetched","by","the","session","at","the","end","of","the","run",".","The","recommended","way","of","creating","a","task","is","by","using","`","net_builder.ops","`",".","Example",":","from","net_builder","import","ops","with","Node","(","'trainer","'",")",",","Task","(","name='my_task","'",",","num_instances=2",")",":","with","ops.task_init","(",")",":","globl","=","ops.Const","(","0",")","with","ops.task_instance_init","(",")",":","local","=","ops.Const","(","0",")","with","ops.loop","(","100",")",":","ops.Copy","(","globl",",","local",")","with","ops.task_instance_exit","(",")",":","ops.Add","(","[","globl",",","local","]",",","[","globl","]",")","with","ops.task_exit","(",")",":","ops.Mul","(","[","globl",",","globl","]",",","[","globl","]",")","The","task","above","will","create","2","instances","that","will","run","in","parallel",".","Each","instance","will","copy","`","local","`","to","`","globl","`","100","times",",","Then","Add","`","local","`","to","`","globl","`","once",".","The","`","Mul","`","will","only","execute","once",",","after","all","the","instances","of","the","task","have","finished","."]
docstr: Instantiate a Task and add it to the current TaskGroup and Node.
  
  Args:
     step:    If provided, this task will run this ExecutionStep.
     outputs: If provided, the task will return the provided outputs
              to the client at completion time.
     node:    If provided, force task execution on the given node.
     name:    Name of the Task.
     num_instances: If provided, this task will be cloned num_instances
                    times at runtime, and all instances will run
                    concurrently.
docstr_tok: ["Instantiate","a","Task","and","add","it","to","the","current","TaskGroup","and","Node",".","Args",":","step",":","If","provided",",","this","task","will","run","this","ExecutionStep",".","outputs",":","If","provided",",","the","task","will","return","the","provided","outputs","to","the","client","at","completion","time",".","node",":","If","provided",",","force","task","execution","on","the","given","node",".","name",":","Name","of","the","Task",".","num_instances",":","If","provided",",","this","task","will","be","cloned","num_instances","times","at","runtime",",","and","all","instances","will","run","concurrently","."]
code: def __init__(
      self,
      step=None,
      outputs=None,
      workspace_type=None,
      group=None,
      node=None,
      name=None,
      num_instances=None,
  ):
      """
      Instantiate a Task and add it to the current TaskGroup and Node.
  
      Args:
         step:    If provided, this task will run this ExecutionStep.
         outputs: If provided, the task will return the provided outputs
                  to the client at completion time.
         node:    If provided, force task execution on the given node.
         name:    Name of the Task.
         num_instances: If provided, this task will be cloned num_instances
                        times at runtime, and all instances will run
                        concurrently.
      """
      if not name and isinstance(step, core.ExecutionStep):
          name = step.Proto().name
      if not name:
          name = "task"
      # register this node name with active context
      self.node = str(
          Node.current(None if node is None else Node(node))
      )
      self.group = TaskGroup.current(group, required=False)
  
      self.name = Task._get_next_name(self.node, self.group, name)
  
      # may need to be temporarily removed later if Task used as a context
      if self.group is not None:
          self.group._tasks_to_add.append(self)
  
      self._already_used = False
      self._step = None
      self._step_with_setup = None
      self._outputs = []
      if step is not None:
          self.set_step(step)
      if outputs is not None:
          self.add_outputs(outputs)
  
      self._pipeline = None
      self._is_pipeline_context = False
      self._workspace_type = workspace_type
      self._report_net = None
      self._num_instances = num_instances
  
imports: from caffe2.python import core, context
  from caffe2.python.schema import Field, from_blob_list
  from collections import defaultdict
  from copy import copy
label_desc: Use image node_id 2 to create a new Task object from inherited base classes: context with example: obj = Task(step, outputs, workspace_type, group, node, name, num_instances)