def test_map_list(mylib): from seamless.highlevel import Context, Cell ctx = Context() ctx.include(mylib.map_list) ctx.add = Context() ctx.add.inp = Cell("mixed") def add(a, b): print("ADD", a, b) return a + b ctx.add.tf = add ctx.add.tf.debug = True ctx.add.tf.a = ctx.add.inp ctx.add.tf.b = 1000 ctx.add.result = ctx.add.tf ctx.add.result.celltype = "int" ctx.compute() ctx.inp = [10, 20, 30, 40] ctx.inp.hash_pattern = {"!": "#"} ctx.result = Cell() ctx.mapping = ctx.lib.map_list(context_graph=ctx.add, inp=ctx.inp, result=ctx.result, elision=True, elision_chunksize=2) ctx.compute() print(ctx.mapping.ctx.m.exception) print(ctx.result.value) ctx.inp += [80, 12, 1, 1, 10, 20, 30, 40] ctx.compute() print(ctx.result.value)
def test_map_dict(mylib): from seamless.highlevel import Context, Cell ctx = Context() ctx.include(mylib.map_dict) ctx.add = Context() ctx.add.inp = Cell("mixed") def add(a, b): print("ADD", a, b) return a + b ctx.add.tf = add ctx.add.tf.debug = True ctx.add.tf.a = ctx.add.inp ctx.add.tf.b = 1000 ctx.add.result = ctx.add.tf ctx.add.result.celltype = "int" ctx.compute() ctx.inp = {"key1": 10, "key2": 220, "key3": 30, "key4": 40} ctx.inp.hash_pattern = {"*": "#"} ctx.result = Cell() ctx.keyorder = Cell("plain") ctx.mapping = ctx.lib.map_dict(context_graph=ctx.add, inp=ctx.inp, keyorder0=[], keyorder=ctx.keyorder, result=ctx.result, elision=True, elision_chunksize=2) ctx.compute() print(ctx.mapping.ctx.status) print(ctx.mapping.ctx.m.ctx.top.exception) print(ctx.result.value) ctx.mapping.keyorder0 = ctx.keyorder.value ctx.compute() print(ctx.result.value) inp = ctx.inp.value inp.update({ "a": 80, "b": 30, "c": 999, "d": -1, }) ctx.inp = inp ctx.compute() print(ctx.result.value) print(ctx.keyorder.value)
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)
from seamless.highlevel import Context, Cell, Macro ctx = Context() ctx.a = Cell("int") ctx.b = Cell("int") def add(a,b): return a+b ctx.add = add ctx.add.a = ctx.a ctx.add.b = ctx.b ctx.result = ctx.add ctx.result.celltype = "int" ctx.compute() graph = ctx.get_graph(runtime=True) ctx = Context() ctx.graph = Cell("plain").set(graph) m = ctx.m = Macro() ctx.par_static = 100 ctx.par_dynamic = 20 m.par_static = ctx.par_static m.graph = ctx.graph m.pins.par_dynamic = {"io": "input", "celltype": "int"} m.pins.graph_result = {"io": "output", "celltype": "int"} def run_macro(ctx, par_static, graph): print("RUN MACRO", par_static) ctx.subctx = HighLevelContext(graph) ctx.subctx.a.set(par_static) ctx.par_dynamic = cell("int") ctx.par_dynamic.connect(ctx.subctx.b)
from seamless.highlevel import Context, Transformer, Cell ctx = Context() ctx.a = Cell() ctx.a.set(2) ctx.b = Cell() ctx.b.set(3) ctx.add = Transformer() ctx.add.a = ctx.a ctx.add.b = ctx.b ctx.add.code = "a + b" ctx.result = Cell() ctx.result = ctx.add ctx.compute() ctx.save_graph("intro.seamless") ctx.save_zip("intro.zip")