Skip to content

Using CMFActivity as a backend for Joblib

Hardik Juneja requested to merge hjuneja/erp5:joblib_improv into master

This merge request is an attempt to use CMFActivity as a backend for scikit learn's [joblib] (https://github.com/joblib/joblib) library.

For further reading : https://nexedi.erp5.net/web_page_module/6103/WebPage_viewAsWeb

Tests Results : https://nexedi.erp5.net/test_result_module/20171213-4777F59

In this pull request I introduce new activity type SQLJoblib, this activity type will store the results in a resultDict

Below is a small example for SQLJoblib usage with resultDict

from Products.CMFActivity.Activity.SQLJoblib import sqljoblib_hash

active_process = portal.portal_activities.newActiveProcess() 

# document can be the persistent model array, or the input array for example
#
# it can also be the active_process is the calculation has no context 
# but this is a special case
document = portal.restrictedTraverse(some_url) 

document.activate(activity="SQLJoblib" , active_process=active_process).someMethod(1, 2, 3, 4) 
document.activate(activity="SQLJoblib" , active_process=active_process).someMethod(3, 4, 5, 6) 
document.activate(activity="SQLJoblib" , active_process=active_process).someMethod(7, 8, 9, 10) 

# Print results as dict
result_dict = active_process.getResultDict() 
print result_dict[sqljoblib_hash(1, 2, 3, 4)] # returns 1 
print result_dict[sqljoblib_hash(3, 4, 5, 6)] # returns 2 
print result_dict[sqljoblib_hash(7, 8, 9, 10)] # returns 3 

Merge request reports