Exemplo n.º 1
0
def test_betweenness_centrality_nx(
        graph_file,
        directed,
        edgevals
):
    prepare_test()

    Gnx = utils.generate_nx_graph_from_file(graph_file, directed, edgevals)

    nx_bc = nx.betweenness_centrality(Gnx)
    cu_bc = cugraph.betweenness_centrality(Gnx)

    # Calculating mismatch
    networkx_bc = sorted(nx_bc.items(), key=lambda x: x[0])
    cugraph_bc = sorted(cu_bc.items(), key=lambda x: x[0])
    err = 0
    assert len(cugraph_bc) == len(networkx_bc)
    for i in range(len(cugraph_bc)):
        if (
            abs(cugraph_bc[i][1] - networkx_bc[i][1]) > 0.01
            and cugraph_bc[i][0] == networkx_bc[i][0]
        ):
            err = err + 1
            print(f"{cugraph_bc[i][1]} and {cugraph_bc[i][1]}")
    print("Mismatches:", err)
    assert err < (0.01 * len(cugraph_bc))
Exemplo n.º 2
0
def test_nx_hits(benchmark, input_combo):
    """
    Simply run NetworkX HITS on the same set of input combinations used for the
    cuGraph HITS tests.
    This is only in place for generating comparison performance numbers.
    """
    Gnx = utils.generate_nx_graph_from_file(input_combo["graph_file"],
                                            directed=True)
    nxResults = benchmark(nx.hits,
                          Gnx,
                          input_combo["max_iter"],
                          input_combo["tol"],
                          normalized=True)
    # Save the results back to the input_combo dictionary to prevent redundant
    # Nx runs. Other tests using the input_combo fixture will look for them,
    # and if not present they will have to re-run the same Nx call.
    input_combo["nxResults"] = nxResults
Exemplo n.º 3
0
def input_expected_output(input_combo):
    """
    This fixture returns a dictionary containing all input params required to
    run a HITS algo and the corresponding expected result (based on NetworkX
    HITS) which can be used for validation.
    """
    # Only run Nx to compute the expected result if it is not already present
    # in the dictionary. This allows separate Nx-only tests that may have run
    # previously on the same input_combo to save their results for re-use
    # elsewhere.
    if "nxResults" not in input_combo:
        Gnx = utils.generate_nx_graph_from_file(input_combo["graph_file"],
                                                directed=True)
        nxResults = nx.hits(Gnx,
                            input_combo["max_iter"],
                            input_combo["tol"],
                            normalized=True)
        input_combo["nxResults"] = nxResults
    return input_combo
Exemplo n.º 4
0
def get_nx_graph_and_params(dataset, directed):
    """
    Helper for fixtures returning a Nx graph obj and params.
    """
    return (dataset, directed,
            utils.generate_nx_graph_from_file(dataset, directed))