示例#1
0
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)
示例#2
0
def test_map_dict_chunk(mylib):
    from seamless.highlevel import Context, Cell
    ctx = Context()
    ctx.include(mylib.map_dict_chunk)

    ctx.mul = Context()
    ctx.mul.inp = Cell("mixed")

    def mul(a, factor):
        print("MUL", a)
        result = {}
        for key in a:
            result[key] = a[key] * factor
        return result

    ctx.mul.tf = mul
    ctx.mul.tf.debug = True
    ctx.mul.tf.a = ctx.mul.inp
    ctx.mul.tf.factor = 3
    ctx.mul.result = ctx.mul.tf
    ctx.mul.result.celltype = "mixed"
    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_chunk(context_graph=ctx.mul,
                                         inp=ctx.inp,
                                         chunksize=2,
                                         keyorder0=[],
                                         keyorder=ctx.keyorder,
                                         result=ctx.result,
                                         elision=True,
                                         elision_chunksize=3)
    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)
    print("UP")
    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)
示例#3
0
def constructor_switch(ctx, libctx, celltype, input, selected, outputs):
    ctx.input = Cell(celltype)
    input.connect(ctx.input)
    ctx.selected = Cell("str")
    selected.connect(ctx.selected)

    macro_pins = {
        "celltype": {
            "io": "parameter", 
            "celltype": "str",
        },
        "input": {
            "io": "input", 
            "celltype": celltype,
        },
        "selected": {
            "io": "parameter", 
            "celltype": "str",
        },
        "options": {
            "io": "parameter", 
            "celltype": "plain",
        }
    }

    """
    Create one macro output pin per cell in the outputs dict
    This will populate the ctx passed to switch_func with output cells
     that can be connected to
    """
    options = []
    for output_name in outputs:
        assert isinstance(output_name, str), output_name
        if output_name in macro_pins or output_name == "switch_macro":
            msg = "You cannot switch to a cell under the selector '{}'"
            raise Exception(msg.format(output_name))
        options.append(output_name)
        pin = {
            "io": "output",
            "celltype": celltype
        }
        macro_pins[output_name] = pin
    ctx.switch_macro = Macro(pins=macro_pins)
    ctx.switch_macro.code = libctx.switch_code.value
    ctx.switch_macro.celltype = celltype
    ctx.switch_macro.input = ctx.input
    ctx.switch_macro.selected = ctx.selected
    ctx.switch_macro.options = options

    for output_name in outputs:
        macro_pin = getattr(ctx.switch_macro, output_name)
        output_cell = Cell(celltype)
        setattr(ctx, output_name, output_cell)
        setattr(ctx, output_name, macro_pin)
        outputs[output_name].connect_from(output_cell)
示例#4
0
def constructor_join(ctx, libctx, celltype, inputs, selected, output):
    ctx.output = Cell(celltype)
    output.connect_from(ctx.output)
    ctx.selected = Cell("str")
    selected.connect(ctx.selected)

    macro_pins = {
        "celltype": {
            "io": "parameter", 
            "celltype": "str",
        },
        "output": {
            "io": "output", 
            "celltype": celltype,
        },
        "selected": {
            "io": "parameter", 
            "celltype": "str",
        },
        "options": {
            "io": "parameter", 
            "celltype": "plain",
        }
    }

    """
    Create one macro input pin per cell in the inputs dict
    This will populate the ctx passed to join_func with input cells
     that can be connected to
    """
    options = []
    for input_name in inputs:
        assert isinstance(input_name, str), input_name
        if input_name in macro_pins or input_name == "join_macro":
            msg = "You cannot join from a cell under the selector '{}'"
            raise Exception(msg.format(input_name))
        options.append(input_name)
        pin = {
            "io": "input",
            "celltype": celltype
        }
        macro_pins[input_name] = pin
    ctx.join_macro = Macro(pins=macro_pins)
    ctx.join_macro.code = libctx.join_code.value
    ctx.join_macro.celltype = celltype
    ctx.join_macro.selected = ctx.selected
    ctx.join_macro.options = options

    for input_name in inputs:
        input_cell = Cell(celltype)
        setattr(ctx, input_name, input_cell)
        setattr(ctx.join_macro, input_name, input_cell)
        inputs[input_name].connect(input_cell)
    ctx.output = ctx.join_macro.output
示例#5
0
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)
示例#6
0
def serve(filename, sharename=None, mount=False):
    import os
    cell = Cell()
    cell.celltype = "text"
    _, ext = os.path.splitext(filename)
    cell.mimetype = ext[1:]
    if mount:
        cell.mount(filename, mode="rw", authority="file")
    else:
        data = open(filename, "rb").read()
        cell.set(data)
    if sharename is None:
        sharename = filename
    cell.share(path=sharename, readonly=True)
    return cell
示例#7
0
def build_transformer():
    del ctx.transform
    ctx.transform = lambda a, b: a + b
    ctx.translate()
    ctx.transform.example.a = 0
    ctx.transform.example.b = 0
    ctx.result = ctx.transform
    ctx.result.celltype = "plain"

    ctx.transform.a = ctx.a
    ctx.transform.b = ctx.b

    ctx.transform.language = "cpp"
    ctx.transform.main_module.compiler_verbose = False
    ctx.code = ctx.transform.code.pull()
    ctx.code = """
    extern "C" double add(int a, int b);
    extern "C" int transform(int a, int b, double *result) {
        *result = add(a,b);
        return 0;
    }"""
    ctx.translate()
    ctx.transform.result.example = 0.0  #example, just to fill the schema

    ctx.transform.main_module.add.language = "c"
    code = """
    int add(int a, int b, double *result) {*result = a+b;};
    """
    ctx.add_code = Cell("code")
    ctx.add_code.language = "c"
    ctx.transform.main_module.add.code = ctx.add_code
    ctx.add_code.set(code)
    ctx.translate()
示例#8
0
def constructor(ctx, libctx, result):
    ctx.sub_inner = ctx.lib.subtract()
    if result is not None:
        ctx.result = ctx.sub_inner.result
        result.connect_from(ctx.result)
    else:
        ctx.result = Cell()
示例#9
0
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)
示例#10
0
def constructor(ctx, libctx, celltype, a, b, c):
    assert celltype in ("int", "float"), celltype
    ctx.a = Cell(celltype)
    ctx.b = Cell(celltype)
    ctx.c = Cell(celltype)
    a.connect(ctx.a)
    b.connect(ctx.b)
    c.connect_from(ctx.c)

    ctx.subtract = Transformer()
    ctx.subtract_code = Cell("code")
    ctx.subtract_code = libctx.subtract_code.value
    ctx.subtract.code = ctx.subtract_code
    ctx.subtract.a = ctx.a
    ctx.subtract.pins.a.celltype = celltype
    ctx.subtract.b = ctx.b
    ctx.subtract.pins.b.celltype = celltype
    ctx.c = ctx.subtract
示例#11
0
def constructor(
    ctx, libctx,
    fallback_mode,
    upstream,
    modified, conflict,
    merged, state
):
    assert fallback_mode in ("upstream", "modified", "no"), fallback_mode
    m = ctx.m = Macro()
    m.code = libctx.macro_code.value
    m.fallback_mode = fallback_mode
    m.code_start = libctx.code_start.value
    m.code_update = libctx.code_update.value

    ctx.upstream = Cell("text")
    upstream.connect(ctx.upstream)
    m.pins.upstream = {"io": "input", "celltype": "text"}
    m.upstream = ctx.upstream

    ctx.modified = Cell("text")
    modified.link(ctx.modified)
    m.pins.modified = {"io": "edit", "celltype": "text"}
    m.modified = ctx.modified

    ctx.conflict = Cell("text")
    conflict.link(ctx.conflict)
    m.pins.conflict = {"io": "edit", "celltype": "text"}
    m.conflict = ctx.conflict

    ctx.merged = Cell("text")
    merged.connect_from(ctx.merged)
    m.pins.merged = {"io": "output", "celltype": "text"}
    ctx.merged = m.merged

    ctx.state = Cell("text")
    state.connect_from(ctx.state)
    m.pins.state = {"io": "output", "celltype": "text"}
    ctx.state = m.state
示例#12
0
def constructor(ctx, libctx, result, state={}, **kw):
    ctx.result = Cell("mixed")
    if state is None:
        return
    startvalue = state.get("startvalue")
    if startvalue is not None:
        ctx.startvalue = Cell("mixed").set(startvalue)
        channel_contents = ctx.startvalue
        for step, operator in enumerate(state.get("operators", [])):
            opname, op_params = operator
            subctxname = "step%d_%s" % (step + 1, opname)
            ctx[subctxname] = Context()
            subctx = ctx[subctxname]
            if opname in ("filter", "first"):
                subctx.tf = Transformer()
                subctx.tf.code = op_params
                subctx.tf.channel_contents = channel_contents
                subctx.result = subctx.tf
                subctx.result.celltype = "mixed"
                channel_contents = subctx.result
            else:
                raise NotImplementedError(opname)
        ctx.result = channel_contents
    result.connect_from(ctx.result)
示例#13
0
def constructor(ctx, libctx, context_graph, inp, result, elision,
                elision_chunksize):
    m = ctx.m = Macro()
    m.elision = elision
    m.graph = context_graph
    m.pins.graph.celltype = "plain"
    m.pins.result = {
        "io": "output",
        "celltype": "mixed",
        "hash_pattern": {
            "!": "#"
        }
    }

    ctx.inp = Context()
    ctx.cs_inp = Context()
    inp_prefix = "INPUT_"
    m.inp_prefix = inp_prefix
    m.pins.inp_prefix.celltype = "str"
    m.elision_chunksize = elision_chunksize
    m.pins.elision_chunksize.celltype = "int"
    for key in inp:
        c = Cell()
        ctx.inp[key] = c
        c.hash_pattern = {"!": "#"}
        inp[key].connect(c)
        ctx.cs_inp[key] = Cell("checksum")
        ctx.cs_inp[key] = ctx.inp[key]
        setattr(m, inp_prefix + key, ctx.cs_inp[key])

    macro_code_lib_code = libctx.map_list_N.value + "\n\n" + libctx.map_list_N_nested.value
    macro_code_lib = {
        "type": "interpreted",
        "language": "python",
        "code": macro_code_lib_code
    }
    ctx.macro_code_lib = Cell("plain").set(macro_code_lib)
    ctx.macro_code_lib_code = Cell("code").set(macro_code_lib_code)
    m.macro_code_lib = ctx.macro_code_lib
    m.pins.macro_code_lib.celltype = "plain"
    m.pins.macro_code_lib.subcelltype = "module"
    m.macro_code_lib_code = ctx.macro_code_lib_code
    m.pins.macro_code_lib_code.celltype = "plain"
    m.map_list_N_nested_code = libctx.map_list_N_nested.value
    ###m.pins.map_list_N_nested_code.celltype = "python"

    m.code = libctx.main.value
    ctx.result = Cell()
    ctx.result.hash_pattern = {"!": "#"}
    ctx.result = m.result
    result.connect_from(ctx.result)
示例#14
0
def constructor(
    ctx,
    libctx,
    package_dirdict,
    package_name,
    package,
):
    mod = ctx.analyze_dependencies = Module()
    mod.code = libctx.code.analyze_dependencies.value
    tf = ctx.build_package = Transformer()
    tf.code = libctx.code.build_package.value
    ctx.package_dirdict = Cell("plain")
    tf.package_dirdict = ctx.package_dirdict
    package_dirdict.connect(ctx.package_dirdict)
    tf.analyze_dependencies = mod
    tf.package_name = package_name
    ctx.package = tf
    ctx.package.celltype = "plain"
    package.connect_from(ctx.package)
from seamless.highlevel import Context, Cell
import traceback

ctx = Context()
ctx.a = Cell("int").set(20)
ctx.b = ctx.a
ctx.b.celltype = "int"
ctx.compute()
print(ctx.b.value)
try:
    ctx.b.mount("/tmp/x")
except Exception:
    traceback.print_exc()
try:
    ctx.b.share(readonly=False)
except Exception:
    traceback.print_exc()
ctx.compute()
示例#16
0
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)
示例#17
0
def constructor(ctx, libctx, context_graph, inp, result):
    m = ctx.m = Macro()
    m.graph = context_graph
    m.pins.result = {
        "io": "output",
        "celltype": "mixed",
        "hash_pattern": {
            "!": "#"
        }
    }

    ctx.inp = Context()
    ctx.cs_inp = Context()
    inp_prefix = "INPUT_"
    m.inp_prefix = inp_prefix
    for key in inp:
        c = Cell()
        ctx.inp[key] = c
        c.hash_pattern = {"!": "#"}
        inp[key].connect(c)
        ctx.cs_inp[key] = Cell("checksum")
        ctx.cs_inp[key] = ctx.inp[key]
        setattr(m, inp_prefix + key, ctx.cs_inp[key])

    def map_list_N(ctx, inp_prefix, graph, **inp):
        first_k = list(inp.keys())[0]
        length = len(inp[first_k])
        first_k = first_k[len(inp_prefix):]
        for k0 in inp:
            k = k0[len(inp_prefix):]
            if len(inp[k0]) != length:
                err = "all cells in inp must have the same length, but '{}' has length {} while '{}' has length {}"
                raise ValueError(err.format(k, len(inp[k0]), first_k, length))

        from seamless.core import Cell as CoreCell
        from seamless.core.unbound_context import UnboundContext
        pseudo_connections = []
        ctx.result = cell("mixed", hash_pattern={"!": "#"})

        ctx.sc_data = cell("mixed", hash_pattern={"!": "#"})
        ctx.sc_buffer = cell("mixed", hash_pattern={"!": "#"})
        ctx.sc = StructuredCell(data=ctx.sc_data,
                                buffer=ctx.sc_buffer,
                                inchannels=[(n, ) for n in range(length)],
                                outchannels=[()],
                                hash_pattern={"!": "#"})

        for n in range(length):
            hc = HighLevelContext(graph)

            subctx = "subctx%d" % (n + 1)
            setattr(ctx, subctx, hc)

            if not hasattr(hc, "inp"):
                raise TypeError(
                    "map_list_N context must have a subcontext called 'inp'")
            hci = hc.inp
            if not isinstance(hci, UnboundContext):
                raise TypeError(
                    "map_list_N context must have an attribute 'inp' that is a context, not a {}"
                    .format(type(hci)))

            for k0 in inp:
                k = k0[len(inp_prefix):]
                if not hasattr(hci, k):
                    raise TypeError(
                        "map_list_N context must have a cell called inp.'{}'".
                        format(k))
                if isinstance(hci[k], StructuredCell):
                    raise TypeError(
                        "map_list_N context has a cell called inp.'{}', but its celltype must be mixed, not structured"
                        .format(k))
                if not isinstance(hci[k], CoreCell):
                    raise TypeError(
                        "map_list_N context must have an attribute inp.'{}' that is a cell, not a {}"
                        .format(k, type(hci[k])))
                if hci[k].celltype != "mixed":
                    raise TypeError(
                        "map_list_N context has a cell called inp.'{}', but its celltype must be mixed, not {}"
                        .format(k, hci[k].celltype))

                con = [".." + k], ["ctx", subctx, "inp", k]
                pseudo_connections.append(con)
                cs = inp[k0][n]
                hci[k].set_checksum(cs)

            resultname = "result%d" % (n + 1)
            setattr(ctx, resultname, cell("int"))
            c = getattr(ctx, resultname)
            hc.result.connect(c)
            c.connect(ctx.sc.inchannels[(n, )])
            con = ["ctx", subctx, "result"], ["..result"]
            pseudo_connections.append(con)

        ctx.sc.outchannels[()].connect(ctx.result)
        ctx._pseudo_connections = pseudo_connections

    m.code = map_list_N
    ctx.result = Cell()
    ctx.result.hash_pattern = {"!": "#"}
    ctx.result = m.result
    result.connect_from(ctx.result)
示例#18
0
    "context_graph": "context",
    "inp": {
        "type": "celldict",
        "io": "input"
    },
    "result": {
        "type": "cell",
        "io": "output"
    },
}

ctx = Context()
ctx.adder = Context()
sctx = ctx.adder
sctx.inp = Context()
sctx.inp.a = Cell("mixed")
sctx.inp.b = Cell("mixed")
sctx.a = Cell("int")
sctx.b = Cell("int")
sctx.a = sctx.inp.a
sctx.b = sctx.inp.b


def add(a, b):
    return a + b


sctx.add = add
sctx.add.a = sctx.a
sctx.add.b = sctx.b
sctx.result = sctx.add
示例#19
0
        for k, path in exits.items():
            export_cell = exports[k]
            subinstance = instance
            for subpathnr, subpath in enumerate(path):
                if subpath not in subinstance.get_children():
                    curr_path = path[:subpathnr + 1]
                    raise AttributeError("Invalid path {} ({})" %
                                         (path, curr_path))
                subinstance = getattr(subinstance, subpath)
            if not isinstance(subinstance, Cell):
                raise TypeError("Invalid path {} is {} instead of Cell" %
                                (path, type(subinstance)))
            export_cell.connect_from(subinstance, target_path=name)


ctx.constructor_code = Cell("code").set(constructor)
ctx.constructor_params = {
    "template": "context",
    "pattern": "value",
    "ncopies": "value",
    "imports": {
        "type": "celldict",
        "io": "input"
    },
    "exports": {
        "type": "celldict",
        "io": "output"
    },
    "entries": "value",
    "exits": "value",
}
示例#20
0
ctx.a = 0
ctx.translate()
ctx.a = 2
ctx.compute()
ctx.get_graph()
print(ctx.a.schema)
print(ctx.a.value)
print(ctx.a.exception)

ctx.a = 1
ctx.a.example = 0
ctx.compute()
print(ctx.a.schema)
print(ctx.a.value)

ctx.a = Cell()
ctx.compute()
print(ctx.a.schema)
print(ctx.a.value)

ctx.a.example = 50
print(ctx.a.value)
print(ctx.a.schema)
ctx.a.set(12)

ctx.compute()
print(ctx.a.value)

ctx.a = 1.2
ctx.compute()
print(ctx.a.exception)
示例#21
0
merge.set_pin("mode", io="output")

merge.fallback = "no"
#TODO: add the validator to the schema of the .fallback property, instead of the main schema
#  (requires that .add_validator and ._set_property/._set_method become schema methods)
def validate_fallback(self):
    assert self.fallback in ("upstream", "modified", "no"), self.fallback
merge.io.handle.add_validator(validate_fallback)

merge.code_start = set_resource("cell-merge-START.py")
merge.code_update = set_resource("cell-merge-UPDATE.py")
merge.code_stop = ""

# Public cells
ctx.upstream = Cell()
ctx.upstream.celltype = "text"
merge.upstream = ctx.upstream

ctx.modified = Cell()
ctx.modified.celltype = "text"
ctx.link_modified = Link(ctx.modified, merge.modified)

ctx.conflict = Cell()
ctx.conflict.celltype = "text"
ctx.link_conflict = Link(ctx.conflict, merge.conflict)

ctx.fallback = merge.fallback.value
ctx.fallback.celltype = "text"
merge.fallback = ctx.fallback
示例#22
0
from seamless.highlevel import Context, Cell, Transformer

ctx = Context()
ctx.a = Cell()
ctx.a.celltype = "int"
ctx.compute()
ctx.a.set(1)
ctx.compute()
ctx.a.set("test")
ctx.compute()
print("*" * 80)
print(ctx.a.exception)
print(ctx.a.value)
print("*" * 80)

ctx.a = 12
ctx.compute()
ctx.a.celltype = "str"
ctx.b = ctx.a
ctx.b.celltype = "int"
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.a = "test2"
ctx.compute()
示例#23
0
from seamless.highlevel import Context, Cell
ctx = Context()

ctx.v = "test"
ctx.v_schema = Cell()
ctx.v_schema.celltype = "plain"
###ctx.mount("/tmp/mount-test")
ctx.translate()
ctx.link(ctx.v.schema, ctx.v_schema)
ctx.translate()
ctx.v_schema.set({'type': 'integer'})
ctx.compute()
print(ctx.v.schema)
print("*" * 50)
print(ctx.v.exception)
print("*" * 50)
ctx.v.schema.set({})
ctx.compute()  # this is needed, else the 1.2 below might take effect first,
# and then be overwritten by this. Seamless is async!!
print(ctx.v.schema)
print(ctx.v_schema.value)
ctx.v.example.set(1.2)
ctx.compute()
print("value:", ctx.v.value)
print("data:", ctx.v.data)
print("buffered:", ctx.v.buffered)
print(ctx.v_schema.value)
print("*" * 50)
print(ctx.v.exception)
print("*" * 50)
ctx.v_schema.set({"type": "string"})
示例#24
0
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)
示例#25
0
"""
import seamless
from seamless.highlevel import Context, Cell
import json, os

cache = seamless.RedisCache()

print("Load graph...")
graph = json.load(open("snakegraph.seamless"))
ctx = seamless.highlevel.load_graph(graph)

print("Bind files...")

# HACK: Keep the large pairwise lrmsd file out of the virtual file system
# To be eliminated when deep cells are there in Seamless
ctx.pw_lrmsd = Cell()
file = "docking-result-pairwise-lrmsd.txt"
print(file)
data = open(file).read()
ctx.pw_lrmsd = data
ctx.jobs.cluster_struc.inputfile_pairwise_lrmsd = ctx.pw_lrmsd

inputs = (
    "params/cluster-cutoff",
    "params/selected-cluster",
    "receptor.pdb",
    "ligand.pdb",
    "receptor-bound.pdb",
    "ligand-bound.pdb",
    "docking-result.dat",
    #"docking-result-pairwise-lrmsd.txt"
示例#26
0
ctx = Context()
ctx.txt = "not OK"
ctx.txt.celltype = "text"
ctx.txt.mount("mount.txt", authority="file")
ctx.compute()
print(ctx.txt.value)

###ctx.mount("mount-test", persistent=False)
ctx.intcell = 780
ctx.intcell.celltype = "int"
ctx.intcell.mount("/tmp/intcell.txt")

ctx.cpp_cell = """
#include <iostream>
using namespace std;
int main() 
{
    cout << "Hello, World!";
    return 0;
}
"""
ctx.cpp_cell.celltype = "code"
ctx.cpp_cell.language = "cpp"
ctx.cpp_cell.mount("/tmp/cpp_cell.cpp")

ctx.txt2 = Cell()
ctx.txt2.celltype = "text"
ctx.link(ctx.txt2, ctx.txt)

ctx.compute()
# continue in interactive mode...
示例#27
0
mylib.channel = ctx0
mylib.channel.constructor = constructor
mylib.channel.params = parameters
mylib.channel.api_schema = api_schema

ctx = Context()
ctx.include(mylib.channel)


def filter_code(key, value):
    import os
    return os.path.splitext(key)[1] == ""


ctx.filter_code = Cell("code").set(filter_code)
ctx.inst = (ctx.lib.channel().fromPath("./*",
                                       is_text=True).filter(filter_code))
ctx.result = ctx.inst.result
ctx.result.celltype = "plain"
ctx.compute()

print(ctx.result.value)

ctx.inst.first(lambda k, v: k == "./b")
ctx.compute()

print(ctx.result.value)
print(ctx.inst.ctx.step2_first.tf.status)
print(ctx.inst.ctx.step2_first.tf.exception)
"""
示例#28
0
    ctx.conflict = Cell("text")
    conflict.link(ctx.conflict)
    m.pins.conflict = {"io": "edit", "celltype": "text"}
    m.conflict = ctx.conflict

    ctx.merged = Cell("text")
    merged.connect_from(ctx.merged)
    m.pins.merged = {"io": "output", "celltype": "text"}
    ctx.merged = m.merged

    ctx.state = Cell("text")
    state.connect_from(ctx.state)
    m.pins.state = {"io": "output", "celltype": "text"}
    ctx.state = m.state

ctx.constructor_code = Cell("code").set(constructor)
constructor_params = {
    "fallback_mode": {
        "type": "value",
        "default": "modified"
    },
    "upstream": {
        "type": "cell",
        "celltype": "text",
        "io": "input"
    },
    "modified": {
        "type": "cell",
        "celltype": "text",
        "io": "edit"
    },
示例#29
0
ctx2.graph.share()
ctx2.graph_rt = {}
ctx2.graph_rt.celltype = "plain"
ctx2.status_ = {}
ctx2.status_data = ctx2.status_
ctx2.status_data.celltype = "plain"

gvs = ctx2.gen_vis_status = Transformer()
gvs.graph = ctx2.graph_rt
gvs.status_ = ctx2.status_
gvs.code.mount("gen_vis_status.py", authority="file")
ctx2.vis_status = ctx2.gen_vis_status
ctx2.vis_status.celltype = "plain"
ctx2.vis_status.share(readonly=True)

c = ctx2.html = Cell()
c.set(open("status-visualization.html").read())
c.celltype = "text"
c.mimetype = "text/html"
c.share(path="index.html")

import seamless, os
seamless_dir = os.path.dirname(seamless.__file__)
c = ctx2.seamless_client_js = Cell()
c.celltype = "text"
c.set(open(seamless_dir + "/js/seamless-client.js").read())
c.mimetype = "text/javascript"
c.share(path="seamless-client.js")

c = ctx2.status_visualization_js = Cell()
c.celltype = "text"
示例#30
0
import seamless
from seamless.highlevel import load_graph, Cell
import os, sys

initial_graphfile = sys.argv[1]
initial_zipfile = sys.argv[2]
output_graphfile = sys.argv[3]
output_zipfile = sys.argv[4]
ctx = load_graph(initial_graphfile, zip=initial_zipfile)

ctx.html = Cell("text").mount("index.html",
                              authority="file").share("index.html")
ctx.html.mimetype = "html"
ctx.js = Cell("text").mount("index.js", authority="file").share("index.js")
ctx.js.mimetype = "js"

seamless_dir = os.path.dirname(seamless.__file__)
seamless_client = open(seamless_dir + "/js/seamless-client.js").read()

ctx.seamless_js = Cell("text").set(seamless_client).share("seamless-client.js")
ctx.seamless_js.mimetype = "js"

ctx.compute()
ctx.save_graph(output_graphfile)
ctx.save_zip(output_zipfile)