Test suite for Jupyter-notebook

Sample example of use of PyCOMPSs from Jupyter

First step

Import ipycompss library


In [ ]:
import pycompss.interactive as ipycompss

Second step

Initialize COMPSs runtime Parameters indicates if the execution will generate task graph, tracefile, monitor interval and debug information. The parameter taskCount is a work around for the dot generation of the legend


In [ ]:
ipycompss.start(graph=True, trace=True, debug=True, project_xml='../project.xml', resources_xml='../resources.xml')

Third step

Import task module before annotating functions or methods


In [ ]:
from pycompss.api.task import task

Fourth step

Declare functions and decorate with @task those that should be tasks


In [ ]:
@task(returns=int)
def test(val1):
    return val1 * val1

In [ ]:
@task(returns=int)
def test2(val2, val3):
    return val2 + val3

Fifth step

Invoke tasks


In [ ]:
a = test(2)

In [ ]:
b = test2(a, 5)

Sixt step

Import compss_wait_on module and synchronize tasks


In [ ]:
from pycompss.api.api import compss_wait_on

In [ ]:
result = compss_wait_on(b)

Only those results being sychronized with compss_wait_on will have a valid value


In [ ]:
print "Results: "
print "a: ", a
print "b: ", b
print "result: ", result

Stop COMPSs runtime. All data will be synchronized in the main program


In [ ]:
ipycompss.stop(sync=True)

In [ ]:
print "Results after stopping PyCOMPSs: "
print "a: ", a
print "b: ", b
print "result: ", result

CHECK THE RESULTS FOR THE TEST


In [ ]:
from pycompss.runtime.binding import Future
if a == 4 and isinstance(b, Future) and result == 9:
    print "RESULT=EXPECTED"
else:
    print "RESULT=UNEXPECTED"

In [ ]: