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


Python PortGraph.connect方法代碼示例

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


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

示例1: test_portgraph_connected_edges

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_portgraph_connected_edges():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()
    vid3 = pg.add_vertex()

    assert_raises(InvalidPort, lambda: tuple(pg.connected_edges(0)))

    pid1 = pg.add_in_port(vid1, 0)
    pid2 = pg.add_in_port(vid1, 1)
    pid3 = pg.add_out_port(vid2, 0)
    pid4 = pg.add_out_port(vid3, 0)

    # test vertices and ports are created without connections
    for pid in (pid1, pid2, pid3, pid4):
        assert len(tuple(pg.connected_edges(pid))) == 0

    eid1 = pg.connect(pid3, pid1)
    assert tuple(pg.connected_edges(pid3)) == (eid1,)
    assert tuple(pg.connected_edges(pid1)) == (eid1,)
    for pid in (pid2, pid4):
        assert len(tuple(pg.connected_edges(pid))) == 0

    eid2 = pg.connect(pid4, pid1)
    assert tuple(pg.connected_edges(pid3)) == (eid1,)
    assert tuple(pg.connected_edges(pid4)) == (eid2,)
    assert sorted(pg.connected_edges(pid1)) == sorted((eid1, eid2))
    assert len(tuple(pg.connected_edges(pid2))) == 0

    eid3 = pg.connect(pid4, pid2)
    assert tuple(pg.connected_edges(pid3)) == (eid1,)
    assert sorted(pg.connected_edges(pid4)) == sorted((eid2, eid3))
    assert sorted(pg.connected_edges(pid1)) == sorted((eid1, eid2))
    assert tuple(pg.connected_edges(pid2)) == (eid3,)
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:36,代碼來源:test_port_graph.py

示例2: test_ws_retrieve_data_on_input_ports

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_ws_retrieve_data_on_input_ports():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)
    pg.add_vertex(1)
    pg.add_in_port(1, "in", 1)

    # non existing port
    ws = WorkflowState(pg)
    assert_raises(KeyError, lambda: ws.get(10))

    # lonely input port without data
    ws = WorkflowState(pg)
    assert_raises(KeyError, lambda: ws.get(1))

    # lonely input port with data
    ws.store_param(1, "param", 0)
    assert ws.get(1) == "param"

    # connected input port
    pg.connect(0, 1)
    ws = WorkflowState(pg)

    ws.store(0, "data")
    assert ws.get(1) == "data"
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:27,代碼來源:test_state.py

示例3: test_evaluation_propagated_upstream

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [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

示例4: test_ws_store_param_only_on_lonely_input_ports

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_ws_store_param_only_on_lonely_input_ports():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_in_port(0, "in", 0)
    pg.add_out_port(0, "out", 1)
    pg.add_vertex(1)
    pg.add_in_port(1, "in", 2)
    pg.connect(1, 2)

    ws = WorkflowState(pg)

    assert_raises(UserWarning, lambda: ws.store_param(1, "param", 0))
    assert_raises(UserWarning, lambda: ws.store_param(2, "param", 0))
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:15,代碼來源:test_state.py

示例5: test_ws_sub_ready_for_evaluation_if_no_input_port

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_ws_sub_ready_for_evaluation_if_no_input_port():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)
    pg.add_vertex(1)
    pg.add_in_port(1, "in", 1)
    pg.connect(0, 1)

    ws = WorkflowState(pg)
    assert ws.is_ready_for_evaluation()

    subpg = get_upstream_subportgraph(pg, 1)
    subws = WorkflowState(subpg)
    assert subws.is_ready_for_evaluation()
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:16,代碼來源:test_state.py

示例6: test_portgraph_clear

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_portgraph_clear():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()

    pid1 = pg.add_in_port(vid1, "in")
    pid2 = pg.add_out_port(vid2, "out")

    pg.connect(pid2, pid1)

    pg.clear()

    assert pg.nb_vertices() == 0
    assert pg.nb_edges() == 0
    assert len(tuple(pg.ports())) == 0
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:17,代碼來源:test_port_graph.py

示例7: test_ws_retrieve_data_on_multiple_connections_input_ports

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_ws_retrieve_data_on_multiple_connections_input_ports():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)
    pg.add_vertex(1)
    pg.add_out_port(1, "out", 1)
    pg.add_vertex(2)
    pg.add_in_port(2, "in", 2)
    pg.connect(0, 2)
    pg.connect(1, 2)

    ws = WorkflowState(pg)
    assert_raises(KeyError, lambda: ws.get(2))
    ws.store(0, "data0")
    assert_raises(KeyError, lambda: ws.get(2))
    ws.store(1, "data1")
    assert tuple(ws.get(2)) == ("data0", "data1")
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:19,代碼來源:test_state.py

示例8: test_portgraph_remove_port

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_portgraph_remove_port():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()

    pid1 = pg.add_in_port(vid1, "in")
    pid2 = pg.add_out_port(vid2, "out")

    pg.connect(pid2, pid1)

    # raise error if global port id dos not exist
    assert_raises(InvalidPort, lambda: pg.remove_port(pid1 + pid2 + 1))

    pg.remove_port(pid1)
    assert len(tuple(pg.ports(vid1))) == 0
    assert tuple(pg.ports(vid2)) == (pid2,)
    assert pg.nb_connections(pid2) == 0
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:19,代碼來源:test_port_graph.py

示例9: test_portgraph_remove_vertex

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_portgraph_remove_vertex():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()

    pid1 = pg.add_in_port(vid1, "in")
    pid2 = pg.add_out_port(vid2, "out")

    pg.connect(pid2, pid1)

    assert_raises(InvalidVertex, lambda: pg.remove_vertex(vid1 + vid2 + 1))

    pg.remove_vertex(vid1)
    assert tuple(pg.ports()) == (pid2,)
    assert_raises(InvalidVertex, lambda: pg.ports(vid1).next())
    assert tuple(pg.ports(vid2)) == (pid2,)
    assert pg.nb_connections(pid2) == 0
    assert pg.nb_neighbors(vid2) == 0
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:20,代碼來源:test_port_graph.py

示例10: test_ws_is_ready_for_evaluation

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_ws_is_ready_for_evaluation():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_in_port(0, "in", 0)
    pg.add_out_port(0, "out", 1)
    pg.add_vertex(1)
    pg.add_out_port(1, "out", 2)
    pg.add_vertex(2)
    pg.add_in_port(2, "in", 3)
    pg.add_out_port(2, "out", 4)
    pg.connect(1, 3)
    pg.connect(2, 3)

    ws = WorkflowState(pg)
    assert not ws.is_ready_for_evaluation()

    ws.store(1, "data")
    assert not ws.is_ready_for_evaluation()

    ws.store_param(0, "param", 0)
    assert ws.is_ready_for_evaluation()
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:23,代碼來源:test_state.py

示例11: test_portgraph_connect

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_portgraph_connect():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()

    # invalid ports
    assert_raises(InvalidPort, lambda: pg.connect(0, 1))
    # invalid source port
    pid1 = pg.add_in_port(vid1, "in")
    assert_raises(InvalidPort, lambda: pg.connect(pid1 + 1, pid1))
    # invalid out port
    pid2 = pg.add_out_port(vid2, "out")
    assert_raises(InvalidPort, lambda: pg.connect(pid2, pid1 + pid2 + 1))
    # edge connection from in to out raise error
    assert_raises(InvalidPort, lambda: pg.connect(pid1, pid2))

    eid = pg.connect(pid2, pid1)
    assert pg.source_port(eid) == pid2
    assert pg.target_port(eid) == pid1
    assert tuple(pg.connected_edges(pid1)) == (eid,)
    assert tuple(pg.connected_edges(pid2)) == (eid,)
    assert pid1 in pg.connected_ports(pid2)
    assert pid2 in pg.connected_ports(pid1)

    # can not duplicate edge
    assert_raises(InvalidEdge, lambda: pg.connect(pid2, pid1, eid))
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:28,代碼來源:test_port_graph.py

示例12: portgraph_nb_connections

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def portgraph_nb_connections():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()
    vid3 = pg.add_vertex()

    assert_raises(InvalidPort, lambda: pg.nb_connections(0))

    pid1 = pg.add_in_port(vid1, 0)
    pid2 = pg.add_in_port(vid1, 1)
    pid3 = pg.add_out_port(vid2, 0)
    pid4 = pg.add_out_port(vid3, 0)

    for pid in (pid1, pid2, pid3, pid4):
        assert pg.nb_connections(pid) == 0

    pg.connect(pid3, pid1)
    assert pg.nb_connections(pid3) == 1
    assert pg.nb_connections(pid1) == 1
    assert pg.nb_connections(pid2) == 0
    assert pg.nb_connections(pid4) == 0

    pg.connect(pid4, pid1)
    assert pg.nb_connections(pid3) == 1
    assert pg.nb_connections(pid4) == 1
    assert pg.nb_connections(pid1) == 2
    assert pg.nb_connections(pid2) == 0

    pg.connect(pid4, pid2)
    assert pg.nb_connections(pid3) == 1
    assert pg.nb_connections(pid4) == 2
    assert pg.nb_connections(pid1) == 2
    assert pg.nb_connections(pid2) == 1
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:35,代碼來源:test_port_graph.py

示例13: test_portgraph_connected_ports

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_portgraph_connected_ports():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()
    vid3 = pg.add_vertex()

    assert_raises(InvalidPort, lambda: tuple(pg.connected_ports(0)))

    pid1 = pg.add_in_port(vid1, 0)
    pid2 = pg.add_in_port(vid1, 1)
    pid3 = pg.add_out_port(vid2, 0)
    pid4 = pg.add_out_port(vid3, 0)

    for pid in (pid1, pid2, pid3, pid4):
        assert len(tuple(pg.connected_ports(pid))) == 0

    pg.connect(pid3, pid1)
    assert tuple(pg.connected_ports(pid3)) == (pid1,)
    assert tuple(pg.connected_ports(pid1)) == (pid3,)
    for pid in (pid2, pid4):
        assert len(tuple(pg.connected_ports(pid))) == 0

    pg.connect(pid4, pid1)
    assert tuple(pg.connected_ports(pid3)) == (pid1,)
    assert tuple(pg.connected_ports(pid4)) == (pid1,)
    assert sorted(pg.connected_ports(pid1)) == sorted((pid3, pid4))
    assert len(tuple(pg.connected_ports(pid2))) == 0

    pg.connect(pid4, pid2)
    assert tuple(pg.connected_ports(pid3)) == (pid1,)
    assert sorted(pg.connected_ports(pid4)) == sorted((pid1, pid2))
    assert sorted(pg.connected_ports(pid1)) == sorted((pid3, pid4))
    assert tuple(pg.connected_ports(pid2)) == (pid4,)
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:35,代碼來源:test_port_graph.py

示例14: test_ws_when_connected_input_port

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_ws_when_connected_input_port():
    pg = PortGraph()
    pg.add_vertex(0)
    pg.add_out_port(0, "out", 0)
    pg.add_vertex(1)
    pg.add_out_port(1, "out", 1)
    pg.add_vertex(2)
    pg.add_in_port(2, "in", 2)
    pg.connect(0, 2)

    ws = WorkflowState(pg)
    assert ws.when(2) is None
    ws.set_last_evaluation(0, 10)
    assert ws.when(2) == 10

    pg.connect(1, 2)
    ws = WorkflowState(pg)
    assert ws.when(2) is None
    ws.set_last_evaluation(0, 10)
    assert ws.when(2) is None
    ws.set_last_evaluation(1, 11)
    assert ws.when(2) == 10
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:24,代碼來源:test_state.py

示例15: test_portgraph_edge_connected_to_ports

# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import connect [as 別名]
def test_portgraph_edge_connected_to_ports():
    pg = PortGraph()
    vid1 = pg.add_vertex()
    vid2 = pg.add_vertex()

    # method add_edge is forbidden
    assert_raises(UserWarning, lambda: pg.add_edge((vid1, vid2)))

    # connect to None port raises InvalidPort
    assert_raises(InvalidPort, lambda: pg.connect(None, None))
    pid1 = pg.add_out_port(vid1, "out")
    pid2 = pg.add_in_port(vid2, "in")
    assert_raises(InvalidPort, lambda: pg.connect(pid1, None))
    assert_raises(InvalidPort, lambda: pg.connect(None, pid2))

    # connect from in port to out port raises InvalidPort
    assert_raises(InvalidPort, lambda: pg.connect(pid2, pid1))

    # test connect is working
    eid = pg.connect(pid1, pid2)
    assert pg.source_port(eid) == pid1
    assert pg.target_port(eid) == pid2
開發者ID:revesansparole,項目名稱:oaworkflow,代碼行數:24,代碼來源:test_port_graph.py


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