コード例 #1
0
ファイル: test_main.py プロジェクト: lukasheinrich/adage
def test_simpleexample():
    x = rl()
    @x.when
    def _(adageobj):
        return True

    @x.do
    def _(adageobj):
        dep = adageobj.dag.addTask(task.s(one = 'what'), nodename = 'first')
        newrule = rl()
        adageobj.rules.append(newrule)
        @newrule.when
        def _(adageobj):
            upstream =  adageobj.dag.getNodeByName('first')
            return upstream.state == adage.nodestate.SUCCESS

        @newrule.do
        def _(adageobj):
            deptwo = adageobj.dag.addTask(task.s(one = 'ok...'), depends_on = [dep], nodename = 'what')
            newrule = rl()
            adageobj.rules.append(newrule)
            @newrule.when
            def _(adageobj):
                return True

            @newrule.do
            def _(adageobj):
                adageobj.dag.addTask(task.s(one = 'nested new'), nodename = 'the')
    adageobj = adage.adageobject()
    adageobj.rules.append(x)
    adage.serialize.obj_to_json(adageobj, lambda r: None, lambda n: None)
    adage.rundag(adageobj, default_trackers = True)

    data = adage.serialize.obj_to_json(adageobj,lambda r: None, lambda n: adage.serialize.node_to_json(n,lambda t: {}, lambda p: {}))
    adage.serialize.dag_from_json(data['dag'], lambda n: adage.node.Node(n['name'],n['task'],n['id']))
コード例 #2
0
ファイル: ifelse.py プロジェクト: lukasheinrich/adage
def main():
    adageobj = adage.adageobject()

    prepare_node    = adageobj.dag.addTask(boolean_task.s(), nodename = 'bool')
    adageobj.rules = [ Rule(node_done.s(nodename = 'bool'), schedule_if_else.s(depnode = 'bool')) ]

    adage.rundag(adageobj, default_trackers = True, trackevery = 5)
コード例 #3
0
ファイル: ifelse.py プロジェクト: zhengge2017/adage
def main():
    adageobj = adage.adageobject()

    prepare_node = adageobj.dag.addTask(boolean_task.s(), nodename='bool')
    adageobj.rules = [
        Rule(node_done.s(nodename='bool'), schedule_if_else.s(depnode='bool'))
    ]

    adage.rundag(adageobj, default_trackers=True, trackevery=5)
コード例 #4
0
ファイル: physicsexample.py プロジェクト: zhengge2017/adage
def build_initial_dag():
    adageobj = adage.adageobject()

    prepare_node    = adageobj.dag.addTask(prepare.s(workdir = 'here'), nodename = 'prepare')
    adageobj.dag.addTask(download.s(workdir = 'here'), depends_on = [prepare_node], nodename = 'download')

    #possible syntax that could be nice using partial function execution
    #    download_node = do(download.s(workdir = 'here'), depends_on = [prepare_node], nodename = 'download')

    adageobj.rules = [ Rule(node_done.s(nodename = 'download'), schedule_pythia.s()) ]
    return adageobj
コード例 #5
0
ファイル: latemerge.py プロジェクト: gfmartins/adage
def main():
    adageobj = adage.adageobject()
    
    fix0 = adageobj.dag.addTask(pdfproducer.s(name = 'fixed'), nodename = 'fixed')
    var1 = adageobj.dag.addTask(variableoutput.s(), nodename = 'variable1')
    var2 = adageobj.dag.addTask(variableoutput.s(), nodename = 'variable2')

    varnodes = [var1,var2]

    adageobj.rules += [
        Rule(variable_nodes_done.s(varnodes),schedule_pdf.s([fix0],varnodes))
    ]

    adage.rundag(adageobj,default_trackers = True, workdir = 'bla')
コード例 #6
0
ファイル: simple.py プロジェクト: lukasheinrich/adage
def main():
    backend = adage.backends.MultiProcBackend(2)

    adageobj = adage.adageobject()
    
    adageobj.rules = [Rule(always.s(),addnode.s(name = 'what')),Rule(byname.s(name = 'what'),addnode.s(name = 'the'))]

    # one = adageobj.dag.addTask(mytask.s(5), nodename = 'first')
    # two = adageobj.dag.addTask(mytask.s(3), depends_on = [one], nodename = 'second')
    #
    # adageobj.rules = [Rule(predicate.s(depnode = two),rulebody.s(depnode = two))]

    try:
        adage.rundag(adageobj, backend = backend, default_trackers = True, workdir = 'simpleTrack', update_interval = 10, trackevery = 10)
    except RuntimeError:
        log.error('ERROR')
コード例 #7
0
def test_simpleexample():
    x = rl()

    @x.when
    def _(adageobj):
        return True

    @x.do
    def _(adageobj):
        dep = adageobj.dag.addTask(task.s(one='what'), nodename='first')
        newrule = rl()
        adageobj.rules.append(newrule)

        @newrule.when
        def _(adageobj):
            upstream = adageobj.dag.getNodeByName('first')
            return upstream.state == adage.nodestate.SUCCESS

        @newrule.do
        def _(adageobj):
            deptwo = adageobj.dag.addTask(task.s(one='ok...'),
                                          depends_on=[dep],
                                          nodename='what')
            newrule = rl()
            adageobj.rules.append(newrule)

            @newrule.when
            def _(adageobj):
                return True

            @newrule.do
            def _(adageobj):
                adageobj.dag.addTask(task.s(one='nested new'), nodename='the')

    adageobj = adage.adageobject()
    adageobj.rules.append(x)
    adage.serialize.obj_to_json(adageobj)
    adage.rundag(adageobj, default_trackers=True)

    data = adage.serialize.obj_to_json(adageobj)
    adage.serialize.dag_from_json(
        data['dag'], lambda n: adage.node.Node(n['name'], n['task'], n['id']),
        lambda p: None, None)
コード例 #8
0
def main():
    dag = random_dag(2,1)

    adageobj = adage.adageobject()
    numbered = {}
    for node in dag.nodes():
        numbered[node] = adageobj.dag.addTask(hello.s(workdir = 'workdir_{}'.format(node)), nodename = 'demo_node_{}'.format(node))
    for i,node in enumerate(dag.nodes()):
        print 'pre for: {} are: {}'.format(node,dag.predecessors(node))
        for parent in dag.predecessors(node):
            adageobj.dag.addEdge(numbered[parent],numbered[node])
    

    rules = []
    rules += [ 
                Rule(nodes_present.s([1]), schedule_after_these.s([1],note = 'depends on one')),
                Rule(nodes_present.s([4,1]), schedule_after_these.s([4,1],note = 'depends on two'))
             ]

    adageobj.rules = rules
    adage.rundag(adageobj, default_trackers = True, workdir = 'workdirtrack', trackevery = 4)
コード例 #9
0
def main():
    dag = random_dag(5,3)

    adageobj = adage.adageobject()
    numbered = {}
    for node in dag.nodes():
        numbered[node] = adageobj.dag.addTask(hello.s(workdir = 'workdir_{}'.format(node)), nodename = 'demo_node_{}'.format(node))
    for i,node in enumerate(dag.nodes()):
        print 'pre for: {} are: {}'.format(node,dag.predecessors(node))
        for parent in dag.predecessors(node):
            adageobj.dag.addEdge(numbered[parent],numbered[node])


    rules = []
    rules += [
                Rule(nodes_present.s([1]), schedule_after_these.s([1],note = 'depends on one', tag = 'dyn1')),
                Rule(nodes_present.s([4,'dynamic_dyn1']), schedule_after_these.s([4,'dynamic_dyn1'],note = 'depends on two', tag = 'dyn2'))
             ]

    from adage.backends import IPythonParallelBackend
    from ipyparallel import Client
    backend = IPythonParallelBackend(Client(), resolve_like_partial = True)
    adageobj.rules = rules
    adage.rundag(adageobj, backend = backend, default_trackers = True, workdir = 'workdirtrack', trackevery = 4)
コード例 #10
0
ファイル: test_main.py プロジェクト: lukasheinrich/adage
def test_trivial():
    adageobj = adage.adageobject()
    adage.rundag(adageobj, default_trackers = False)
コード例 #11
0
def test_trivial():
    adageobj = adage.adageobject()
    adage.rundag(adageobj, default_trackers=False)
コード例 #12
0
@x.do
def _(adageobj):
    dep = adageobj.dag.addTask(task.s(one = 'what'), nodename = 'first')
    newrule = rl()
    adageobj.rules.append(newrule)
    @newrule.when
    def _(adageobj):
        upstream =  adageobj.dag.getNodeByName('first')
        return upstream.state == adage.nodestate.SUCCESS

    @newrule.do
    def _(adageobj):
        deptwo = adageobj.dag.addTask(task.s(one = 'ok...'), depends_on = [dep], nodename = 'what')
        newrule = rl()
        adageobj.rules.append(newrule)
        @newrule.when
        def _(adageobj):
            return True

        @newrule.do
        def _(adageobj):
            adageobj.dag.addTask(task.s(one = 'nested new'), nodename = 'the')

adageobj = adage.adageobject()
adageobj.rules.append(x)


logging.basicConfig(level = logging.INFO)
adage.rundag(adageobj, default_trackers = True)
コード例 #13
0
ファイル: callback.py プロジェクト: lukasheinrich/adage
import adage
import logging
import time
logging.basicConfig()

@adage.adagetask
def hello(one, two):
    print 'calling a task with ', one, two
    time.sleep(1)
    return 'a return value'


workflow = adage.adageobject()
initial = workflow.dag.addTask(hello.s(one = 'hello', two = 'there'))
another = workflow.dag.addTask(hello.s(one = 'one', two = 'two'))

@adage.decorators.callbackrule(after = {'init': initial.identifier, 'another': another.identifier})
def schedule(depnodes, adageobj):
    results = {k:v.result for k,v in depnodes.items()}
    parts = results['init'].split()
    for i,p in enumerate(parts):
        adageobj.dag.addTask(hello.s(one = 'part {}'.format(i), two = p), nodename = p, depends_on = depnodes.values())

workflow.rules = [schedule]
adage.rundag(workflow, default_trackers = True, workdir = 'callback')
コード例 #14
0
import adage
import logging
import time
logging.basicConfig()


@adage.adagetask
def hello(one, two):
    print 'calling a task with ', one, two
    time.sleep(1)
    return 'a return value'


workflow = adage.adageobject()
initial = workflow.dag.addTask(hello.s(one='hello', two='there'))
another = workflow.dag.addTask(hello.s(one='one', two='two'))


@adage.decorators.callbackrule(after={
    'init': initial.identifier,
    'another': another.identifier
})
def schedule(depnodes, adageobj):
    results = {k: v.result for k, v in depnodes.items()}
    parts = results['init'].split()
    for i, p in enumerate(parts):
        adageobj.dag.addTask(hello.s(one='part {}'.format(i), two=p),
                             nodename=p,
                             depends_on=depnodes.values())