def define_ctx(): with macro_mode_on(): ctx = context(toplevel=True) ctx.cell1 = cell("json").set(1) ctx.cell2 = cell("json").set(2) ctx.result = cell("json") ctx.tf = transformer({"a": "input", "b": "input", "c": "output"}) ctx.cell1_link = link(ctx.cell1) ctx.cell1_link.connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = pytransformercell().set("c = a + b") ctx.code.connect(ctx.tf.code) ctx.result_link = link(ctx.result) ctx.tf.c.connect(ctx.result_link) return ctx
def define_ctx(): with macro_mode_on(): ctx = context(toplevel=True) ctx.cell1 = cell().set(1) ctx.cell2 = cell().set(2) ctx.result = cell() ctx.tf = transformer({ "a": "input", "b": "input", "c": "output" }) ctx.cell1_link = link(ctx.cell1) ctx.cell1_link.connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = pytransformercell().set("c = a + b") ctx.code.connect(ctx.tf.code) ctx.result_link = link(ctx.result) ctx.tf.c.connect(ctx.result_link) return ctx
def build(ctx, param, run): print("BUILD") tf = transformer({ "a": "input", "b": "input", "c": "output", }) if param.startswith("PARAM"): ctx.tf_alt1 = tf else: ctx.tf_alt2 = tf ctx.tf = link(tf) ctx.run = pytransformercell().set(run) ctx.run.connect(tf.code) ctx.a = link(tf.a).export() ctx.b = link(tf.b).export() ctx.c = link(tf.c).export() ctx.param = cell("json").set(param)
def build(ctx, param, run): print("BUILD") tf = transformer( { "a": "input", "b": "input", "c": "output", }) if param.startswith("PARAM"): ctx.tf_alt1 = tf else: ctx.tf_alt2 = tf ctx.tf = link(tf) ctx.run = pytransformercell().set(run) ctx.run.connect(tf.code) ctx.a = cell() ctx.a.connect(tf.a) ctx.b = cell() ctx.b.connect(tf.b) ctx.c = cell() tf.c.connect(ctx.c) ctx.param = cell().set(param)
import seamless from seamless.core import macro_mode_on from seamless.core import context, cell, transformer, pytransformercell with macro_mode_on(): ctx = context(toplevel=True) ctx.cell1 = cell().set(1) ctx.cell2 = cell().set(2) ctx.result = cell() ctx.tf = transformer({"a": "input", "b": "input", "c": "output"}) ctx.cell1.connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = pytransformercell().set("c = a + b") ctx.code.connect(ctx.tf.code) ctx.tf.c.connect(ctx.result) shell = ctx.tf.shell()
"a": "input", "b": "input", "c": "output" }) ctx.a = StructuredCell( "a", ctx.cell1, schema = None, buffer = None, plain = True, inchannels = None, outchannels = [()] ) ctx.a.outchannels[()].connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = pytransformercell().set("c = a + b") ctx.code.connect(ctx.tf.code) ctx.tf.c.connect(ctx.result) ctx.mount("/tmp/mount-test") ctx.equilibrate() print(ctx.result.value) ctx.a.set(1) ctx.equilibrate() print(ctx.result.value) #shell = ctx.tf.shell()
#redis_cache = seamless.RedisCache() with macro_mode_on(): ctx = context(toplevel=True) ctx.cell1 = cell().set(2) ctx.cell2 = cell().set(3) ctx.result = cell() ctx.tf = transformer({ "a": "input", "b": "input", "c": "output" }) ctx.cell1.connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = pytransformercell() ctx.code.connect(ctx.tf.code) ctx.tf.c.connect(ctx.result) import asyncio done = asyncio.sleep(1) ctx.equilibrate() asyncio.get_event_loop().run_until_complete(done) ctx.code.from_label("Secret source code") print("Secret source code", ctx.code.checksum) ctx.equilibrate() print(ctx.status) print(ctx.result.checksum) print(ctx.result.value)
import seamless from seamless.core import macro_mode_on from seamless.core import context, textcell, transformer, pytransformercell with macro_mode_on(): ctx = context(toplevel=True) ctx.cell1 = textcell().set(1) ctx.cell2 = textcell().set(2) ctx.result = textcell() ctx.tf = transformer({"a": "input", "b": "input", "c": "output"}) ctx.cell1.connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = pytransformercell().set("c = float(a) + float(b)") ctx.code.connect(ctx.tf.code) ctx.tf.c.connect(ctx.result) ctx.result.mount("/tmp/mount-test/myresult", persistent=True) ctx.mount("/tmp/mount-test") ctx.sub = context(toplevel=False, context=ctx, name="sub") ctx.sub.mycell = textcell().set("This is my cell\nend") ctx.equilibrate() print(ctx.result.value) ctx.cell1.set(10) ctx.equilibrate() print(ctx.result.value) print(ctx.result.value) ctx.code.set("c = float(a) + float(b) + 1000") ctx.equilibrate() print(ctx.result.value) print(ctx.status())
import seamless from seamless.core import macro_mode_on from seamless.core import context, cell, transformer, pytransformercell, link with macro_mode_on(): ctx = context(toplevel=True) ctx.cell1 = cell().set(1) ctx.cell2 = cell().set(2) ctx.result = cell() ctx.tf = transformer({"a": "input", "b": "input", "c": "output"}) ctx.cell1_link = link(ctx.cell1) ctx.cell1_link.connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = pytransformercell().set(""" import time time.sleep(3) c = a + b """) ctx.code.connect(ctx.tf.code) ctx.result_link = link(ctx.result) ctx.tf.c.connect(ctx.result_link) def callback(): print("Equilibration complete") ctx._get_manager().on_equilibrate(callback) ctx.cell1.set(10) for n in range(5): ctx.equilibrate(1)
ctx.cell1 = cell().set(1) ctx.cell2 = cell().set(2) ctx.result = cell() ctx.tf = transformer({ "a": "input", "b": "input", "testmodule": ("input", "ref", "module", "python"), "c": "output", }) ctx.cell1.connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = pytransformercell().set(""" print("macro execute") 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]) c = a + b print("/macro execute")""") ctx.code.connect(ctx.tf.code) ctx.tf.c.connect(ctx.result) ctx.testmodule = pythoncell().set("q = 10") ctx.testmodule.connect(ctx.tf.testmodule) ctx.equilibrate() print(ctx.result.value) ctx.cell1.set(10) ctx.equilibrate() print(ctx.result.value)
cell1.mount("/tmp/mixedcell.mixed") ctx.cell1 = cell1 print(ctx.cell1.storage) print(ctx.cell1.form) print(ctx.cell1.value) ctx.cell2 = cell("mixed").set(80) ctx.result = cell("mixed") ctx.tf = transformer({ "a": "input", "b": "input", "c": "output" }) ctx.cell1_link = link(ctx.cell1) ctx.cell1_link.connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = pytransformercell().set("c = a['x'] * a['y'] + b") ctx.code.connect(ctx.tf.code) ctx.result_link = link(ctx.result) ctx.tf.c.connect(ctx.result_link) ctx.result_copy = cell("mixed") ctx.result.connect(ctx.result_copy) print(ctx.cell1.value) print(ctx.code.value) ctx.equilibrate() print(ctx.result.value, ctx.status) ctx.cell2.set(10) ctx.equilibrate() print(ctx.result.value, ctx.status)
ctx.run.connect(tf.code) ctx.a = cell() ctx.a.connect(tf.a) ctx.b = cell() ctx.b.connect(tf.b) ctx.c = cell() tf.c.connect(ctx.c) ctx.param = cell().set(param) with macro_mode_on(): ctx = context(toplevel=True) ctx.macro = macro({ "param":"copy", "run": ("copy", "text"), }) ctx.macro_code = pytransformercell().set(build) ctx.macro_code.connect(ctx.macro.code) ctx.run = pytransformercell().set(run) ctx.run.connect(ctx.macro.run) ctx.param = cell().set("PARAM") ctx.param.connect(ctx.macro.param) ctx.a = cell().set(1) ctx.b = cell().set(2) ctx.c = cell() ctx.a.connect(ctx.macro.ctx.a) ctx.b.connect(ctx.macro.ctx.b) ctx.macro.ctx.c.connect(ctx.c) ctx.equilibrate(0.5) print(ctx.c.value)
ctx.run = pytransformercell().set(run) ctx.run.connect(tf.code) ctx.a = link(tf.a).export() ctx.b = link(tf.b).export() ctx.c = link(tf.c).export() ctx.param = cell("json").set(param) with macro_mode_on(): ctx = context(toplevel=True) ctx.macro = macro({ "param": "copy", "run": ("copy", "text"), }) ctx.macro_code = pytransformercell().set(build) ctx.macro_code.connect(ctx.macro.code) ctx.run = pytransformercell().set(run) ctx.run.connect(ctx.macro.run) ctx.param = cell("json").set("PARAM") ctx.param.connect(ctx.macro.param) ctx.a = cell("json").set(1) ctx.b = cell("json").set(2) ctx.c = cell() ctx.a.connect(ctx.macro.ctx.a) ctx.b.connect(ctx.macro.ctx.b) ctx.macro.ctx.c.connect(ctx.c) ctx.equilibrate(0.5) print(ctx.c.value) print(ctx.macro.ctx.tf.status())