Пример #1
0
def kg_bfs_iter(graph: KatanaGraph, source_node: NodeID,
                depth_limit: int) -> NumpyVectorType:
    '''
    .. py:function:: metagraph.algos.traversal.bfs_iter(graph, source_node, depth_limit)

    Use BFS to traverse a graph given a source node and BFS depth limit (implemented by a Katana Graph API)

    :param KatanaGraph graph: The origianl graph to traverse
    :param NodeID source_node: The starting node for BFS
    :param int depth: The BFS depth
    :return: the BFS traversal result in order
    :rtype: NumpyVectorType
    '''
    bfs_prop_name = "bfs_prop_start_from_" + str(source_node)
    depth_limit_internal = 2**30 - 1 if depth_limit == -1 else depth_limit  # return all the reachable nodes for the default value of depth_limit (-1)
    start_node = source_node
    if not has_node_prop(graph.value, bfs_prop_name):
        bfs(graph.value, start_node, bfs_prop_name)
    pg_bfs_list = graph.value.get_node_property(
        bfs_prop_name).to_pandas().values.tolist()
    new_list = [[i, pg_bfs_list[i]] for i in range(len(pg_bfs_list))
                if pg_bfs_list[i] < depth_limit_internal]
    sorted_list = sorted(new_list, key=lambda each: (each[1], each[0]))
    bfs_arr = np.array([each[0] for each in sorted_list])
    return bfs_arr
Пример #2
0
def test_assert_valid(graph: Graph):
    property_name = "NewProp"
    start_node = 0

    with raises(AssertionError):
        bfs_assert_valid(graph, start_node, "workFrom")

    bfs(graph, start_node, property_name)

    v = graph.get_node_property(property_name).to_numpy().copy()
    v[0] = 100
    graph.add_node_property(table({"Prop2": v}))

    with raises(AssertionError):
        bfs_assert_valid(graph, start_node, "Prop2")
Пример #3
0
def test_busy_wait(graph: Graph):
    set_busy_wait()
    property_name = "NewProp"
    start_node = 0

    bfs(graph, start_node, property_name)

    node_schema: Schema = graph.loaded_node_schema()
    num_node_properties = len(node_schema)
    new_property_id = num_node_properties - 1
    assert node_schema.names[new_property_id] == property_name

    assert graph.get_node_property(property_name)[start_node].as_py() == 0

    bfs_assert_valid(graph, start_node, property_name)

    BfsStatistics(graph, property_name)

    # Verify with numba implementation of verifier as well
    verify_bfs(graph, start_node, new_property_id)
    set_busy_wait(0)