generated from S2-group/robot-runner
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
462b563
commit 0039fd5
Showing
8 changed files
with
208 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
from copy import deepcopy | ||
import shutil | ||
from ConfigValidator.Config.RunnerConfig import RunnerConfig as OriginalRunnerConfig | ||
from ProgressManager.Output.CSVOutputManager import CSVOutputManager | ||
from ProgressManager.RunTable.Models.RunProgress import RunProgress | ||
|
||
import TestUtilities | ||
|
||
if __name__ == '__main__': | ||
TEST_DIR = TestUtilities.get_test_dir(__file__) | ||
|
||
config_file = TestUtilities.load_and_get_config_file_as_module(TEST_DIR) | ||
RunnerConfig: OriginalRunnerConfig = config_file.RunnerConfig | ||
|
||
csv_data_manager = CSVOutputManager(RunnerConfig.results_output_path / RunnerConfig.name) | ||
run_table = csv_data_manager.read_run_table() | ||
|
||
# keep old successful run table for comparison in the validator | ||
shutil.move(csv_data_manager._experiment_path / 'run_table.csv', csv_data_manager._experiment_path / 'run_table.old.csv') | ||
|
||
for row in run_table: | ||
if row['__run_id'] in ['run_2', 'run_5']: | ||
row['__done'] = RunProgress.TODO | ||
row['avg_cpu'] = 0 | ||
csv_data_manager.write_run_table(run_table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from EventManager.Models.RunnerEvents import RunnerEvents | ||
from EventManager.EventSubscriptionController import EventSubscriptionController | ||
from ConfigValidator.Config.Models.RunTableModel import RunTableModel | ||
from ConfigValidator.Config.Models.FactorModel import FactorModel | ||
from ConfigValidator.Config.Models.RunnerContext import RunnerContext | ||
from ConfigValidator.Config.Models.OperationType import OperationType | ||
from ExtendedTyping.Typing import SupportsStr | ||
from ProgressManager.Output.OutputProcedure import OutputProcedure as output | ||
|
||
from typing import Dict, List, Any, Optional | ||
from pathlib import Path | ||
from os.path import dirname, realpath | ||
|
||
''' | ||
Test Description: | ||
Test functionality for shuffling | ||
* When recovering from a crash, the order of the run table should remain the same | ||
''' | ||
|
||
class RunnerConfig: | ||
ROOT_DIR = Path(dirname(realpath(__file__))) | ||
|
||
# ================================ USER SPECIFIC CONFIG ================================ | ||
name: str = "new_runner_experiment" | ||
results_output_path: Path = ROOT_DIR / 'experiments' | ||
operation_type: OperationType = OperationType.AUTO | ||
time_between_runs_in_ms: int = 100 | ||
|
||
def __init__(self): | ||
"""Executes immediately after program start, on config load""" | ||
|
||
EventSubscriptionController.subscribe_to_multiple_events([ | ||
(RunnerEvents.BEFORE_EXPERIMENT, self.before_experiment), | ||
(RunnerEvents.BEFORE_RUN , self.before_run ), | ||
(RunnerEvents.START_RUN , self.start_run ), | ||
(RunnerEvents.START_MEASUREMENT, self.start_measurement), | ||
(RunnerEvents.INTERACT , self.interact ), | ||
(RunnerEvents.STOP_MEASUREMENT , self.stop_measurement ), | ||
(RunnerEvents.STOP_RUN , self.stop_run ), | ||
(RunnerEvents.POPULATE_RUN_DATA, self.populate_run_data), | ||
(RunnerEvents.AFTER_EXPERIMENT , self.after_experiment ) | ||
]) | ||
self.run_table_model = None # Initialized later | ||
|
||
output.console_log("Custom config loaded") | ||
|
||
def create_run_table_model(self) -> RunTableModel: | ||
factor1 = FactorModel("example_factor1", ["level1", "level2", "level3"]) | ||
factor2 = FactorModel("example_factor2", [True, False]) | ||
self.run_table_model = RunTableModel( | ||
factors=[factor1, factor2], | ||
data_columns=['avg_cpu', 'avg_mem'], | ||
shuffle=True | ||
) | ||
return self.run_table_model | ||
|
||
def before_experiment(self) -> None: | ||
output.console_log("Config.before_experiment() called!") | ||
|
||
def before_run(self) -> None: | ||
output.console_log("Config.before_run() called!") | ||
|
||
def start_run(self, context: RunnerContext) -> None: | ||
output.console_log("Config.start_run() called!") | ||
|
||
def start_measurement(self, context: RunnerContext) -> None: | ||
output.console_log("Config.start_measurement() called!") | ||
|
||
def interact(self, context: RunnerContext) -> None: | ||
output.console_log("Config.interact() called!") | ||
|
||
def stop_measurement(self, context: RunnerContext) -> None: | ||
output.console_log("Config.stop_measurement called!") | ||
|
||
def stop_run(self, context: RunnerContext) -> None: | ||
output.console_log("Config.stop_run() called!") | ||
|
||
def populate_run_data(self, context: RunnerContext) -> Optional[Dict[str, SupportsStr]]: | ||
output.console_log("Config.populate_run_data() called!") | ||
return { | ||
'avg_cpu': 13, | ||
'avg_mem': 18.1 | ||
} | ||
|
||
def after_experiment(self) -> None: | ||
output.console_log("Config.after_experiment() called!") | ||
|
||
# ================================ DO NOT ALTER BELOW THIS LINE ================================ | ||
experiment_path: Path = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
import csv | ||
|
||
from ConfigValidator.Config.RunnerConfig import RunnerConfig as OriginalRunnerConfig | ||
from ProgressManager.Output.CSVOutputManager import CSVOutputManager | ||
from ProgressManager.RunTable.Models.RunProgress import RunProgress | ||
|
||
import TestUtilities | ||
|
||
if __name__ == 'main': | ||
TEST_DIR = TestUtilities.get_test_dir(__file__) | ||
|
||
config_file = TestUtilities.load_and_get_config_file_as_module(TEST_DIR) | ||
RunnerConfig: OriginalRunnerConfig = config_file.RunnerConfig | ||
|
||
with open(RunnerConfig.results_output_path / RunnerConfig.name / 'run_table.old.csv') as f: | ||
old = f.read() # this is before the crash. | ||
with open(RunnerConfig.results_output_path / RunnerConfig.name / 'run_table.csv') as f: | ||
new = f.read() | ||
assert(old == new) | ||
|
||
csv_data_manager = CSVOutputManager(RunnerConfig.results_output_path / RunnerConfig.name) | ||
run_table = csv_data_manager.read_run_table() | ||
for row in run_table: | ||
assert(row['__done']) == RunProgress.DONE.name | ||
assert(int(row['avg_cpu'])) == 13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters