From 4f1c6f4855ac5821d95230ff77c5eec978d96cc1 Mon Sep 17 00:00:00 2001 From: Deyao Chen Date: Tue, 13 Dec 2022 11:48:48 +0000 Subject: [PATCH] raise NotImplementedError when parallel > 1 on Windows workaround for #16 --- src/irace/__init__.py | 5 +++++ tests/test_dual_annealing.py | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/irace/__init__.py b/src/irace/__init__.py index 9490009..0c3ce71 100644 --- a/src/irace/__init__.py +++ b/src/irace/__init__.py @@ -99,6 +99,10 @@ def tmp_r_target_runner(experiment, scenario): return ListVector(ret) return tmp_r_target_runner +def check_windows(scenario): + if scenario.get('parallel', 1) != 1 and os.name == 'nt': + raise NotImplementedError('Parallel running on windows is not supported yet. Follow https://github.com/auto-optimization/iracepy/issues/16 for updates. Alternatively, use Linux or MacOS or the irace R package directly.') + class irace: # Imported R package try: @@ -114,6 +118,7 @@ def __init__(self, scenario, parameters_table, target_runner): # IMPORTANT: We need to save this in a variable or it will be garbage # collected by Python and crash later. self.r_target_runner = make_target_runner(target_runner) + check_windows(scenario) def read_configurations(self, filename=None, text=None): if text is None: diff --git a/tests/test_dual_annealing.py b/tests/test_dual_annealing.py index 2147d9a..589f22e 100644 --- a/tests/test_dual_annealing.py +++ b/tests/test_dual_annealing.py @@ -1,5 +1,7 @@ import numpy as np from irace import irace +import os +import pytest DIM=10 # This works even with parallel LB = [-5.12] @@ -33,13 +35,19 @@ def target_runner(experiment, scenario, lb = LB, ub = UB): instances = np.arange(100) # See https://mlopez-ibanez.github.io/irace/reference/defaultScenario.html + +if os.name == 'nt': + parallel = 1 +else: + parallel = 2 + scenario = dict( instances = instances, maxExperiments = 180, debugLevel = 3, seed = 123, digits = 5, - parallel= 2, # It can run in parallel ! + parallel= parallel, # It can run in parallel ! logFile = "") def test_run(): @@ -49,3 +57,18 @@ def test_run(): # FIXME: assert type Pandas DataFrame print(best_confs) +def test_fail_windows(): + # FIXME: remove when https://github.com/auto-optimization/iracepy/issues/16 is closed. + if os.name == 'nt': + with pytest.raises(NotImplementedError): + scenario = dict( + instances = instances, + maxExperiments = 180, + debugLevel = 3, + seed = 123, + digits = 5, + parallel= 2, # It can run in parallel ! + logFile = "") + tuner = irace(scenario, parameters_table, target_runner) + tuner.run() + \ No newline at end of file