def test_map_list_N_uniform(mylib): from seamless.highlevel import Context, Cell ctx = Context() ctx.include(mylib.map_list_N) ctx.add = Context() ctx.add.uniform = Cell("mixed") ctx.add.inp = Context() ctx.add.inp.a = Cell("mixed") ctx.add.inp.b = Cell("mixed") def add(a, b, c): print("ADD", a, b, c) return a + b + c ctx.add.tf = add ctx.add.tf.debug = True ctx.add.tf.a = ctx.add.inp.a ctx.add.tf.b = ctx.add.inp.b ctx.add.tf.c = ctx.add.uniform ctx.add.result = ctx.add.tf ctx.add.result.celltype = "int" ctx.compute() ctx.a = [110, 120, 130, 140] ctx.a.hash_pattern = {"!": "#"} ctx.b = [2, 4, 8, 12] ctx.b.hash_pattern = {"!": "#"} ctx.c = 7000 ctx.result = Cell() ctx.mapping = ctx.lib.map_list_N(context_graph=ctx.add, inp={ "a": ctx.a, "b": ctx.b, }, uniform=ctx.c, result=ctx.result, elision=True, elision_chunksize=2) ctx.compute() print(ctx.result.value) ctx.c = 8000 ctx.compute() print(ctx.result.value)
print("*" * 80) print("b", ctx.b.exception) print("b", ctx.b.value) print("*" * 80) ctx.a = "test2" ctx.compute() print("*" * 80) print("a", ctx.a.exception) print("a", ctx.a.value) print("*" * 80) print("b", ctx.b.exception) print("b", ctx.b.value) print("*" * 80) ctx.c = Cell() ctx.c.celltype = "float" ctx.translate() ctx.c._get_cell().set_buffer(b"'blah'\n") ctx.compute() print("c", ctx.c.exception) print(ctx.c.buffer) print() print("*" * 80) print("* TRANSFORMER") print("*" * 80) print() ctx.tf = lambda x, y: x + y ctx.tf.pins.x.celltype = "int" ctx.tf.pins.y.celltype = "int"
from seamless.highlevel import Context, Cell ctx = Context() ctx.a = Cell("int").set(10) ctx.c = Cell("int").set(30) ctx.s = Cell() ctx.translate() ctx.s.a = ctx.a ctx.s.c = ctx.c ctx.ss = ctx.s ctx.ss.celltype = "plain" ctx.compute() print(ctx.s.value) print(ctx.ss.value) ctx.s.set("NOT TO BE PRINTED") ctx.compute() print(ctx.s.value) print(ctx.ss.value) print(ctx.s.exception) print("") ctx.s = "NOT TO BE PRINTED 2" ctx.s.a = ctx.a ctx.s.c = ctx.c ctx.compute() print(ctx.s.value) print(ctx.ss.value) print(ctx.s.exception) print("") ctx.s.set({}) ctx.compute() print(ctx.s.value) print(ctx.ss.value)
tf_code = ''' print(__name__) print(testmodule) print(testmodule.q) from .testmodule import q print(q) import sys print([m for m in sys.modules if m.find("testmodule") > -1]) result = a + b ''' from seamless.highlevel import Transformer, Cell, Context ctx = Context() ctx.testmodule = Cell("plain").set({ "type": "interpreted", "language": "python", "code": "q = 10" }) ctx.tf = Transformer(code=tf_code) ctx.tf.a = 10 ctx.tf.b = 20 ctx.tf.testmodule = ctx.testmodule ctx.tf.pins.testmodule.celltype = "plain" ctx.tf.pins.testmodule.subcelltype = "module" ctx.c = ctx.tf ctx.compute() print(ctx.testmodule.status) print(ctx.tf.status) print(ctx.tf.exception) print(ctx.c.value)
from seamless.highlevel import Context, Cell, Transformer ctx = Context() ctx.a = Cell("int").set(10) ctx.a.share(readonly=False) ctx.b = Cell("int").set(20) ctx.b.share(readonly=False) ctx.c = Cell("int").set(30).share() ctx.tf = lambda a,b: a+b ctx.tf.a = ctx.a ctx.tf.b = ctx.b ctx.c = ctx.tf ctx.translate() ctx.save_graph("initial-graph.seamless") ctx.save_zip("initial-graph.zip")
from seamless.highlevel import Context ctx = Context() ctx.a = {} ctx.translate() ctx.a.b = 12 ctx.compute() print(ctx.a.value, ctx.a.value.data) print(type(ctx.a.value), type(ctx.a.value.data)) ctx.a.example.b = 1.1 ctx.compute() print(ctx.a.value, ctx.a.value.data, ctx.a.schema) ctx.tf = lambda x, y: x + y ctx.tf.x = ctx.a.b ctx.c = 20 ctx.tf.y = ctx.c ctx.d = ctx.tf ctx.compute() print(ctx.d.value) #32 print(ctx.tf.inp.value) print() print("Stage 2") ctx.f0 = 20 ctx.q = {} ctx.translate() ctx.q.c = ctx.c ctx.q.d = ctx.d ctx.q.f = ctx.f0 ctx.q.g = 50
from seamless.highlevel import Context ctx = Context() def add(a, b): return a + b ctx.a = 10 ctx.b = 20 ctx.add = add ctx.add.a = ctx.a ctx.add.b = ctx.b ctx.c = ctx.add ctx.compute() print(ctx.c.value) ctx.a.celltype = "plain" ctx.a.mount("/tmp/a") ctx.b.celltype = "plain" ctx.b.mount("/tmp/b") ctx.c.celltype = "plain" ctx.c.mount("/tmp/c", mode="w") ctx.add.code.mount("/tmp/code.py") ctx.compute()
def func2(b, c, d): return b + 10 * c - d ctx.tf = func2 ctx.tf.d = 5 ctx.compute() print(ctx.tf.status) print(ctx.tf.exception) print(ctx.tf.inp.value) print(ctx.tf.result.value) graph = ctx.get_graph() dummy = Context() dummy.c = graph dummy.c.celltype = "plain" dummy.compute() print(dummy.c.checksum) ctx = Context() ctx.tf = func2 ctx.a = 10 ctx.b = 20 ctx.tf.b = ctx.b ctx.tf.c = 80 ctx.tf.d = 5 ctx.tf.inp.x = 123 ctx.compute() print(ctx.tf.status)