Exemple #1
0
from seamless.highlevel import Context

ctx = Context()
ctx.code = "head -$lines testdata"
ctx.code.celltype = "text"
ctx.code.mount("/tmp/test.bash")
ctx.tf = lambda lines, testdata: None
ctx.tf.language = "bash"
ctx.tf.testdata = "a \nb \nc \nd \ne \nf \n"    
ctx.tf.lines = 3
ctx.tf.code = ctx.code
ctx.result = ctx.tf
ctx.result.mount("/tmp/result")
ctx.translate(force=True)
ctx.equilibrate()
print(ctx.result.value)
ctx.code = "tar czf test.tgz testdata; cat test.tgz"
ctx.equilibrate()
print(ctx.result.value)
ctx.code = "python3 -c 'import numpy as np; np.save(\"test\",np.arange(12)*3)'; cat test.npy"
ctx.equilibrate()
print(ctx.result.value)
    class ForkedPdb(pdb.Pdb):
        """A Pdb subclass that may be used
        from a forked multiprocessing child

        """
        def interaction(self, *args, **kwargs):
            _stdin = sys.stdin
            try:
                sys.stdin = open('/dev/stdin')
                super().interaction(*args, **kwargs)
            finally:
                sys.stdin = _stdin

    #from pdb_clone.pdb import set_trace
    #from pdb import set_trace
    #from ipdb import set_trace
    #set_trace = ForkedPdb().set_trace
    from seamless.pdb import set_trace
    set_trace()
    return 3 * a


ctx.transform = triple_it
ctx.transform.debug = True
ctx.code = ctx.transform.code.pull()
ctx.code.mount("triple_it.py")
ctx.transform.a = ctx.a
ctx.myresult = ctx.transform
ctx.compute(report=None)
print(ctx.myresult.value)
Exemple #3
0
from seamless.highlevel import Context

code = """
sleep 3
head -$lines testdata > RESULT
"""

ctx = Context()
ctx.code = code
ctx.code.celltype = "text"
ctx.tf = lambda lines, testdata: None
ctx.tf.language = "bash"
ctx.tf.docker_image = "ubuntu"
ctx.tf.testdata = "a \nb \nc \nd \ne \nf \n"
ctx.tf.lines = 3
ctx.tf.code = ctx.code

ctx.compute(1)
ctx.tf.lines = 2  # This will cancel the old transformer, and hopefully the Docker image
ctx.compute()
print(ctx.tf.status)
print(ctx.tf.exception)
print(ctx.tf.result.value)
Exemple #4
0
from seamless.highlevel import Context

ctx = Context()
ctx.code = "bash -c 'head -$lines testdata'"
ctx.code.celltype = "text"
ctx.code.mount("/tmp/test.bash")
ctx.tf = lambda lines, testdata: None
ctx.tf.language = "docker"
ctx.tf.docker_image = "ubuntu"
ctx.tf.docker_options = {"name": "ubuntu-container"}
ctx.tf.testdata = "a \nb \nc \nd \ne \nf \n"  
ctx.tf.lines = 3
ctx.tf.code = ctx.code
ctx.result = ctx.tf
ctx.result.mount("/tmp/result")
ctx.translate(force=True)
ctx.equilibrate()
print(ctx.result.value)
from seamless.highlevel import Context, Cell

ctx = Context()
ctx.transform = lambda a,b: a + b
ctx.transform.a = 2
ctx.transform.b = 3
ctx.translate()
ctx.transform.example.a = 0
ctx.transform.example.b = 0
ctx.result = ctx.transform
ctx.result.celltype = "plain"
ctx.compute()
print(ctx.result.value)

ctx.transform.language = "cpp"
ctx.code = """
extern "C" int transform(int a, int b, double *result) {
    *result = a + b;
    return 0;
}"""
ctx.code.celltype = "code"
ctx.code.language = "cpp"
ctx.transform.code = ctx.code
ctx.translate()
ctx.transform.result.example = 0.0 #example, just to fill the schema
ctx.compute()
print(ctx.result.value)

ctx.a = 10
ctx.a.celltype = "plain"
ctx.transform.a = ctx.a
Exemple #6
0
        "default": "",
        "help": "Package name, if absolute imports are used"
    },
    "package": {
        "type":
        "cell",
        "celltype":
        "plain",
        "io":
        "output",
        "help":
        """Python package dict, to be set as the code attribute of a Module""",
    },
}
ctx.constructor_params = constructor_params
ctx.code = Context()
ctx.code.analyze_dependencies = set_resource("analyze_dependencies.py")
ctx.code.build_package = set_resource("build_package.py")

ctx.compute()

# 2: obtain graph and zip

graph = ctx.get_graph()
zip = ctx.get_zip()

# 3: Package the contexts in a library

from seamless.highlevel.library import LibraryContainer
mylib = LibraryContainer("mylib")
mylib.python_package = ctx
Exemple #7
0
from seamless.highlevel import Context

ctx = Context()
ctx.code = "head -$lines testdata > RESULT"
ctx.code.celltype = "text"
ctx.code.mount("/tmp/test.bash", authority="cell")
ctx.tf = lambda lines, testdata: None
ctx.tf.language = "bash"
ctx.tf.docker_image = "rpbs/seamless"
ctx.tf.testdata = "a \nb \nc \nd \ne \nf \n"
ctx.tf.lines = 3
ctx.tf.code = ctx.code
ctx.result = ctx.tf
ctx.result.celltype = "text"
ctx.result.mount("/tmp/result", "w")
ctx.translate(force=True)
ctx.compute()
print(ctx.result.value)
ctx.code = "head -3 testdata > firstdata; tar czf RESULT testdata firstdata"
ctx.compute()
print(ctx.result.value)
ctx.code = "python3 -c 'import numpy as np; np.save(\"test\",np.arange(12)*3)'; cat test.npy > RESULT"
ctx.compute()
print(ctx.tf.result.value)
print(ctx.tf.status)
print(ctx.tf.exception)
ctx.code = "python3 -c 'import numpy as np; np.save(\"test\",np.arange(12)*3)'; echo OK > ok; mkdir RESULT; mv ok test.npy RESULT"
ctx.compute()
print(ctx.tf.result.value)
print(ctx.tf.status)
print(ctx.tf.exception)
Exemple #8
0
ctx.filtered_pdb.share("filtered_pdb.pdb")

ctx.fix_pdb = Transformer()
ctx.fix_pdb.language = "bash"
ctx.fix_pdb.code = 'head -20 filtered_pdb > RESULT'
ctx.fix_pdb.filtered_pdb = ctx.filtered_pdb

ctx.pdb = ctx.fix_pdb
ctx.pdb.celltype = "text"
ctx.pdb.share("pdb.pdb")

ctx.filter_code = ctx.filter_pdb.code.pull()
ctx.filter_code.share("filter_code.bash", readonly=False)
ctx.filter_code.mount("/tmp/filter_code.bash")

ctx.code = ctx.fix_pdb.code.pull()
ctx.code.share("code.bash", readonly=False)
ctx.code.mount("/tmp/code.bash")

import seamless, os
seamless_dir = os.path.dirname(seamless.__file__)
c = ctx.js = Cell()
c.celltype = "text"
c.set(open(seamless_dir + "/js/seamless-client.js").read())
c.mimetype = "text/javascript"
c.share(path="seamless-client.js")

c = ctx.vismol_js = Cell()
c.celltype = "text"
c.mount("vismol.js", authority="file")
c.mimetype = "text/javascript"
from seamless.highlevel import Context, Cell

ctx = Context()
ctx.mount(os.path.join(tempfile.gettempdir(), "transformer-compiled"))

ctx.transform = lambda a,b: a + b
ctx.transform.example.a = 0
ctx.transform.example.b = 0
ctx.result = ctx.transform
ctx.result.celltype = "json"
ctx.equilibrate()
print(ctx.result.value)

ctx.transform.language = "cpp"
ctx.code >> ctx.transform.code
ctx.code = """
extern "C" double transform(int a, int b) {
    return a + b;
}"""
ctx.transform.result.example = 0.0 #example, just to fill the schema
ctx.equilibrate()
print(ctx.result.value)

ctx.a = 10
ctx.a.celltype = "json"
ctx.transform.a = ctx.a

ctx.b = 30
ctx.b.celltype = "json"
ctx.transform.b = ctx.b
Exemple #10
0
from seamless.highlevel import Context

ctx = Context()
ctx.code = "head -$lines testdata > RESULT"
ctx.code.celltype = "text"
ctx.code.mount("/tmp/test.bash", authority="cell")
ctx.tf = lambda lines, testdata: None
ctx.tf.language = "bash"
ctx.tf.docker_image = "ubuntu"
ctx.tf.testdata = "a \nb \nc \nd \ne \nf \n"
ctx.tf.lines = 3
ctx.tf.code = ctx.code
ctx.result = ctx.tf
ctx.result.celltype = "text"
ctx.result.mount("/tmp/result", "w")
ctx.translate(force=True)
ctx.compute()
print(ctx.result.value)
print(ctx.tf.exception)
ctx.code = """
python3 -c 'import numpy as np; np.save(\"test\",np.arange(12)*3)'
echo 'hello' > test.txt
mkdir RESULT
mv test.npy RESULT
mv test.txt RESULT
"""
ctx.tf.docker_image = "rpbs/seamless"
del ctx.result.mount
ctx.result.celltype = "structured"
ctx.result_npy = ctx.result["test.npy"]
ctx.result_txt = ctx.result["test.txt"]
Exemple #11
0
ctx.transform.a = 2
ctx.transform.b = 3
ctx.translate()
ctx.transform.example.a = 0
ctx.transform.example.b = 0
ctx.result = ctx.transform
ctx.result.celltype = "plain"
ctx.compute()
print(ctx.result.value)

print("")
print("ERROR 1:")
print("")

ctx.transform.language = "cpp"
ctx.code = ctx.transform.code.pull()
ctx.code = """
#include <iostream>
using namespace std;
extern "C" int transform(int a, int b, double *result) {
    cout << "transform " << a << " " << b << endl;
    return 1;
}"""
ctx.translate()
ctx.transform.result.example = 0.0  #example, just to fill the schema
ctx.transform.main_module.link_options = ["-lstdc++"]
ctx.compute()
print(ctx.transform.exception)
print("")
print("ERROR 2:")
print("")