コード例 #1
0
import os
os.environ["SEAMLESS_COMMUNION_ID"] = "jobmaster"
os.environ["SEAMLESS_COMMUNION_INCOMING"] = "localhost:8602"
import seamless
seamless.set_ncores(0)

from seamless import communion_server
communion_server.configure_master(
    buffer=True,
    buffer_status=True,
    transformation_job=True,
    transformation_status=True
)

from seamless.highlevel import load_graph
import sys, json

infile, outfile = sys.argv[1:]
graph = json.load(open(infile))

seamless.database_cache.connect()

ctx = load_graph(graph)

import asyncio
done = asyncio.sleep(1)
asyncio.get_event_loop().run_until_complete(done)

ctx.compute()

colored_graph = ctx.get_graph()
コード例 #2
0
"""
Retrieval of buffers and computation results from database cache
First run simple.py with Seamless database running
"""

import seamless
from seamless.core import context, cell, transformer, unilink

seamless.set_ncores(0)  # Forbids Seamless to add 1 and 2 by itself

seamless.database_cache.connect()

ctx = context(toplevel=True)
ctx.cell1 = cell("int").set_checksum(
    "bc4bb29ce739b5d97007946aa4fdb987012c647b506732f11653c5059631cd3d"  # 1
)
ctx.cell2 = cell("int").set_checksum(
    "191fb5fc4a9bf2ded9a09a0a2c4eb3eb90f15ee96deb1eec1a970df0a79d09ba"  # 2
)
ctx.code = cell("transformer").set_checksum(
    "1cbba7cc10e067273fdec7cc350d2b87508c1959d26bbab4f628f6f59ec49607"  # a + b
)
ctx.result = cell("int")
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_copy = cell("transformer")
ctx.code.connect(ctx.code_copy)
ctx.code_copy.connect(ctx.tf.code)
ctx.result_unilink = unilink(ctx.result)
コード例 #3
0
ファイル: communion-peer2.py プロジェクト: sjdv1982/seamless
import seamless
from seamless.core import macro_mode_on
from seamless.core import context, cell, transformer, pytransformercell, link
from seamless import get_hash

seamless.set_ncores(0)
from seamless import communionserver
communionserver.configure_master(
    value=True, 
    transformer_job=True,
    transformer_result=True,
    transformer_result_level2=True
)
communionserver.configure_servant(value=True)

#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)
コード例 #4
0
# will not work until load_graph will be much smarter
if args.database:
    communion_server.configure_servant({
        "buffer": False,
        "buffer_status": False,
        "buffer_length": False,
        "transformation_job": False,
        "transformation_status": False,
        "semantic_to_syntactic": False,
        "hard_cancel": False,  # allow others to hard cancel our jobs
        "clear_exception": False, # allow others to clear exceptions on our jobs
    })
"""

if args.ncores is not None:
    seamless.set_ncores(args.ncores)

shareserver_address = env.get("SHARESERVER_ADDRESS")
if shareserver_address is not None:
    if shareserver_address == "HOSTNAME":
        shareserver_address = subprocess.getoutput("hostname -I | awk '{print $1}'")
    seamless.shareserver.DEFAULT_ADDRESS = shareserver_address
    print("Setting shareserver address to: {}".format(shareserver_address))

import seamless.stdlib

from seamless.highlevel import load_graph, Context
graph = json.load(args.graph)
if args.zipfile is None and not args.add_zip:
    ctx = load_graph(graph, mounts=args.mounts, shares=args.shares)
else:
コード例 #5
0
"""

import sys
import seamless

import seamless.core.execute

seamless.core.execute.DIRECT_PRINT = True

seamless.database_sink.connect()
seamless.database_cache.connect()
#seamless.set_ncores(2)
#seamless.set_parallel_evaluations(5)

seamless.set_ncores(8)  ###
seamless.set_parallel_evaluations(100)  ###

# for the big testing, 20 evaluations
seamless.set_parallel_evaluations(20)  ###
"""
import logging
logging.basicConfig()
logging.getLogger("seamless").setLevel(logging.DEBUG)
"""

from seamless.highlevel import Context, Cell, Macro
from seamless.highlevel.library import LibraryContainer

import time
import cProfile
コード例 #6
0
ファイル: cachehit_level2.py プロジェクト: sjdv1982/seamless
    return v["a"] + 2
ctx.code = cell("transformer").set(func)
ctx.tf = transformer(params)
ctx.code.connect(ctx.tf.code)
ctx.cell1.connect(ctx.tf.v)
ctx.result = cell()
ctx.tf.result.connect(ctx.result)
ctx.equilibrate()
print(ctx.result.value)

tcache = ctx._get_manager().transform_cache
tf1 = tcache.transformer_to_level1[ctx.tf]
print("TF level 1", tf1.get_hash())
tf2 = tcache.hlevel1_to_level2[tf1.get_hash()]
print("TF level 2", tf2.get_hash())

seamless.set_ncores(0) # no more local computations
ctx.ttf = transformer(params)
ctx.code.connect(ctx.ttf.code)
ctx.cell1a.connect(ctx.ttf.v)
ctx.result2 = cell()
ctx.ttf.result.connect(ctx.result2)
ctx.equilibrate()
print(ctx.result2.value)

ttf1 = tcache.transformer_to_level1[ctx.ttf]
print("TTF level 1", ttf1.get_hash())
ttf2 = tcache.hlevel1_to_level2[ttf1.get_hash()]
print("TTF level 2", ttf2.get_hash())

assert ttf2.get_hash() == tf2.get_hash()
コード例 #7
0
# Version of high-in-low4.py where the input and result are really big
# To be run with Seamless database with flatfile, so that the memory usage stays low

import seamless

import seamless.core.execute
seamless.core.execute.DIRECT_PRINT = True

seamless.database_sink.connect()
seamless.database_cache.connect()
seamless.set_ncores(2)
seamless.set_parallel_evaluations(5)
"""
import logging
logging.basicConfig()
logging.getLogger("seamless").setLevel(logging.DEBUG)
"""

from seamless.highlevel import Context, Cell, Macro

sctx = Context()
sctx.inp = Cell("mixed")
sctx.inp2 = Cell()
sctx.inp2 = sctx.inp
sctx.a = Cell("str")
sctx.b = Cell("str")
sctx.a = sctx.inp2.a
sctx.b = sctx.inp2.b


def add(a, b):
コード例 #8
0
print(ctx.cell1.value)
print(ctx.cell1.semantic_checksum)
print(ctx.cell1a.value)
print(ctx.cell1a.semantic_checksum)

params = {"v": ("input", "plain"), "result": "output"}


def func(v):
    return v["a"] + 2


ctx.code = cell("transformer").set(func)
ctx.tf = transformer(params)
ctx.code.connect(ctx.tf.code)
ctx.cell1.connect(ctx.tf.v)
ctx.result = cell()
ctx.tf.result.connect(ctx.result)
ctx.compute()
print(ctx.result.value)

seamless.set_ncores(0)  # no more local computations
ctx.ttf = transformer(params)
ctx.code.connect(ctx.ttf.code)
ctx.cell1a.connect(ctx.ttf.v)
ctx.result2 = cell()
ctx.ttf.result.connect(ctx.result2)
ctx.compute()
print(ctx.result2.value)