How to use AsyncAction to distribute tasks from Jupyter notebook?

I have a set of compute tasks that I want to submit to the C3 console from the Jupyter notebook, and I’d like to distribute the tasks across different machines to speed up processing time. How can I use AsyncAction to do this?

You need a type and a function to use AsyncAction. For example,


Car.c3typ

entity type Car schema name 'CAR' {
  @py(env="server")
  computeTotalStorage: function(length: double, width: double): double
}

Car.py

def computeTotalStorage(length, width):
  return length*width

In your Jupyter Notebook

lengths = [1,2,3]
widths = [1,2,3]
for i in range(3):
  asyncSpec = c3.AsyncActionSpec(
    typeName = "Car",
    action = "computeTotalStorage",
    args = {"length": lengths[i], width: widths[i]}
  )    
  action = c3.AsyncAction.submit(spec = asyncSpec) # this job is now in ActionQueue

// the three actions you submit are now distributed 

To get the result,

c3.AsyncAction.get(this = {"id":action.id}).result

You can use this on C3 functions as well. For example,

emSpec = c3.EvalMetricsSpec(
  expressions = ["metric1", "metric2", "metric3"],
  ids = ["car1", "car2", "car3"],
  interval = "DAY",
  start = "2018-01-01",
  end = "2019-01-01",
)

asyncSpec = c3.AsyncActionSpec(
  typeName = "Car",
  action = "evalMetrics",
  args = {"spec": emSpec}
)    

Please also consider other jobs

2 Likes