Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] reactivate and fix test_multiprocessing_idempotent #5573

Merged
merged 4 commits into from Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 32 additions & 24 deletions sktime/tests/test_all_estimators.py
Expand Up @@ -1428,8 +1428,6 @@ def test_save_estimators_to_file(
err_msg=msg,
)

# todo: this needs to be diagnosed and fixed - temporary skip
@pytest.mark.skip(reason="hangs on mac and unix remote tests")
def test_multiprocessing_idempotent(
self, estimator_instance, scenario, method_nsc_arraylike
):
Expand All @@ -1443,29 +1441,39 @@ def test_multiprocessing_idempotent(
method_nsc = method_nsc_arraylike
params = estimator_instance.get_params()

if "n_jobs" in params:
# run on a single process
# -----------------------
estimator = deepcopy(estimator_instance)
estimator.set_params(n_jobs=1)
set_random_state(estimator)
result_single_process = scenario.run(
estimator, method_sequence=["fit", method_nsc]
)
# test runs only if n_jobs is a parameter of the estimator
if "n_jobs" not in params:
return None

# run on multiple processes
# -------------------------
estimator = deepcopy(estimator_instance)
estimator.set_params(n_jobs=-1)
set_random_state(estimator)
result_multiple_process = scenario.run(
estimator, method_sequence=["fit", method_nsc]
)
_assert_array_equal(
result_single_process,
result_multiple_process,
err_msg="Results are not equal for n_jobs=1 and n_jobs=-1",
)
# skip test for predict_proba
# this produces a BaseDistribution object, for which no ready
# equality check is implemented
if method_nsc == "predict_proba":
return None

# run on a single process
# -----------------------
estimator = deepcopy(estimator_instance)
estimator.set_params(n_jobs=1)
set_random_state(estimator)
result_single_process = scenario.run(
estimator, method_sequence=["fit", method_nsc]
)

# run on multiple processes
# -------------------------
estimator = deepcopy(estimator_instance)
estimator.set_params(n_jobs=-1)
set_random_state(estimator)
result_multiple_process = scenario.run(
estimator, method_sequence=["fit", method_nsc]
)

_assert_array_equal(
result_single_process,
result_multiple_process,
err_msg="Results are not equal for n_jobs=1 and n_jobs=-1",
)

def test_dl_constructor_initializes_deeply(self, estimator_class):
"""Test DL estimators that they pass custom parameters to underlying Network."""
Expand Down