async def build_transformation(): func_buf = await serialize(func_code, "python") inp = { "a": ("int", 12,), "b": ("int", 7,), "code": ("python", func_buf), } transformation = { "__output__": ("result", "int", None) } environment = { "powers": ["ipython"] } for k,v in inp.items(): celltype, value = v buf = await serialize(value, celltype) checksum = get_hash(buf) buffer_cache.cache_buffer(checksum, buf) sem_checksum = await get_semantic_checksum(checksum, celltype, k) transformation[k] = celltype, None, sem_checksum envbuf = await serialize(environment, "plain") checksum = get_hash(envbuf) buffer_cache.cache_buffer(checksum, envbuf) transformation["__env__"] = checksum tf_buf = tf_get_buffer(transformation) print(tf_buf.decode()) tf_checksum = get_hash(tf_buf) buffer_cache.cache_buffer(tf_checksum, tf_buf) tf = DummyTransformer(tf_checksum) result = await transformation_cache.run_transformation_async(tf_checksum) print(buffer_cache.get_buffer(result)) print(transformation_cache.transformation_logs[tf_checksum])
async def build_transformation(): func_buf = await serialize( get_source(func) + "\nresult = func(a,b)", "python") inp = { "a": ( "int", 12, ), "b": ( "int", 7, ), "code": ("python", func_buf), } transformation = {"__output__": ("result", "int", None)} for k, v in inp.items(): celltype, value = v buf = await serialize(value, celltype) checksum = get_hash(buf) buffer_cache.cache_buffer(checksum, buf) sem_checksum = await get_semantic_checksum(checksum, celltype, k) transformation[k] = celltype, None, sem_checksum tf_buf = tf_get_buffer(transformation) print(tf_buf.decode()) tf_checksum = get_hash(tf_buf) buffer_cache.cache_buffer(tf_checksum, tf_buf) tf = DummyTransformer(tf_checksum) result = await transformation_cache.run_transformation_async(tf_checksum) print(buffer_cache.get_buffer(result))
def triple_it(a): print("triple", a) return 3 * a ctx.transform = triple_it ctx.transform.a = ctx.a ctx.transform.debug = True ctx.myresult = ctx.transform ctx.compute() print(ctx.myresult.value) ctx2 = Context() ctx2.sub = ctx ctx2.sub2 = ctx ctx2.translate() print(ctx2.sub.myresult.value) ctx2.compute() print(ctx2.sub.myresult.value) ctx2.sub.a = 3 ctx2.sub2.a = 5 ctx2.compute() print(ctx2.sub.myresult.value) print(ctx2.sub2.myresult.value) graph = ctx.get_graph() j = json.dumps(graph, sort_keys=True, indent=2) from seamless import get_hash print(get_hash(j).hex())
def h(value): return get_hash(json.dumps(value)+"\n")
def h(value): return get_hash(json.dumps(value)+"\n")
from seamless import communion_server communion_server.configure_servant( buffer=True, buffer_status=True, transformation_job=True, transformation_status=True, ) 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 = cell("transformer").set("c = a + b") ctx.code.connect(ctx.tf.code) ctx.tf.c.connect(ctx.result) ctx.compute() print("Secret source code ", ctx.code.checksum) print("hash verification ", get_hash("c = a + b\n").hex()) print(ctx.result.value) print(ctx.result.checksum) print("Communion peer 1 ready.") import sys if len(sys.argv) == 1 or sys.argv[1] != "--interactive": import asyncio asyncio.get_event_loop().run_forever()
import seamless #redis_sink = seamless.RedisSink() #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().set("c = a + b") ctx.code.set_label("Secret source code") ctx.code.connect(ctx.tf.code) ctx.tf.c.connect(ctx.result) ctx.equilibrate() print("Secret source code ", ctx.code.checksum, ctx._get_manager().value_get(bytes.fromhex(ctx.code.checksum))) print("hash verification ", get_hash("c = a + b\n").hex()) print(ctx.result.value) print(ctx.result.checksum) import asyncio asyncio.get_event_loop().run_forever()
print(ctx.cell1.value) print(ctx.cell1.storage) print(ctx.cell1.form) ctx.cell2 = cell("mixed").set(80) ctx.result = cell("mixed") ctx.tf = transformer({"a": "input", "b": "input", "c": "output"}) ctx.cell1_unilink = unilink(ctx.cell1) ctx.cell1_unilink.connect(ctx.tf.a) ctx.cell2.connect(ctx.tf.b) ctx.code = cell("transformer").set("c = a['x'] * a['y'] + b") ctx.code.connect(ctx.tf.code) ctx.result_unilink = unilink(ctx.result) ctx.tf.c.connect(ctx.result_unilink) ctx.result_copy = cell("mixed") ctx.result.connect(ctx.result_copy) ctx.compute() print(ctx.cell1.value) print(ctx.code.value) ctx.compute() print(ctx.result.value, ctx.status) ctx.cell2.set(10) ctx.compute() print(ctx.result.value, ctx.status) with open("/tmp/mixedcellsilk.mixed", "rb") as f: content = f.read() from seamless import get_hash print(get_hash(content).hex())
import cProfile, pstats, io cProfile.profiler = cProfile.Profile() cProfile.profiler.enable() from seamless import get_hash from seamless.core.protocol.serialize import _serialize repeat = int(10e6) #repeat = int(5) #for n in range(1000): # 2x10 GB #for n in range(100): # 2x1 GB for n in range(100): a = "A:%d:" % n + str(n % 10) * repeat b = "B:%d:" % n + str(n % 10) * repeat get_hash(_serialize(a, "str")) get_hash(_serialize(b, "str")) print(n + 1) import sys sortby = 'tottime' ps = pstats.Stats(cProfile.profiler, stream=sys.stdout).sort_stats(sortby) ps.print_stats(10)