Skip to content

Commit

Permalink
API change - create_run_table() removed
Browse files Browse the repository at this point in the history
This change will make it easier for plugins to modify
the base behavior. The `create_run_table` function has been
replaced with `create_run_table_model`
  • Loading branch information
nikosChalk committed Jul 22, 2022
1 parent fc8564c commit 462b563
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions examples/hello-world/RunnerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def __init__(self):

output.console_log("Custom config loaded")

def create_run_table(self) -> List[Dict]:
"""Create and return the run_table here. A run_table is a List (rows) of tuples (columns),
def create_run_table_model(self) -> RunTableModel:
"""Create and return the run_table model here. A run_table is a List (rows) of tuples (columns),
representing each run performed"""
factor1 = FactorModel("example_factor1", ['example_treatment1', 'example_treatment2', 'example_treatment3'])
factor2 = FactorModel("example_factor2", [True, False])
Expand All @@ -63,7 +63,7 @@ def create_run_table(self) -> List[Dict]:
],
data_columns=['avg_cpu', 'avg_mem']
)
return self.run_table_model.generate_experiment_run_table()
return self.run_table_model

def before_experiment(self) -> None:
"""Perform any activity required before starting the experiment here
Expand Down
6 changes: 3 additions & 3 deletions examples/linux-ps-profiling/RunnerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def __init__(self):
self.run_table_model = None # Initialized later
output.console_log("Custom config loaded")

def create_run_table(self) -> List[Dict]:
"""Create and return the run_table here. A run_table is a List (rows) of tuples (columns),
def create_run_table_model(self) -> RunTableModel:
"""Create and return the run_table model here. A run_table is a List (rows) of tuples (columns),
representing each run performed"""
cpu_limit_factor = FactorModel("cpu_limit", [20, 50, 70 ])
pin_core_factor = FactorModel("pin_core" , [True, False])
Expand All @@ -66,7 +66,7 @@ def create_run_table(self) -> List[Dict]:
],
data_columns=['avg_cpu']
)
return self.run_table_model.generate_experiment_run_table()
return self.run_table_model

def before_experiment(self) -> None:
"""Perform any activity required before starting the experiment here
Expand Down
6 changes: 3 additions & 3 deletions experiment-runner/ConfigValidator/Config/RunnerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def __init__(self):

output.console_log("Custom config loaded")

def create_run_table(self) -> List[Dict]:
"""Create and return the run_table here. A run_table is a List (rows) of tuples (columns),
def create_run_table_model(self) -> RunTableModel:
"""Create and return the run_table model here. A run_table is a List (rows) of tuples (columns),
representing each run performed"""
factor1 = FactorModel("example_factor1", ['example_treatment1', 'example_treatment2', 'example_treatment3'])
factor2 = FactorModel("example_factor2", [True, False])
Expand All @@ -64,7 +64,7 @@ def create_run_table(self) -> List[Dict]:
],
data_columns=['avg_cpu', 'avg_mem']
)
return self.run_table_model.generate_experiment_run_table()
return self.run_table_model

def before_experiment(self) -> None:
"""Perform any activity required before starting the experiment here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, config: RunnerConfig, metadata: Metadata):

self.csv_data_manager = CSVOutputManager(self.config.experiment_path)
self.json_data_manager = JSONOutputManager(self.config.experiment_path)
self.run_table = self.config.create_run_table()
self.run_table = self.config.create_run_table_model().generate_experiment_run_table()

# Create experiment output folder, and in case that it exists, check if we can resume
self.restarted = False
Expand Down
12 changes: 6 additions & 6 deletions experiment-runner/Plugins/CodecarbonWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def emission_tracker(online=False, *decargs, **deckwargs):
def emission_tracker_decorator(cls: RunnerConfig.__class__):
data_columns = deckwargs.pop('data_columns', [DataColumns.EMISSIONS])

cls.create_run_table = add_data_columns(data_columns)(cls.create_run_table)
cls.start_measurement = start_emission_tracker(online=online, *decargs, **deckwargs)(cls.start_measurement)
cls.stop_measurement = stop_emission_tracker(cls.stop_measurement)
cls.populate_run_data = populate_data_columns(cls.populate_run_data)
cls.create_run_table_model = add_data_columns(data_columns)(cls.create_run_table_model)
cls.start_measurement = start_emission_tracker(online=online, *decargs, **deckwargs)(cls.start_measurement)
cls.stop_measurement = stop_emission_tracker(cls.stop_measurement)
cls.populate_run_data = populate_data_columns(cls.populate_run_data)

return cls
return emission_tracker_decorator
Expand Down Expand Up @@ -72,10 +72,10 @@ def add_data_columns_decorator(func):
def wrapper(*args, **kwargs):
self: RunnerConfig = args[0]

func(*args, **kwargs) # will set self.run_table_model. Discard result
func(*args, **kwargs) # will set self.run_table_model
for dc in data_cols:
self.run_table_model.get_data_columns().append(dc.name)
return self.run_table_model.generate_experiment_run_table() # FIXME: this is bad
return self.run_table_model
return wrapper
return add_data_columns_decorator

Expand Down
2 changes: 1 addition & 1 deletion experiment-runner/Plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ from Plugins.CodecarbonWrapper import DataColumns as CCDataCols
class RunnerConfig:

@CodecarbonWrapper.add_data_columns([CCDataCols.EMISSIONS, CCDataCols.ENERGY_CONSUMED])
def create_run_table(self):
def create_run_table_model(self):
...

@CodecarbonWrapper.start_emission_tracker(
Expand Down
6 changes: 3 additions & 3 deletions test-standalone/core/arbitrary-objects/RunnerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Test Description:
Test functionality for arbitrary objects as factor levels
* When recovering from a crash, the generated objects from `create_run_table()` should be used
* When recovering from a crash, the generated objects from `create_run_table_model()` should be used
instead of the `str` values found in the stored csv.
'''

Expand Down Expand Up @@ -59,7 +59,7 @@ def __init__(self):

output.console_log("Custom config loaded")

def create_run_table(self) -> List[Dict]:
def create_run_table_model(self) -> RunTableModel:
x1, x2, x3 = CustomObject(1), CustomObject(2), CustomObject(3)

factor1 = FactorModel("example_factor1", [x1, x2, x3])
Expand All @@ -72,7 +72,7 @@ def create_run_table(self) -> List[Dict]:
],
data_columns=['avg_cpu', 'avg_mem']
)
return self.run_table_model.generate_experiment_run_table()
return self.run_table_model

def before_experiment(self) -> None:
output.console_log("Config.before_experiment() called!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self):
])
self.run_table_model = None # Initialized later

def create_run_table(self) -> List[Dict]:
def create_run_table_model(self) -> RunTableModel:
factor1 = FactorModel("example_factor1", ['example_treatment1', 'example_treatment2', 'example_treatment3'])
factor2 = FactorModel("example_factor2", [True, False])
self.run_table_model = RunTableModel(
Expand All @@ -60,7 +60,7 @@ def create_run_table(self) -> List[Dict]:
],
data_columns=['avg_cpu', 'avg_mem']
)
return self.run_table_model.generate_experiment_run_table()
return self.run_table_model

def before_experiment(self) -> None:
output.console_log("Config.before_experiment() called!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self):
self.run_table_model = None # Initialized later

@CodecarbonWrapper.add_data_columns([CCDataCols.EMISSIONS, CCDataCols.ENERGY_CONSUMED])
def create_run_table(self) -> List[Dict]:
def create_run_table_model(self) -> RunTableModel:
factor1 = FactorModel("example_factor1", ['example_treatment1', 'example_treatment2', 'example_treatment3'])
factor2 = FactorModel("example_factor2", [True, False])
self.run_table_model = RunTableModel(
Expand All @@ -57,7 +57,7 @@ def create_run_table(self) -> List[Dict]:
],
data_columns=['avg_cpu', 'avg_mem']
)
return self.run_table_model.generate_experiment_run_table()
return self.run_table_model

def before_experiment(self) -> None:
output.console_log("Config.before_experiment() called!")
Expand Down
8 changes: 4 additions & 4 deletions test/Plugins/test_CodecarbonWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def clear(self):
shutil.rmtree(self.__class__.tmpdir)

@CodecarbonWrapper.add_data_columns([CCDataCols.EMISSIONS, CCDataCols.ENERGY_CONSUMED])
def create_run_table(self):
super().create_run_table()
def create_run_table_model(self):
return super().create_run_table_model()

@CodecarbonWrapper.start_emission_tracker(
country_iso_code="NLD",
Expand All @@ -52,7 +52,7 @@ def populate_run_data(self, context: RunnerContext):

def setUp(self) -> None:
self.runner_config = self.__class__.EmissionTrackerConfig()
self.run_table = self.runner_config.create_run_table()
self.run_table = self.runner_config.create_run_table_model().generate_experiment_run_table()

def tearDown(self) -> None:
self.runner_config.clear()
Expand Down Expand Up @@ -97,7 +97,7 @@ def populate_run_data(self, context: RunnerContext):

def setUp(self) -> None:
self.runner_config = self.__class__.EmissionTrackerConfig()
self.run_table = self.runner_config.create_run_table()
self.run_table = self.runner_config.create_run_table_model().generate_experiment_run_table()

def tearDown(self) -> None:
self.runner_config.clear()
Expand Down

0 comments on commit 462b563

Please sign in to comment.