Run an application using the configuration.
This helper method (1) logs and writes the configuration to the run
directory, (2), configures the benchmark app, (3) creates the engine,
(4) runs the application, and (5) cleans up all resources afterwards.
Note
This function changes the current working directory to
config.run.run_dir
so that all paths are relative to the current
working directory.
Parameters:
Source code in taps/run/main.py
| @_cwd_run_dir
def run(config: Config, run_dir: pathlib.Path) -> None:
"""Run an application using the configuration.
This helper method (1) logs and writes the configuration to the run
directory, (2), configures the benchmark app, (3) creates the engine,
(4) runs the application, and (5) cleans up all resources afterwards.
Note:
This function changes the current working directory to
`config.run.run_dir` so that all paths are relative to the current
working directory.
Args:
config: Benchmark configuration.
run_dir: Run directory to use.
"""
timer = Timer()
timer.start()
logger.log(RUN_LOG_LEVEL, f'Runtime directory: {run_dir}')
_log_config_and_env(config)
logger.log(RUN_LOG_LEVEL, 'Starting benchmark...')
env_vars = config.run.env_vars if config.run.env_vars is not None else {}
with update_environment(env_vars):
with Timer() as app_init_timer:
app = config.app.get_app()
logger.log(
RUN_LOG_LEVEL,
f'Initialized app (name={config.app.name}, '
f'type={type(app).__name__}, '
f'elapsed={app_init_timer.elapsed_s:.3f}s)',
)
with Timer() as engine_init_timer:
engine = config.engine.get_engine()
logger.log(
RUN_LOG_LEVEL,
f'Initialized engine (elapsed={engine_init_timer.elapsed_s:.3f}s)',
)
logger.debug(repr(engine))
with contextlib.closing(app), engine:
logger.log(RUN_LOG_LEVEL, 'Running app...')
with Timer() as app_timer:
app.run(engine=engine, run_dir=run_dir)
logger.log(
RUN_LOG_LEVEL,
f'Finished app (elapsed={app_timer.elapsed_s:.3f}s)',
)
logger.log(RUN_LOG_LEVEL, f'Results saved to {run_dir}')
timer.stop()
logger.log(
RUN_LOG_LEVEL,
f'Finished benchmark (app={config.app.name}, '
f'elapsed={timer.elapsed_s:.3f}s, tasks={engine.tasks_executed})',
)
|