Skip to content

Commit

Permalink
Updates to bench_algos.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nv-rliu committed Nov 25, 2024
1 parent 5ed1e53 commit 5b42986
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions benchmarks/pytest-based/bench_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.


from collections.abc import Mapping

import networkx as nx
Expand Down Expand Up @@ -224,6 +225,17 @@ def build_personalization_dict(pagerank_dict):

return pers_dict

# Used to return a function that calls the original function inside a try-except block
# which is Useful to still save pytest-benchmark numbers if failure is correct behavior for
# the function being tested.
def possible_to_fail(exception, function):
def nested_func(*args, **kwargs):
try:
return function(*args, **kwargs)
except exception:
pass
return nested_func


################################################################################
# Benchmarks
Expand Down Expand Up @@ -366,7 +378,10 @@ def bench_in_degree_centrality(benchmark, graph_obj, backend_wrapper):
def bench_katz_centrality(benchmark, graph_obj, backend_wrapper, normalized):
G = get_graph_obj_for_benchmark(graph_obj, backend_wrapper)
result = benchmark.pedantic(
target=backend_wrapper(nx.katz_centrality),
target=possible_to_fail(
nx.PowerIterationFailedConvergence,
backend_wrapper(nx.katz_centrality)
),
args=(G,),
kwargs=dict(
normalized=normalized,
Expand All @@ -375,7 +390,7 @@ def bench_katz_centrality(benchmark, graph_obj, backend_wrapper, normalized):
iterations=iterations,
warmup_rounds=warmup_rounds,
)
assert type(result) is dict
assert type(result) is dict or result is None


def bench_k_truss(benchmark, graph_obj, backend_wrapper):
Expand Down Expand Up @@ -691,7 +706,7 @@ def bench_descendants_at_distance(benchmark, graph_obj, backend_wrapper):
)
assert type(result) is set


@pytest.mark.skip(reason="benchmark not implemented")
def bench_is_bipartite(benchmark, graph_obj, backend_wrapper):
G = get_graph_obj_for_benchmark(graph_obj, backend_wrapper)
result = benchmark.pedantic(
Expand All @@ -704,6 +719,7 @@ def bench_is_bipartite(benchmark, graph_obj, backend_wrapper):
assert type(result) is bool


@pytest.mark.skip(reason="benchmark not implemented")
def bench_is_strongly_connected(benchmark, graph_obj, backend_wrapper):
G = get_graph_obj_for_benchmark(graph_obj, backend_wrapper)
result = benchmark.pedantic(
Expand All @@ -728,6 +744,7 @@ def bench_is_weakly_connected(benchmark, graph_obj, backend_wrapper):
assert type(result) is bool


@pytest.mark.skip(reason="benchmark not implemented")
def bench_number_strongly_connected_components(benchmark, graph_obj, backend_wrapper):
G = get_graph_obj_for_benchmark(graph_obj, backend_wrapper)
result = benchmark.pedantic(
Expand Down Expand Up @@ -780,6 +797,7 @@ def bench_reciprocity(benchmark, graph_obj, backend_wrapper):
assert type(result) is float


@pytest.mark.skip(reason="benchmark not implemented")
def bench_strongly_connected_components(benchmark, graph_obj, backend_wrapper):
G = get_graph_obj_for_benchmark(graph_obj, backend_wrapper)
result = benchmark.pedantic(
Expand Down Expand Up @@ -850,7 +868,7 @@ def bench_ego_graph(benchmark, graph_obj, backend_wrapper):
iterations=iterations,
warmup_rounds=warmup_rounds,
)
assert isinstance(result, (nx.Graph, nxcg.Graph))
assert type(result) is type(G)


@pytest.mark.skip(reason="benchmark not implemented")
Expand Down

0 comments on commit 5b42986

Please sign in to comment.