2024-11-28 15:15:05 -03:00
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import typer
|
|
|
|
from pydantic_core import ValidationError
|
|
|
|
|
|
|
|
from benchmarks.core.config import ConfigParser
|
|
|
|
from benchmarks.deluge.config import DelugeExperimentConfig
|
|
|
|
|
|
|
|
parser = ConfigParser()
|
|
|
|
parser.register(DelugeExperimentConfig)
|
|
|
|
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
|
|
|
|
def _parse_config(config: Path):
|
|
|
|
if not config.exists():
|
|
|
|
print(f'Config file {config} does not exist.')
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2024-11-28 15:52:38 -03:00
|
|
|
with config.open(encoding='utf-8') as infile:
|
2024-11-28 15:15:05 -03:00
|
|
|
try:
|
2024-11-28 15:52:38 -03:00
|
|
|
return parser.parse(infile)
|
2024-11-28 15:15:05 -03:00
|
|
|
except ValidationError as e:
|
|
|
|
print(f'There were errors parsing the config file.')
|
|
|
|
for error in e.errors():
|
|
|
|
print(f' - {error["loc"]}: {error["msg"]} {error["input"]}')
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def list(config: Path):
|
|
|
|
"""
|
|
|
|
Lists the experiments available in CONFIG.
|
|
|
|
"""
|
2024-11-28 15:52:38 -03:00
|
|
|
experiments = _parse_config(config)
|
2024-11-28 15:15:05 -03:00
|
|
|
print(f'Available experiments in {config}:')
|
2024-11-28 15:52:38 -03:00
|
|
|
for experiment in experiments.keys():
|
2024-11-28 15:15:05 -03:00
|
|
|
print(f' - {experiment}')
|
|
|
|
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def run(config: Path, experiment: str):
|
|
|
|
"""
|
|
|
|
Runs the experiment with name EXPERIMENT.
|
|
|
|
"""
|
2024-11-28 15:52:38 -03:00
|
|
|
experiments = _parse_config(config)
|
|
|
|
if experiment not in experiments:
|
2024-11-28 15:15:05 -03:00
|
|
|
print(f'Experiment {experiment} not found in {config}.')
|
|
|
|
sys.exit(-1)
|
2024-11-28 15:52:38 -03:00
|
|
|
experiments[experiment].run()
|
2024-11-28 15:15:05 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app()
|