Commit f79085ca authored by Hardik Juneja's avatar Hardik Juneja

[erp5_joblib]: create a new portal skins and move all examples there

parent 1186a65a
......@@ -58,7 +58,7 @@ def example_simple_function(self, active_process_path):
result = Parallel(n_jobs=2, pre_dispatch='all', timeout=30, verbose=30)(delayed(sqrt)(i**2) for i in range(5))
# Set result value and an id to the active result and post it
result = ActiveResult(result=result, signature=12345)
result = ActiveResult(result=result)
active_process.postResult(result)
log("joblib activity result", result)
return result
......
if REQUEST is not None:
raise Unauthorized
"""
This script safely executes and return the result of the given safe function
"""
if callable(batch_function) is False:
raise Exception('batch_function is not callable')
from Products.CMFActivity.ActiveResult import ActiveResult
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>erp5_joblib_examples</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
active_process = context.portal_activities.newActiveProcess()
active_process_id = active_process.getId()
path = active_process.getPhysicalPath()
context.portal_activities.activate(activity="SQLQueue", after_method_id="Base_callSafeFunction", active_process=active_process).Base_joblibRandomForestFunction(path)
return path
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_driverScriptRandomForest</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
active_process = context.portal_activities.newActiveProcess()
active_process_id = active_process.getId()
path = active_process.getPhysicalPath()
context.portal_activities.activate(activity="SQLQueue", after_method_id="Base_callSafeFunction", active_process=active_process).Base_joblibSimpleFunction(path)
return path
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_driverScriptSquareRoot</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>example_random_forest_function</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>joblibUseCaseExamples</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_joblibRandomForestFunction</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Base_joblibRandomForestFunction</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>example_simple_function</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>joblibUseCaseExamples</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_joblibSimpleFunction</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Base_joblibSimpleFunction</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -26,7 +26,6 @@
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod
class Test(ERP5TypeTestCase):
"""
......@@ -37,59 +36,16 @@ class Test(ERP5TypeTestCase):
return "TestJoblibUsecases"
def test_randomForest(self):
portal_skins = self.getPortal().portal_skins
manage_addExternalMethod(self.portal,
'Base_joblibRandomForestFunction',
'Base_joblibRandomForestFunction',
'joblibUseCaseExamples',
'example_random_forest_function')
skin_folder = getattr(portal_skins, "erp5_joblib")
skin_folder.manage_addProduct['PythonScripts'].manage_addPythonScript(id='Base_driverScriptRandomForest')
script = getattr(skin_folder, 'Base_driverScriptRandomForest')
script.ZPythonScript_edit('**kw', """import time
active_process = context.portal_activities.newActiveProcess()
active_process_id = active_process.getId()
path = active_process.getPhysicalPath()
context.portal_activities.activate(activity="SQLQueue", after_method_id="Base_callSafeFunction", active_process=active_process).Base_joblibRandomForestFunction(path)
return path""")
path = portal_skins.erp5_joblib.Base_driverScriptRandomForest()
path = self.portal.Base_driverScriptRandomForest()
self.tic()
active_process = portal_skins.erp5_joblib.portal_activities.unrestrictedTraverse(path)
active_process = self.portal.portal_activities.unrestrictedTraverse(path)
result = active_process.getResultList()
self.assertAlmostEqual(0.98444444444444446, result[0].result)
def test_UnderRootOfSquaresFunction(self):
portal_skins = self.getPortal().portal_skins
manage_addExternalMethod(self.portal,
'Base_joblibSimpleFunction',
'Base_joblibSimpleFunction',
'joblibUseCaseExamples',
'example_simple_function')
skin_folder = getattr(portal_skins, "erp5_joblib")
skin_folder.manage_addProduct['PythonScripts'].manage_addPythonScript(id='Base_driverScriptSquareRoot')
script = getattr(skin_folder, 'Base_driverScriptSquareRoot')
script.ZPythonScript_edit('**kw', """import time
active_process = context.portal_activities.newActiveProcess()
active_process_id = active_process.getId()
path = active_process.getPhysicalPath()
context.portal_activities.activate(activity="SQLQueue", after_method_id="Base_callSafeFunction", active_process=active_process).Base_joblibSimpleFunction(path)
return path""")
path = portal_skins.erp5_joblib.Base_driverScriptSquareRoot()
path = self.portal.Base_driverScriptSquareRoot()
self.tic()
active_process = self.portal.portal_activities.unrestrictedTraverse(path)
result = active_process.getResultList()
self.assertEquals([0.0, 1.0, 2.0, 3.0, 4.0], result[0].result)
def beforeTearDown(self):
scripts = ['Base_driverScriptSquareRoot', 'Base_driverScriptSquareRoot', 'Base_joblibRandomForestFunction', 'Base_joblibSimpleFunction']
for script in scripts:
try:
self.portal.manage_delObjects([script,])
except Exception:
continue
erp5_joblib
\ No newline at end of file
erp5_joblib
erp5_joblib_examples
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment