本文整理匯總了Python中openalea.workflow.port_graph.PortGraph.set_actor方法的典型用法代碼示例。如果您正苦於以下問題:Python PortGraph.set_actor方法的具體用法?Python PortGraph.set_actor怎麽用?Python PortGraph.set_actor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類openalea.workflow.port_graph.PortGraph
的用法示例。
在下文中一共展示了PortGraph.set_actor方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_portgraph_add_actor
# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import set_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
示例2: test_portgraph_set_actor
# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import set_actor [as 別名]
def test_portgraph_set_actor():
pg = PortGraph()
assert_raises(InvalidVertex, lambda: pg.set_actor(0, None))
actor = Node()
for key in ("toto", 1, "titi"):
actor.add_input(key, "descr")
actor.add_output(key, "descr")
assert_raises(InvalidVertex, lambda: pg.set_actor(0, actor))
vid = pg.add_vertex()
pg.set_actor(vid, None)
assert pg.actor(vid) is None
assert_raises(InvalidPort, lambda: pg.set_actor(vid, actor))
for key in actor.inputs():
pg.add_in_port(vid, key)
assert_raises(InvalidPort, lambda: pg.set_actor(vid, actor))
for key in actor.outputs():
pg.add_out_port(vid, key)
pg.set_actor(vid, actor)
assert pg.actor(vid) == actor
pg.set_actor(vid, None)
assert pg.actor(vid) is None
示例3: test_portgraph_set_actor_port_order_not_important
# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import set_actor [as 別名]
def test_portgraph_set_actor_port_order_not_important():
pg = PortGraph()
actor = Node()
keys = ("toto", 1, "titi")
for key in keys:
actor.add_input(key, "descr")
actor.add_output(key, "descr")
vid = pg.add_vertex()
for k in reversed(keys):
pg.add_in_port(vid, k)
pg.add_out_port(vid, k)
pg.set_actor(vid, actor)
assert pg.actor(vid) == actor
示例4: test_evaluation_fail_if_port_mismatch_outputs
# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import set_actor [as 別名]
def test_evaluation_fail_if_port_mismatch_outputs():
def func():
return 1, 2
pg = PortGraph()
pg.add_vertex(0)
pg.add_out_port(0, 'res', 0)
n = RawFuncNode(func)
n.add_output('res', "descr")
pg.set_actor(0, n)
algo = BruteEvaluation(pg)
env = EvaluationEnvironment()
ws = WorkflowState(pg)
assert_raises(EvaluationError, lambda: algo.eval(env, ws))
示例5: test_evaluation_affect_output_to_right_ports
# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import set_actor [as 別名]
def test_evaluation_affect_output_to_right_ports():
def func(a, b):
c = a + b
d = a * 2
return c, d
# simple order
pg = PortGraph()
n = FuncNode(func)
pg.add_vertex(0)
pg.add_in_port(0, 'a', 0)
pg.add_in_port(0, 'b', 1)
pg.add_out_port(0, 'c', 2)
pg.add_out_port(0, 'd', 3)
pg.set_actor(0, n)
algo = BruteEvaluation(pg)
env = EvaluationEnvironment()
ws = WorkflowState(pg)
ws.store_param(0, 'a', 0)
ws.store_param(1, 'b', 0)
algo.eval(env, ws)
assert ws.get(2) == 'ab'
assert ws.get(3) == 'aa'
# reverse input orders
pg = PortGraph()
n = FuncNode(func)
pg.add_vertex(0)
pg.add_in_port(0, 'b', 0)
pg.add_in_port(0, 'a', 1)
pg.add_out_port(0, 'c', 2)
pg.add_out_port(0, 'd', 3)
pg.set_actor(0, n)
algo = BruteEvaluation(pg)
env = EvaluationEnvironment()
ws = WorkflowState(pg)
ws.store_param(0, 'a', 0)
ws.store_param(1, 'b', 0)
algo.eval(env, ws)
assert ws.get(2) == 'ba'
assert ws.get(3) == 'bb'
# reverse output order
pg = PortGraph()
n = FuncNode(func)
pg.add_vertex(0)
pg.add_in_port(0, 'a', 0)
pg.add_in_port(0, 'b', 1)
pg.add_out_port(0, 'd', 2)
pg.add_out_port(0, 'c', 3)
pg.set_actor(0, n)
algo = BruteEvaluation(pg)
env = EvaluationEnvironment()
ws = WorkflowState(pg)
ws.store_param(0, 'a', 0)
ws.store_param(1, 'b', 0)
algo.eval(env, ws)
assert ws.get(3) == 'ab'
assert ws.get(2) == 'aa'