示例#1
0
def get_dataflow():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")
    pid42 = df.add_out_port(vid4, "out")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)

    df.set_actor(vid1, FuncNode({}, {}, int))
    df.set_actor(vid2, FuncNode({}, {}, fixed_function))
    df.set_actor(vid3, FuncNode({}, {}, operator.add))
    df.set_actor(vid4, FuncNode({}, {}, print))

    return df, (pid10, pid42)
def test_dataflow_state_is_ready_for_evaluation():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)

    dfs = DataflowState(df)

    assert not dfs.is_ready_for_evaluation()

    dfs.set_data(pid10, 0)

    assert dfs.is_ready_for_evaluation()

    dfs.clear()
    for i, pid in enumerate([pid11, pid21, pid33]):
        dfs.set_data(pid, i)
        assert not dfs.is_ready_for_evaluation()
示例#3
0
def test_dataflow_state_is_ready_for_evaluation():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)

    dfs = DataflowState(df)

    assert not dfs.is_ready_for_evaluation()

    dfs.set_data(pid10, 0)

    assert dfs.is_ready_for_evaluation()

    dfs.clear()
    for i, pid in enumerate([pid11, pid21, pid33]):
        dfs.set_data(pid, i)
        assert not dfs.is_ready_for_evaluation()
def test_dataflow_state_reinit():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)

    dfs = DataflowState(df)

    dfs.set_data(pid10, 0)

    for i, pid in enumerate([pid11, pid21, pid33]):
        dfs.set_data(pid, i)

    dfs.reinit()
    assert dfs.is_ready_for_evaluation()
    for pid in (pid11, pid21, pid33):
        raises(KeyError, lambda: dfs.get_data(pid))
示例#5
0
def test_dataflow_state_reinit():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)

    dfs = DataflowState(df)

    dfs.set_data(pid10, 0)

    for i, pid in enumerate([pid11, pid21, pid33]):
        dfs.set_data(pid, i)

    dfs.reinit()
    assert dfs.is_ready_for_evaluation()
    for pid in (pid11, pid21, pid33):
        assert_raises(KeyError, lambda: dfs.get_data(pid))
def get_dataflow():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")
    pid42 = df.add_out_port(vid4, "out")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)

    df.set_actor(vid1, FuncNode({}, {}, int))
    df.set_actor(vid2, FuncNode({}, {}, fixed_function))
    df.set_actor(vid3, FuncNode({}, {}, operator.add))
    df.set_actor(vid4, FuncNode({}, {}, print_func))

    return df, (pid10, pid42)
def test_dataflow_state_get_data():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")
    vid5 = df.add_vertex()
    pid51 = df.add_out_port(vid5, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)
    df.connect(pid51, pid32)

    dfs = DataflowState(df)

    for pid in df.ports():
        raises(KeyError, lambda: dfs.get_data(pid))

    for i, pid in enumerate([pid11, pid21, pid33, pid51]):
        dfs.set_data(pid, i)

    raises(KeyError, lambda: dfs.get_data(pid10))

    dfs.set_data(pid10, 'a')
    assert dfs.get_data(pid10) == 'a'

    for i, pid in enumerate([pid11, pid21, pid33, pid51]):
        assert dfs.get_data(pid) == i

    assert dfs.get_data(pid31) == 0
    assert tuple(dfs.get_data(pid32)) == (1, 3)
    assert dfs.get_data(pid41) == 2

    n2 = Node()
    df.set_actor(vid2, n2)

    assert tuple(dfs.get_data(pid32)) == (1, 3)

    n5 = Node()
    df.set_actor(vid5, n5)
    assert tuple(dfs.get_data(pid32)) == (1, 3)

    n2.get_ad_hoc_dict().set_metadata('position', [10, 0])
    n5.get_ad_hoc_dict().set_metadata('position', [0, 0])
    assert tuple(dfs.get_data(pid32)) == (3, 1)
示例#8
0
def test_dataflow_state_get_data():
    df = DataFlow()
    vid1 = df.add_vertex()
    pid10 = df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")
    vid5 = df.add_vertex()
    pid51 = df.add_out_port(vid5, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)
    df.connect(pid51, pid32)

    dfs = DataflowState(df)

    for pid in df.ports():
        assert_raises(KeyError, lambda: dfs.get_data(pid))

    for i, pid in enumerate([pid11, pid21, pid33, pid51]):
        dfs.set_data(pid, i)

    assert_raises(KeyError, lambda: dfs.get_data(pid10))

    dfs.set_data(pid10, 'a')
    assert dfs.get_data(pid10) == 'a'

    for i, pid in enumerate([pid11, pid21, pid33, pid51]):
        assert dfs.get_data(pid) == i

    assert dfs.get_data(pid31) == 0
    assert tuple(dfs.get_data(pid32)) == (1, 3)
    assert dfs.get_data(pid41) == 2

    n2 = Node()
    df.set_actor(vid2, n2)

    assert tuple(dfs.get_data(pid32)) == (1, 3)

    n5 = Node()
    df.set_actor(vid5, n5)
    assert tuple(dfs.get_data(pid32)) == (1, 3)

    n2.get_ad_hoc_dict().set_metadata('position', [10, 0])
    n5.get_ad_hoc_dict().set_metadata('position', [0, 0])
    assert tuple(dfs.get_data(pid32)) == (3, 1)
示例#9
0
def test_dataflow():
    """ test dataflow"""
    df=DataFlow()
    vid1=df.add_vertex()
    pid11=df.add_out_port(vid1, "out")
    vid2=df.add_vertex()
    pid21=df.add_out_port(vid2, "out")

    vid3=df.add_vertex()
    pid31=df.add_in_port(vid3, "in1")
    pid32=df.add_in_port(vid3, "in2")
    pid33=df.add_out_port(vid3, "res")

    vid4=df.add_vertex()
    pid41=df.add_in_port(vid4, "in")

    eid1=df.connect(pid11, pid31)
    eid2=df.connect(pid21, pid32)
    eid3=df.connect(pid33, pid41)

    assert df.source_port(eid1)==pid11
    assert df.target_port(eid2)==pid32
    assert set(df.out_ports(vid1))==set((pid11, ))
    assert set(df.in_ports(vid3))==set((pid31, pid32))
    assert set(df.ports(vid3))==set((pid31, pid32, pid33))
    assert df.is_in_port(pid31)
    assert df.is_out_port(pid11)
    assert df.vertex(pid11)==vid1
    assert set(df.connected_ports(pid11))==set((pid31, ))
    assert set(df.connected_edges(pid21))==set((eid2, ))
    assert df.out_port(vid1, "out")==pid11
    assert df.in_port(vid3, "in1")==pid31

    test=False
    try:
        dummy=df.connect(pid11, pid33)
    except PortError:
        test=True
    assert test


    df.remove_port(pid33)
    assert set(df.connected_ports(pid41))==set()
    assert set(df.out_edges(vid3))==set()
    test=False
    try:
        dummy=df.port(pid33)
    except PortError:
        test=True
    assert test
示例#10
0
def test_dataflow():
    """ test dataflow"""
    df = DataFlow()
    vid1 = df.add_vertex()
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")

    eid1 = df.connect(pid11, pid31)
    eid2 = df.connect(pid21, pid32)
    eid3 = df.connect(pid33, pid41)

    assert df.source_port(eid1) == pid11
    assert df.target_port(eid2) == pid32
    assert set(df.out_ports(vid1)) == set((pid11, ))
    assert set(df.in_ports(vid3)) == set((pid31, pid32))
    assert set(df.ports(vid3)) == set((pid31, pid32, pid33))
    assert df.is_in_port(pid31)
    assert df.is_out_port(pid11)
    assert df.vertex(pid11) == vid1
    assert set(df.connected_ports(pid11)) == set((pid31, ))
    assert set(df.connected_edges(pid21)) == set((eid2, ))
    assert df.out_port(vid1, "out") == pid11
    assert df.in_port(vid3, "in1") == pid31

    test = False
    try:
        dummy = df.connect(pid11, pid33)
    except PortError:
        test = True
    assert test

    df.remove_port(pid33)
    assert set(df.connected_ports(pid41)) == set()
    assert set(df.out_edges(vid3)) == set()
    test = False
    try:
        dummy = df.port(pid33)
    except PortError:
        test = True
    assert test
示例#11
0
    def connect(self, src_id, port_src, dst_id, port_dst):
        """ Connect 2 elements

        :param src_id: source node id
        :param port_src: source output port number
        :param dst_id: destination node id
        :param port_dst: destination input port number
        """

        try:
            source_pid = self.out_port(src_id, port_src)
            target_pid = self.in_port(dst_id, port_dst)
            eid = DataFlow.connect(self, source_pid, target_pid)
        except:
            logger.error("Enable to create the edge %s %d %d %d %d"%( self.factory.name,  src_id, port_src, dst_id, port_dst))
            return

        self.actor(dst_id).set_input_state(port_dst, "connected")
        self.notify_listeners(("connection_modified", ))
        self.graph_modified = True

        self.update_eval_listeners(src_id)
        nodeSrc = self.node(src_id)
        nodeDst = self.node(dst_id)
        src_port = nodeSrc.output_desc[port_src]
        dst_port = nodeDst.input_desc[port_dst]

        edgedata = "default", eid, src_port, dst_port
        #connected ports cannot be hidden:
        #nodeSrc.set_port_hidden(port_src, False)
        nodeDst.set_port_hidden(port_dst, False)
        self.notify_listeners(("edge_added", edgedata))
示例#12
0
    def connect(self, src_id, port_src, dst_id, port_dst):
        """ Connect 2 elements

        :param src_id: source node id
        :param port_src: source output port number
        :param dst_id: destination node id
        :param port_dst: destination input port number
        """

        try:
            source_pid = self.out_port(src_id, port_src)
            target_pid = self.in_port(dst_id, port_dst)
            eid = DataFlow.connect(self, source_pid, target_pid)
        except:
            logger.error(
                "Enable to create the edge %s %d %d %d %d" %
                (self.factory.name, src_id, port_src, dst_id, port_dst))
            return

        self.actor(dst_id).set_input_state(port_dst, "connected")
        self.notify_listeners(("connection_modified", ))
        self.graph_modified = True

        self.update_eval_listeners(src_id)
        nodeSrc = self.node(src_id)
        nodeDst = self.node(dst_id)
        src_port = nodeSrc.output_desc[port_src]
        dst_port = nodeDst.input_desc[port_dst]

        edgedata = "default", eid, src_port, dst_port
        #connected ports cannot be hidden:
        #nodeSrc.set_port_hidden(port_src, False)
        nodeDst.set_port_hidden(port_dst, False)
        self.notify_listeners(("edge_added", edgedata))
def test_dataflow_state_init():
    df = DataFlow()
    vid1 = df.add_vertex()
    df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)

    dfs = DataflowState(df)
    dfs.clear()

    assert len(dfs._state) == 0
示例#14
0
def test_dataflow_state_init():
    df = DataFlow()
    vid1 = df.add_vertex()
    df.add_in_port(vid1, "in")
    pid11 = df.add_out_port(vid1, "out")
    vid2 = df.add_vertex()
    pid21 = df.add_out_port(vid2, "out")

    vid3 = df.add_vertex()
    pid31 = df.add_in_port(vid3, "in1")
    pid32 = df.add_in_port(vid3, "in2")
    pid33 = df.add_out_port(vid3, "res")

    vid4 = df.add_vertex()
    pid41 = df.add_in_port(vid4, "in")

    df.connect(pid11, pid31)
    df.connect(pid21, pid32)
    df.connect(pid33, pid41)

    dfs = DataflowState(df)
    dfs.clear()

    assert len(dfs._state) == 0