Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nx_parallel/algorithms/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _compute_clustering_chunk(node_iter_chunk):
return clustering


@nxp._configure_if_nx_active()
@nxp._configure_if_nx_active(should_run=nxp.should_run_if_nodes_none)
def triangles(G, nodes=None, get_chunks="chunks"):
"""The nodes are chunked into `node_chunks` and for all `node_chunks`
the number of triangles that include a node as one vertex is computed
Expand Down
13 changes: 13 additions & 0 deletions nx_parallel/tests/test_should_run.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a consistent and organized test structure, it would be good to split the tests in this file-- tests that test should_run used in nx-parallel can remain in this file, while tests that test the functionality implemented in should_run_policies.py (i.e. tests with dummy functions, data, etc.) can live in utils/tests/test_should_run_policies.py. (like get_chunks)

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ def dummy_if_large(G):
assert dummy_if_large.should_run(largeG)


def test_should_run_if_nodes_none():
@nxp._configure_if_nx_active(should_run=nxp.should_run_if_nodes_none)
def dummy_nodes_none(G, nodes=None):
pass

G = nx.fast_gnp_random_graph(20, 0.6, seed=42)
assert (
dummy_nodes_none.should_run(G, nodes=[1, 3])
== "Parallel execution only supported when `nodes` is None"
)
assert dummy_nodes_none.should_run(G)


def test_should_run_if_sparse():
@nxp._configure_if_nx_active(should_run=nxp.should_run_if_sparse(threshold=0.4))
def dummy_if_sparse(G):
Expand Down
7 changes: 7 additions & 0 deletions nx_parallel/utils/should_run_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"default_should_run",
"should_skip_parallel",
"should_run_if_large",
"should_run_if_nodes_none",
"should_run_if_sparse",
]

Expand All @@ -30,6 +31,12 @@ def default_should_run(*_):
return True


def should_run_if_nodes_none(G, nodes=None, *_):
if nodes is None:
return True
return "Parallel execution only supported when `nodes` is None"


def should_run_if_sparse(threshold=0.3):
def wrapper(G, *_):
if hasattr(G, "graph_object"):
Expand Down