-
Notifications
You must be signed in to change notification settings - Fork 5
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
pass instances #34
base: main
Are you sure you want to change the base?
pass instances #34
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
from irace import irace | ||
import pandas as pd | ||
from multiprocessing import Queue | ||
import pytest | ||
import os | ||
|
||
q = Queue() | ||
|
||
|
@@ -12,6 +14,10 @@ def target_runner(experiment, scenario): | |
else: | ||
return dict(cost=1) | ||
|
||
def target_runner2(experiment, scenario): | ||
if experiment['id.instance'] == 1: | ||
experiment['instance'].put(1335) | ||
return dict(cost=1) | ||
|
||
params = ''' | ||
one "" c ('0', '1') | ||
|
@@ -34,4 +40,65 @@ def test(): | |
tuner = irace(scenario, params, target_runner) | ||
best_conf = tuner.run() | ||
assert q.get() == 124 | ||
|
||
|
||
def test_instances(): | ||
q = Queue() | ||
scenario = dict( | ||
instances = [q], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would an instance be a Queue? What is this testing? Could you add a testcase that is more realistic, like instances being a list of functions that need to me minimized? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because Queue is not serializable and can only work if the queue on the other hand shares the same memory address. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why pass it in "instances" and not via other way? You are using "instances" for something that is not its purpose. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it doesn't need to be. But I think it's nice if there are multiple ways to pass stuff around. |
||
maxExperiments = 180, | ||
debugLevel = 0, | ||
parallel = 1, | ||
logFile = "", | ||
seed = 123 | ||
) | ||
tuner = irace(scenario, params, target_runner2) | ||
best_conf = tuner.run() | ||
assert q.get() == 1335 | ||
|
||
@pytest.mark.skipif(os.name == 'nt', | ||
reason="Parallel on Windows not supported") | ||
def test_instances2(): | ||
q = Queue() | ||
scenario = dict( | ||
instances = [q], | ||
maxExperiments = 180, | ||
debugLevel = 0, | ||
parallel = 2, | ||
logFile = "", | ||
seed = 123 | ||
) | ||
tuner = irace(scenario, params, target_runner2) | ||
best_conf = tuner.run() | ||
assert q.get() == 1335 | ||
|
||
def test_default_serializer(): | ||
q = Queue() | ||
scenario = dict( | ||
instances = [q], | ||
maxExperiments = 180, | ||
debugLevel = 0, | ||
parallel = 1, | ||
logFile = "", | ||
seed = 123, | ||
instanceObjectSerializer = lambda x: 'hello world' | ||
) | ||
tuner = irace(scenario, params, target_runner2) | ||
best_conf = tuner.run() | ||
assert q.get() == 1335 | ||
|
||
@pytest.mark.skipif(os.name == 'nt', | ||
reason="Parallel on Windows not supported") | ||
def test_default_serializer(): | ||
q = Queue() | ||
scenario = dict( | ||
instances = [q], | ||
maxExperiments = 180, | ||
debugLevel = 0, | ||
parallel = 2, | ||
logFile = "", | ||
seed = 123, | ||
instanceObjectSerializer = lambda x: 'hello world' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this doing? Could you document it somewhere? Irace is extremely well documented and most of its documentation currently applies to iracepy. See: https://mlopez-ibanez.github.io/irace/ and https://mlopez-ibanez.github.io/irace/irace-package.pdf |
||
) | ||
tuner = irace(scenario, params, target_runner2) | ||
best_conf = tuner.run() | ||
assert q.get() == 1335 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that the serializer is applied to strings and integers? Isn't that a waste?
Also, could you document with a comment what this line is doing? It seems to replace the instance with the string
'<not serializable>'
unless the user provides an 'instanceObjectSerializer'. Is that the case? If so, how can the user serialize their instances? It is unclear to me how all this works and will be used in practice.A couple of examples using for example: