Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -72,7 +72,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])
== "`nodes` should be None for parallel execution"
)
assert dummy_nodes_none.should_run(G)


@pytest.mark.parametrize("func_name", get_functions_with_should_run())
def test_should_run(func_name):
tournament_funcs = [
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",
]


Expand All @@ -24,3 +25,9 @@ def default_should_run(*_):
if n_jobs in (None, 0, 1):
return "Parallel backend requires `n_jobs` > 1 to run"
return True


def should_run_if_nodes_none(G, nodes=None, *_):
if nodes is None:
return True
return "`nodes` should be None for parallel execution"
Loading