Skip to content

Commit

Permalink
raise NotImplementedError when parallel > 1 on Windows
Browse files Browse the repository at this point in the history
workaround for #16
  • Loading branch information
DE0CH committed Dec 13, 2022
1 parent 28cfb2a commit 4f1c6f4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/irace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
25 changes: 24 additions & 1 deletion tests/test_dual_annealing.py
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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():
Expand All @@ -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()

0 comments on commit 4f1c6f4

Please sign in to comment.