crace 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crace/__init__.py +36 -0
- crace/_version.py +24 -0
- crace/configurator/__init__.py +0 -0
- crace/configurator/configurator.py +26 -0
- crace/configurator/crace.py +105 -0
- crace/configurator/irace.py +21 -0
- crace/configurator/tester.py +206 -0
- crace/containers/__init__.py +29 -0
- crace/containers/configurations.py +720 -0
- crace/containers/crace_option.py +943 -0
- crace/containers/crace_options.py +795 -0
- crace/containers/crace_results.py +430 -0
- crace/containers/experiments.py +1536 -0
- crace/containers/forbidden_expressions.py +41 -0
- crace/containers/instances.py +563 -0
- crace/containers/parameters.py +1237 -0
- crace/containers/scenario.py +266 -0
- crace/containers/toolbox.py +25 -0
- crace/elimination_tests/__init__.py +2 -0
- crace/elimination_tests/eliminator.py +158 -0
- crace/elimination_tests/tests.py +1112 -0
- crace/errors/__init__.py +56 -0
- crace/execution/__init__.py +101 -0
- crace/execution/execution_base.py +213 -0
- crace/execution/execution_pool.py +332 -0
- crace/execution/local_concurrent.py +295 -0
- crace/execution/mpi.py +661 -0
- crace/execution/target_evaluator.py +88 -0
- crace/execution/target_runner.py +218 -0
- crace/inst/bin/profile_main.py +99 -0
- crace/inst/bin/profile_mpi.py +86 -0
- crace/inst/bin/slurm_mpi +146 -0
- crace/inst/bin/slurm_mpi_bind_cores +189 -0
- crace/inst/examples/README.md +22 -0
- crace/inst/examples/Spear/README +29 -0
- crace/inst/examples/Spear/parameters-cat.txt +27 -0
- crace/inst/examples/Spear/parameters-mixed.txt +27 -0
- crace/inst/examples/Spear/scenario.txt +40 -0
- crace/inst/examples/Spear/target-runner +80 -0
- crace/inst/examples/acotsp/Instances/2000-1.tsp +2006 -0
- crace/inst/examples/acotsp/Instances/2000-2.tsp +2006 -0
- crace/inst/examples/acotsp/Instances/2000-3.tsp +2006 -0
- crace/inst/examples/acotsp/Instances/2000-4.tsp +2006 -0
- crace/inst/examples/acotsp/Instances/2000-5.tsp +2006 -0
- crace/inst/examples/acotsp/default.txt +15 -0
- crace/inst/examples/acotsp/forbidden.txt +12 -0
- crace/inst/examples/acotsp/instance-list.txt +5 -0
- crace/inst/examples/acotsp/parameters.txt +16 -0
- crace/inst/examples/acotsp/scenario.txt +28 -0
- crace/inst/examples/acotsp/target-runner +73 -0
- crace/inst/examples/batchmode-cluster/README +2 -0
- crace/inst/examples/batchmode-cluster/irace-sge-cluster +16 -0
- crace/inst/examples/batchmode-cluster/target-evaluator +66 -0
- crace/inst/examples/batchmode-cluster/target-runner-htcondor +69 -0
- crace/inst/examples/batchmode-cluster/target-runner-pbs +59 -0
- crace/inst/examples/batchmode-cluster/target-runner-sge +75 -0
- crace/inst/examples/batchmode-cluster/target-runner-slurm +77 -0
- crace/inst/examples/hypervolume/README +14 -0
- crace/inst/examples/hypervolume/target-evaluator +105 -0
- crace/inst/examples/hypervolume/target-runner +48 -0
- crace/inst/examples/matlab/Main.m +19 -0
- crace/inst/examples/matlab/instances.txt +10 -0
- crace/inst/examples/matlab/parameters.txt +2 -0
- crace/inst/examples/matlab/scenario.txt +80 -0
- crace/inst/examples/mik/Instances/mik.250-1-50.1.mps +8713 -0
- crace/inst/examples/mik/Instances/mik.250-1-50.2.mps +8713 -0
- crace/inst/examples/mik/Instances/mik.250-1-50.3.mps +8713 -0
- crace/inst/examples/mik/Instances/mik.250-5-50.1.mps +8929 -0
- crace/inst/examples/mik/Instances/mik.250-5-50.2.mps +8929 -0
- crace/inst/examples/mik/Instances/mik.250-5-50.3.mps +8929 -0
- crace/inst/examples/mik/aclib/executable/cplex12.6_wrapper.rb +92 -0
- crace/inst/examples/mik/aclib/executable/cplex12.6_wrapper_aclib.rb +223 -0
- crace/inst/examples/mik/aclib/executable/run_cplex12.6.rb +81 -0
- crace/inst/examples/mik/default.txt +16 -0
- crace/inst/examples/mik/instance-list.txt +6 -0
- crace/inst/examples/mik/parameters.txt +227 -0
- crace/inst/examples/mik/scenario.txt +32 -0
- crace/inst/examples/mik/target-runner +114 -0
- crace/inst/examples/moaco/README +29 -0
- crace/inst/examples/moaco/parameters.txt +41 -0
- crace/inst/examples/moaco/scenario.txt +13 -0
- crace/inst/examples/moaco/target-evaluator +107 -0
- crace/inst/examples/moaco/target-runner +62 -0
- crace/inst/examples/slurm/job.sh +43 -0
- crace/inst/examples/slurm/run_irace.R +42 -0
- crace/inst/examples/target-runner-c/instances.txt +4 -0
- crace/inst/examples/target-runner-c/parameters.txt +5 -0
- crace/inst/examples/target-runner-c/scenario.txt +2 -0
- crace/inst/examples/target-runner-c/target-runner.c +128 -0
- crace/inst/examples/target-runner-python/target-runner-acotsp.py +99 -0
- crace/inst/examples/target-runner-python/target-runner-advanced.py +433 -0
- crace/inst/examples/target-runner-python/target-runner-python-win.bat +28 -0
- crace/inst/examples/target-runner-python/trivial/instances.txt +2 -0
- crace/inst/examples/target-runner-python/trivial/parameters.txt +4 -0
- crace/inst/examples/target-runner-python/trivial/scenario.txt +4 -0
- crace/inst/examples/target-runner-python/trivial/target-runner.py +80 -0
- crace/inst/examples/win/instances.txt +9 -0
- crace/inst/examples/win/parameters.txt +2 -0
- crace/inst/examples/win/runner.exe +0 -0
- crace/inst/examples/win/scenario.txt +8 -0
- crace/inst/examples/win/src/CMakeLists.txt +4 -0
- crace/inst/examples/win/src/runner.cpp +44 -0
- crace/inst/examples/win/target-runner.bat +37 -0
- crace/inst/output_sed.sh +46 -0
- crace/inst/templates/configurations.txt +15 -0
- crace/inst/templates/forbidden.txt +10 -0
- crace/inst/templates/ins/2000-1.tsp +2006 -0
- crace/inst/templates/ins/2000-2.tsp +2006 -0
- crace/inst/templates/ins/2000-3.tsp +2006 -0
- crace/inst/templates/ins/2000-4.tsp +2006 -0
- crace/inst/templates/ins/2000-5.tsp +2006 -0
- crace/inst/templates/instances-list.txt +12 -0
- crace/inst/templates/parameters.txt +36 -0
- crace/inst/templates/scenario.txt +212 -0
- crace/inst/templates/target-runner +80 -0
- crace/inst/templates/windows/target-runner.bat +66 -0
- crace/models/__init__.py +0 -0
- crace/models/model.py +1290 -0
- crace/race/__init__.py +0 -0
- crace/race/race.py +2368 -0
- crace/race/race_log.py +660 -0
- crace/scripts/__init__.py +71 -0
- crace/scripts/crace-guide +12 -0
- crace/scripts/crace-main +3 -0
- crace/scripts/crace-mpi +3 -0
- crace/scripts/crace-parallel +89 -0
- crace/scripts/main.py +156 -0
- crace/scripts/mpi.py +99 -0
- crace/scripts/parallel.py +107 -0
- crace/scripts/utils.py +216 -0
- crace/settings/__init__.py +0 -0
- crace/settings/crace_options.json +1048 -0
- crace/settings/description.py +67 -0
- crace/threads/__init__.py +120 -0
- crace/utils/__init__.py +157 -0
- crace/utils/const.py +6 -0
- crace/utils/format.py +159 -0
- crace/utils/logger.py +113 -0
- crace/utils/reader.py +102 -0
- crace/vignettes/crace-package.pdf +0 -0
- crace-1.0.0.data/scripts/crace-parallel +89 -0
- crace-1.0.0.dist-info/METADATA +541 -0
- crace-1.0.0.dist-info/RECORD +158 -0
- crace-1.0.0.dist-info/WHEEL +5 -0
- crace-1.0.0.dist-info/entry_points.txt +2 -0
- crace-1.0.0.dist-info/licenses/LICENSE +674 -0
- crace-1.0.0.dist-info/top_level.txt +2 -0
- docs/_config.yml +48 -0
- docs/_static/css/custom.css +168 -0
- docs/_static/js/navbar.js +40 -0
- docs/_toc.yml +4 -0
- docs/index.md +4 -0
- docs/references/404.md +3 -0
- docs/references/CITIATION.bib +31 -0
- docs/references/LICENSE.md +157 -0
- docs/references/authors.md +57 -0
- docs/references/index.md +43 -0
- docs/requirements.txt +4 -0
crace/__init__.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# crace/__init__.py
|
|
2
|
+
|
|
3
|
+
from crace.scripts import run
|
|
4
|
+
from crace.scripts import crace_main as main
|
|
5
|
+
|
|
6
|
+
from crace.utils import Reader
|
|
7
|
+
from crace.containers.scenario import Scenario
|
|
8
|
+
from crace.containers.parameters import Parameters
|
|
9
|
+
from crace.containers.instances import Instances
|
|
10
|
+
from crace.containers.crace_options import CraceOptions
|
|
11
|
+
from crace.containers.crace_results import CraceResults
|
|
12
|
+
from crace.containers.configurations import Configurations
|
|
13
|
+
|
|
14
|
+
import crace.settings.description as _csd
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__version__ = _csd.version
|
|
18
|
+
__author__ = _csd.authors
|
|
19
|
+
__maintainers__ = _csd.maintainers
|
|
20
|
+
__long_description__ = _csd.long_description
|
|
21
|
+
__doc__ = _csd.description
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
'run',
|
|
25
|
+
'main',
|
|
26
|
+
'Reader',
|
|
27
|
+
'Scenario',
|
|
28
|
+
'Parameters',
|
|
29
|
+
'Instances',
|
|
30
|
+
'CraceOptions',
|
|
31
|
+
'Configurations',
|
|
32
|
+
'CraceResults'
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
def __dir__():
|
|
36
|
+
return __all__
|
crace/_version.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '1.0.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 0, 0)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Configurator(ABC):
|
|
5
|
+
|
|
6
|
+
def __init__(self, scenario):
|
|
7
|
+
self.scenario = scenario
|
|
8
|
+
|
|
9
|
+
@abstractmethod
|
|
10
|
+
def run(self):
|
|
11
|
+
"""
|
|
12
|
+
Create and send experiments to work. Iterate until the end conditions
|
|
13
|
+
are met
|
|
14
|
+
:return:
|
|
15
|
+
"""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def recover(self):
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def check(self):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import asyncio
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
import crace.execution as execution
|
|
6
|
+
from crace.race.race import Race, RaceCheck
|
|
7
|
+
from crace.containers.scenario import Scenario
|
|
8
|
+
from crace.containers.instances import Instances
|
|
9
|
+
from crace.containers.parameters import Parameters
|
|
10
|
+
from crace.containers.crace_options import CraceOptions
|
|
11
|
+
|
|
12
|
+
asyncio_logger = logging.getLogger("asyncio")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Crace:
|
|
16
|
+
def __init__(self, scenario: Scenario):
|
|
17
|
+
self.options = scenario.options
|
|
18
|
+
self.parameters = scenario.parameters
|
|
19
|
+
self.instances = scenario.instances
|
|
20
|
+
self.initial_configurations = scenario.initial_configurations
|
|
21
|
+
|
|
22
|
+
random.seed((self.options.seed.value * 7 - 1234567) % 7654321)
|
|
23
|
+
|
|
24
|
+
if self.options.readLogsInCplot.value < 1: self.options.print_crace_header()
|
|
25
|
+
if not self.options.readlogs.value:
|
|
26
|
+
print_options(self.options, self.parameters, self.instances, full=True)
|
|
27
|
+
|
|
28
|
+
self.race = Race(self.initial_configurations, self.instances, self.parameters, self.options)
|
|
29
|
+
|
|
30
|
+
# create master execution handler
|
|
31
|
+
if not self.options.readlogs.value:
|
|
32
|
+
self.master, self._pool = execution.start_execution(self.options, self.race.race_callback, self.race.experiments)
|
|
33
|
+
self.race.set_pool(self._pool)
|
|
34
|
+
|
|
35
|
+
def recover(self, options: CraceOptions):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
def run(self):
|
|
39
|
+
"""
|
|
40
|
+
Runs the configurator and returns the result of the race
|
|
41
|
+
:return:
|
|
42
|
+
"""
|
|
43
|
+
print("# Running crace configuration procedure")
|
|
44
|
+
execution_logger = logging.getLogger('execution')
|
|
45
|
+
loop = asyncio.get_event_loop()
|
|
46
|
+
future = asyncio.ensure_future(self.race.asynchronous_race())
|
|
47
|
+
asyncio_logger.debug("Ensured asynchronous_race future")
|
|
48
|
+
loop.run_until_complete(future)
|
|
49
|
+
asyncio_logger.debug("asynchronous_race future is complete")
|
|
50
|
+
execution_logger.info(future.result())
|
|
51
|
+
shutdown_future = asyncio.ensure_future(execution.stop_execution_async(self.master, self._pool))
|
|
52
|
+
asyncio_logger.debug("Requesting stop of execution")
|
|
53
|
+
loop.run_until_complete(shutdown_future)
|
|
54
|
+
asyncio_logger.debug("Execution stopped")
|
|
55
|
+
return future.result()
|
|
56
|
+
|
|
57
|
+
def read_log_files(self):
|
|
58
|
+
"""
|
|
59
|
+
Read log files
|
|
60
|
+
"""
|
|
61
|
+
data = self.race.read_log_files()
|
|
62
|
+
return data
|
|
63
|
+
|
|
64
|
+
def get_elite_configurations(self):
|
|
65
|
+
return self.race.get_elite_configurations()
|
|
66
|
+
|
|
67
|
+
class Check:
|
|
68
|
+
def __init__(self, scenario: Scenario):
|
|
69
|
+
self.options = scenario.options
|
|
70
|
+
self.parameters = scenario.parameters
|
|
71
|
+
self.instances = scenario.instances
|
|
72
|
+
self.initial_configurations = scenario.initial_configurations
|
|
73
|
+
|
|
74
|
+
random.seed((self.options.seed.value * 7 - 1234567) % 7654321)
|
|
75
|
+
|
|
76
|
+
if self.options.readLogsInCplot.value < 1: self.options.print_crace_header()
|
|
77
|
+
print_options(self.options, self.parameters, self.instances, full=False)
|
|
78
|
+
|
|
79
|
+
self.race = RaceCheck(self.initial_configurations, self.instances, self.parameters, self.options)
|
|
80
|
+
|
|
81
|
+
# create master execution handler
|
|
82
|
+
self.master, self._pool = execution.start_execution(self.options, self.race.race_callback, self.race.experiments)
|
|
83
|
+
self.race.set_pool(self._pool)
|
|
84
|
+
|
|
85
|
+
def run(self):
|
|
86
|
+
"""
|
|
87
|
+
Runs the configurator and returns the result of the race
|
|
88
|
+
:return:
|
|
89
|
+
"""
|
|
90
|
+
print("# Checking the provided scenario files..")
|
|
91
|
+
loop = asyncio.get_event_loop()
|
|
92
|
+
future = asyncio.ensure_future(self.race.asynchronous_race())
|
|
93
|
+
loop.run_until_complete(future)
|
|
94
|
+
shutdown_future = asyncio.ensure_future(execution.stop_execution_checking(self.master, self._pool))
|
|
95
|
+
loop.run_until_complete(shutdown_future)
|
|
96
|
+
return future.result()
|
|
97
|
+
|
|
98
|
+
def print_options(options: CraceOptions, parameters: Parameters, instances: Instances, full=True):
|
|
99
|
+
# FIXME: check what we want to display here
|
|
100
|
+
if full:
|
|
101
|
+
options.print_all()
|
|
102
|
+
print('#------------------------------------------------------------------------------')
|
|
103
|
+
else:
|
|
104
|
+
options.print_selects()
|
|
105
|
+
print('#------------------------------------------------------------------------------')
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
from crace.containers import Scenario, CraceOptions
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Irace:
|
|
6
|
+
def __init__(self, scenario: Scenario):
|
|
7
|
+
self.options = scenario.options
|
|
8
|
+
self.parameters = scenario.parameters
|
|
9
|
+
self.instances = scenario.instances
|
|
10
|
+
self.configurations = copy.deepcopy(scenario.initial_configurations)
|
|
11
|
+
|
|
12
|
+
# calculate important variables
|
|
13
|
+
|
|
14
|
+
def recover(self, options: CraceOptions):
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
def search(self):
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
def get_elite_configurations(self):
|
|
21
|
+
pass
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import time
|
|
3
|
+
import copy
|
|
4
|
+
import asyncio
|
|
5
|
+
import logging
|
|
6
|
+
import crace.execution as execution
|
|
7
|
+
|
|
8
|
+
from crace.utils import get_loop
|
|
9
|
+
from crace.errors import CraceError
|
|
10
|
+
from crace.containers.scenario import Scenario
|
|
11
|
+
from crace.containers.experiments import Experiments
|
|
12
|
+
|
|
13
|
+
asyncio_logger = logging.getLogger("asyncio")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Tester:
|
|
17
|
+
def __init__(self, scenario: Scenario):
|
|
18
|
+
print("\n\n# Initializing tester ")
|
|
19
|
+
self.options = scenario.options
|
|
20
|
+
self.parameters = scenario.parameters
|
|
21
|
+
self.instances = scenario.instances
|
|
22
|
+
if scenario.initial_configurations is None:
|
|
23
|
+
self.initial_configurations = None
|
|
24
|
+
else:
|
|
25
|
+
self.initial_configurations = copy.deepcopy(scenario.initial_configurations)
|
|
26
|
+
self.configurations = self.initial_configurations.get_alive()
|
|
27
|
+
|
|
28
|
+
self.target_eval = False
|
|
29
|
+
# if self.options.targetEvaluator.value is not None:
|
|
30
|
+
# self.target_eval = True
|
|
31
|
+
|
|
32
|
+
self.log_folder_test = os.path.join(self.options.logDir.value, "test")
|
|
33
|
+
if not os.path.exists(self.log_folder_test):
|
|
34
|
+
os.mkdir(self.log_folder_test)
|
|
35
|
+
self.experiments = Experiments(log_folder=self.log_folder_test,
|
|
36
|
+
budget_digits=self.options.boundDigits.value,
|
|
37
|
+
log_level=self.options.logLevel.value)
|
|
38
|
+
|
|
39
|
+
self.debug_level = self.options.debugLevel.value
|
|
40
|
+
self._scheduled_jobs = []
|
|
41
|
+
self._to_eval_jobs = []
|
|
42
|
+
self.n_experiments = 0
|
|
43
|
+
|
|
44
|
+
# self._result_future = asyncio.Future()
|
|
45
|
+
loop = get_loop()
|
|
46
|
+
self._result_future = loop.create_future()
|
|
47
|
+
|
|
48
|
+
# create master execution handler
|
|
49
|
+
self.master, self._pool = execution.start_execution(self.options, self.test_callback, self.experiments, True)
|
|
50
|
+
|
|
51
|
+
self.clock = time.time()
|
|
52
|
+
|
|
53
|
+
def do_test(self, config: dict = None):
|
|
54
|
+
terminated = None
|
|
55
|
+
if self.options.recoveryDir.is_set():
|
|
56
|
+
terminated = self.check_status(config)
|
|
57
|
+
if terminated:
|
|
58
|
+
print('# Testing is finished in previous run.')
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
print("# Start testing ... ")
|
|
62
|
+
|
|
63
|
+
if config is not None:
|
|
64
|
+
self.configurations = config
|
|
65
|
+
elif self.configurations is None:
|
|
66
|
+
raise CraceError("There are no configurations assigned to test.")
|
|
67
|
+
|
|
68
|
+
print("# Configurations: ", len(self.configurations))
|
|
69
|
+
if self.debug_level >= 0:
|
|
70
|
+
for co in self.configurations:
|
|
71
|
+
print(f" {co.id}: {co.cmd}")
|
|
72
|
+
|
|
73
|
+
print("# Instances: ", self.instances.tsize)
|
|
74
|
+
if self.debug_level >= 2:
|
|
75
|
+
for i in range(self.instances.tsize):
|
|
76
|
+
print(" {}: {}".format(i+1, self.instances.tnames[i]))
|
|
77
|
+
|
|
78
|
+
if self.options.testNbElites.value != len(self.configurations):
|
|
79
|
+
self.configurations = self.configurations[0:self.options.testNbElites.value]
|
|
80
|
+
print(f"# Test {self.options.testNbElites.value} configuration(s): {','.join([str(x.id) for x in self.configurations])}")
|
|
81
|
+
if self.debug_level >= 2 and self.options.testNbElites.value > len(self.configurations):
|
|
82
|
+
print(f"# Only {len(self.configurations)} elite configurations are returned.")
|
|
83
|
+
|
|
84
|
+
asyncio_logger.debug("do_test")
|
|
85
|
+
loop = asyncio.get_event_loop()
|
|
86
|
+
future = asyncio.ensure_future(self.execute_test())
|
|
87
|
+
asyncio_logger.debug("do_test: ensured future")
|
|
88
|
+
loop.run_until_complete(future)
|
|
89
|
+
asyncio_logger.debug("do_test: future is complete")
|
|
90
|
+
asyncio_logger.info(future.result())
|
|
91
|
+
shutdown_future = asyncio.ensure_future(execution.stop_execution_async(self.master, self._pool))
|
|
92
|
+
asyncio_logger.debug("do_test: requesting stop")
|
|
93
|
+
loop.run_until_complete(shutdown_future)
|
|
94
|
+
asyncio_logger.debug("do_test: stopped")
|
|
95
|
+
|
|
96
|
+
print("Stopped")
|
|
97
|
+
|
|
98
|
+
async def execute_test(self):
|
|
99
|
+
asyncio_logger.debug("execute_test")
|
|
100
|
+
assert self.configurations is not None, "configurations must be provided"
|
|
101
|
+
self._add_experiments(self.configurations, self.instances.tinstances, {0:self.options.boundMax.value})
|
|
102
|
+
asyncio_logger.debug("execute_test: Before await")
|
|
103
|
+
# do we need the following line?
|
|
104
|
+
await self._result_future
|
|
105
|
+
return "finished"
|
|
106
|
+
|
|
107
|
+
def _add_experiments(self, configurations: list, instances: list, bound: dict):
|
|
108
|
+
asyncio_logger.debug("_add_experiments: called")
|
|
109
|
+
|
|
110
|
+
if configurations is dict:
|
|
111
|
+
configurations = configurations.values()
|
|
112
|
+
|
|
113
|
+
exp_ids, exps = self.experiments.new_experiments(configurations, instances, bound)
|
|
114
|
+
if self.debug_level >= 2:
|
|
115
|
+
print("# Adding test experiments config: {} \n# instances: {} \n# exp ids: {} ".format(
|
|
116
|
+
[x.id for x in configurations],
|
|
117
|
+
[x.instance_id for x in instances],
|
|
118
|
+
exp_ids))
|
|
119
|
+
self._pool.submit_experiments(exps)
|
|
120
|
+
self._scheduled_jobs.extend(exp_ids)
|
|
121
|
+
asyncio_logger.debug("_add_experiments: finished")
|
|
122
|
+
|
|
123
|
+
def _complete_experiment(self, experiment, result, result_time):
|
|
124
|
+
print("# Experiment: {:<7d} config: {:<7d} instance: {:<7d} result: {:<20f}time: {:.5f}".format(experiment.experiment_id,
|
|
125
|
+
experiment.configuration_id,
|
|
126
|
+
experiment.instance_id,
|
|
127
|
+
result,result_time))
|
|
128
|
+
if not self.target_eval:
|
|
129
|
+
result_experiment = self.experiments.complete_experiment(
|
|
130
|
+
experiment_id=experiment.experiment_id,
|
|
131
|
+
budget=experiment.budget,
|
|
132
|
+
budget_format=experiment.budget_format,
|
|
133
|
+
solution_quality=result,
|
|
134
|
+
exp_time=result_time,
|
|
135
|
+
start_time=experiment.start_time,
|
|
136
|
+
end_time=experiment.end_time)
|
|
137
|
+
else:
|
|
138
|
+
result_experiment = self.experiments.complete_experiment_time(
|
|
139
|
+
experiment_id=experiment.experiment_id,
|
|
140
|
+
exp_time=result_time,
|
|
141
|
+
start_time=experiment.start_time,
|
|
142
|
+
end_time=experiment.end_time)
|
|
143
|
+
self._to_eval_jobs.append(experiment.experiment_id)
|
|
144
|
+
|
|
145
|
+
if experiment.experiment_id in self._scheduled_jobs:
|
|
146
|
+
index = self._scheduled_jobs.index(experiment.experiment_id)
|
|
147
|
+
del self._scheduled_jobs[index]
|
|
148
|
+
return result_experiment
|
|
149
|
+
|
|
150
|
+
def _evaluate_experiment(self, experiment):
|
|
151
|
+
"""
|
|
152
|
+
Call to target evaluator when an a set of experiments is done.
|
|
153
|
+
|
|
154
|
+
:param experiment: experiment object
|
|
155
|
+
:param solution_quality:
|
|
156
|
+
|
|
157
|
+
:return: None
|
|
158
|
+
"""
|
|
159
|
+
if self.target_eval:
|
|
160
|
+
# FIXME: put this into a function
|
|
161
|
+
exps = self.experiments.get_waiting_experiments_by_instance_id(experiment.instance_id)
|
|
162
|
+
alive_ids = self.configurations.keys()
|
|
163
|
+
evaluations = self._pool.evaluate_experiments(exps, alive_ids)
|
|
164
|
+
for e, solution_quality in evaluations:
|
|
165
|
+
result_experiment = self.experiments.complete_experiment_quality(e.experiment_id, solution_quality)
|
|
166
|
+
index = self._to_eval_jobs.index(e.experiment_id)
|
|
167
|
+
del self._to_eval_jobs[index]
|
|
168
|
+
|
|
169
|
+
def _is_instance_fully_executed(self, instance_id):
|
|
170
|
+
"""
|
|
171
|
+
Checks if an instance is fully executed. A fully executed instance is defined as
|
|
172
|
+
an instance for which there are no experiments scheduled.
|
|
173
|
+
|
|
174
|
+
:param instance_id: instance id
|
|
175
|
+
|
|
176
|
+
:return: Boolean indicating if instance is complete
|
|
177
|
+
"""
|
|
178
|
+
for experiment_id in self._scheduled_jobs:
|
|
179
|
+
experiment = self.experiments.get_experiment_by_id(experiment_id, as_dataframe=False)
|
|
180
|
+
if instance_id == experiment.instance_id:
|
|
181
|
+
return False
|
|
182
|
+
return True
|
|
183
|
+
|
|
184
|
+
def test_callback(self, experiment, solution_quality, solution_time):
|
|
185
|
+
complete_experiment = self._complete_experiment(experiment, solution_quality, solution_time)
|
|
186
|
+
self.n_experiments = self.n_experiments + 1
|
|
187
|
+
|
|
188
|
+
if self._is_instance_fully_executed(experiment.instance_id):
|
|
189
|
+
self._evaluate_experiment(experiment)
|
|
190
|
+
|
|
191
|
+
if len(self._scheduled_jobs) == 0:
|
|
192
|
+
self._result_future.set_result("Future is done!")
|
|
193
|
+
|
|
194
|
+
def check_status(self, config):
|
|
195
|
+
"""
|
|
196
|
+
check if test is finished already
|
|
197
|
+
"""
|
|
198
|
+
tsize = self.instances.tsize
|
|
199
|
+
n_elite = self.options.testNbElites.value
|
|
200
|
+
exps_fin = os.path.join(self.options.recoveryDir.value, 'test/exps_fin.log')
|
|
201
|
+
if os.path.exists(exps_fin) and os.path.getsize(exps_fin) > 0:
|
|
202
|
+
with open(exps_fin, newline='') as f:
|
|
203
|
+
line_count = sum(1 for line in f)
|
|
204
|
+
return True if line_count == tsize * n_elite else False
|
|
205
|
+
else:
|
|
206
|
+
return False
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
"""def create_log(path,logger_name,debug_lv):
|
|
3
|
+
#create the class using a logger, and the path when log file will be saved
|
|
4
|
+
logger = logging.getLogger()
|
|
5
|
+
logger.setLevel(0)
|
|
6
|
+
formatter = logging.Formatter('%(asctime)s - %(message)s')
|
|
7
|
+
file_handler = logging.FileHandler(path)
|
|
8
|
+
file_handler.setLevel(0)# minimun level to save,must be higher or equal than logger's level
|
|
9
|
+
file_handler.setFormatter(formatter)
|
|
10
|
+
logger.addHandler(file_handler)
|
|
11
|
+
handler = logging.StreamHandler()
|
|
12
|
+
handler.setLevel(50-(debug_lv*10))#minimun level to show, must be higher or equal than logger's level
|
|
13
|
+
formatter = logging.Formatter('%(asctime)s - %(message)s')
|
|
14
|
+
handler.setFormatter(formatter)
|
|
15
|
+
logger.addHandler(handler)
|
|
16
|
+
return logger"""
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
debug level equivalences from crace and logging
|
|
20
|
+
|
|
21
|
+
debug lv crace | logging lv
|
|
22
|
+
---------------|-----------
|
|
23
|
+
5 | 0 notset
|
|
24
|
+
4 | 10 debug
|
|
25
|
+
3 | 20 info
|
|
26
|
+
2 | 30 warning
|
|
27
|
+
1 | 40 error
|
|
28
|
+
0 | 50 critical
|
|
29
|
+
"""
|