當前位置: 首頁>>代碼示例>>Python>>正文


Python PortGraph.add_actor方法代碼示例

本文整理匯總了Python中openalea.workflow.port_graph.PortGraph.add_actor方法的典型用法代碼示例。如果您正苦於以下問題:Python PortGraph.add_actor方法的具體用法?Python PortGraph.add_actor怎麽用?Python PortGraph.add_actor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在openalea.workflow.port_graph.PortGraph的用法示例。


在下文中一共展示了PortGraph.add_actor方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_evaluation_propagated_upstream

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import add_actor [as 別名]
def test_evaluation_propagated_upstream():
    visited = []

    def func(txt):
        visited.append(txt)
        return txt

    pg = PortGraph()
    n = FuncNode(func)
    pg.add_actor(n, 0)
    pg.add_actor(n, 1)
    pg.connect(pg.out_port(0, 'txt'), pg.in_port(1, 'txt'))

    algo = BruteEvaluation(pg)

    ws = WorkflowState(pg)
    env = EvaluationEnvironment()
    ws.store_param(pg.in_port(0, 'txt'), "txt", 0)

    algo.eval(env, ws, 0)
    assert len(visited) == 1
    algo.eval(env, ws, 1)
    assert len(visited) == 2

    env.new_execution()
    algo.eval(env, ws, 1)
    assert len(visited) == 4
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:29,代碼來源:test_evaluation.py

示例2: test_portgraph_add_actor

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import add_actor [as 別名]
def test_portgraph_add_actor():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    actor = Node()
    keys = {"toto", 1, "titi"}
    for key in keys:
        actor.add_input(key, "descr")
        actor.add_output(key, "descr")

    # bad actor
    assert_raises(AttributeError, lambda: pg.add_actor(None))
    assert len(pg) == 1
    assert_raises(AttributeError, lambda: pg.add_actor(None, vid1 + 1))
    assert len(pg) == 1
    # vertex id already used
    assert_raises(InvalidVertex, lambda: pg.add_actor(actor, vid1))
    assert len(pg) == 1

    for key in actor.inputs():
        pg.add_in_port(vid1, key)

    for key in actor.outputs():
        pg.add_out_port(vid1, key)

    pg.set_actor(vid1, actor)
    # vertex id already used
    assert_raises(InvalidVertex, lambda: pg.add_actor(actor, vid1))
    assert len(pg) == 1

    vid2 = pg.add_actor(actor)
    assert pg.actor(vid2) == actor
    assert set(actor.inputs()) == keys
    assert set(pg.local_id(pid) for pid in pg.in_ports(vid2)) == keys
    assert set(actor.outputs()) == keys
    assert set(pg.local_id(pid) for pid in pg.out_ports(vid2)) == keys
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:37,代碼來源:test_port_graph.py

示例3: test_evaluation_do_not_reevaluate_same_node

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import add_actor [as 別名]
def test_evaluation_do_not_reevaluate_same_node():
    visited = []

    def func():
        visited.append("yes")

    pg = PortGraph()
    n = FuncNode(func)
    pg.add_actor(n, 0)
    pg.add_actor(n, 1)

    env = EvaluationEnvironment()
    algo = BruteEvaluation(pg)

    ws = WorkflowState(pg)
    algo.eval(env, ws, 0)
    assert len(visited) == 1

    algo.eval(env, ws, 1)
    assert len(visited) == 2

    algo.eval(env, ws, 0)
    assert len(visited) == 2

    env.new_execution()
    algo.eval(env, ws, 0)
    assert len(visited) == 3
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:29,代碼來源:test_evaluation.py

示例4: test_evaluation_needs_ready_to_evaluate_state

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import add_actor [as 別名]
def test_evaluation_needs_ready_to_evaluate_state():
    def func(a, b):
        c = a + b
        return c

    pg = PortGraph()
    n = FuncNode(func)
    pg.add_actor(n, 0)

    algo = BruteEvaluation(pg)

    ws = WorkflowState(pg)
    assert_raises(EvaluationError, lambda: algo.eval(None, ws))
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:15,代碼來源:test_evaluation.py

示例5: test_evaluation_eval_all_nodes

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import add_actor [as 別名]
def test_evaluation_eval_all_nodes():
    visited = []

    def func():
        visited.append("yes")

    pg = PortGraph()
    n = FuncNode(func)
    pg.add_actor(n, 0)
    pg.add_actor(n, 1)

    algo = BruteEvaluation(pg)

    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    algo.eval(env, ws)

    assert len(visited) == 2
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:20,代碼來源:test_evaluation.py

示例6: test_evaluation_clear

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import add_actor [as 別名]
def test_evaluation_clear():
    def func():
        pass

    pg = PortGraph()
    n = FuncNode(func)
    pg.add_actor(n, 0)
    pg.add_actor(n, 1)

    algo = BruteEvaluation(pg)

    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    algo.eval(env, ws)

    assert not algo.requires_evaluation(env, ws)

    ws.clear()

    assert algo.requires_evaluation(env, ws)
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:22,代碼來源:test_evaluation.py

示例7: test_lazy_evaluate_at_least_once_each_node

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import add_actor [as 別名]
def test_lazy_evaluate_at_least_once_each_node():
    evaluated = []

    def func():
        evaluated.append('bla')

    pg = PortGraph()
    vid = pg.add_actor(FuncNode(func))
    assert pg.actor(vid).is_lazy()

    algo = LazyEvaluation(pg)
    env = EvaluationEnvironment()
    ws = WorkflowState(pg)

    algo.eval(env, ws)
    assert len(evaluated) == 1
    algo.eval(env, ws)
    assert len(evaluated) == 1
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:20,代碼來源:test_evaluation.py

示例8: test_lazy_do_not_reevaluate_node_if_same_execution

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import add_actor [as 別名]
def test_lazy_do_not_reevaluate_node_if_same_execution():
    evaluated = []

    def func(txt):
        evaluated.append(txt)
        return txt

    pg = PortGraph()
    vid = pg.add_actor(FuncNode(func))
    assert pg.actor(vid).is_lazy()

    algo = LazyEvaluation(pg)
    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    ws.store_param(pg.in_port(vid, 'txt'), 'toto', env.current_execution())

    algo.eval(env, ws)
    assert len(evaluated) == 1

    algo.eval_node(env, ws, vid)
    assert len(evaluated) == 1
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:23,代碼來源:test_evaluation.py

示例9: test_lazy_always_reevaluate_non_lazy_nodes

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import add_actor [as 別名]
def test_lazy_always_reevaluate_non_lazy_nodes():
    evaluated = []

    def func(txt):
        evaluated.append(txt)
        return txt

    pg = PortGraph()
    vid = pg.add_actor(FuncNode(func))
    pg.actor(vid).set_lazy(False)

    algo = LazyEvaluation(pg)
    env = EvaluationEnvironment()
    ws = WorkflowState(pg)
    ws.store_param(pg.in_port(vid, 'txt'), 'toto', env.current_execution())

    algo.eval(env, ws)
    assert len(evaluated) == 1

    env.new_execution()
    algo.eval(env, ws)
    assert len(evaluated) == 2
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:24,代碼來源:test_evaluation.py


注:本文中的openalea.workflow.port_graph.PortGraph.add_actor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。