Coverage for mlos_bench/mlos_bench/storage/sql/tunable_config_data.py: 100%
15 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""
6An interface to access the tunable config data stored in SQL DB.
7"""
9import pandas
10from sqlalchemy import Engine
12from mlos_bench.storage.base_tunable_config_data import TunableConfigData
13from mlos_bench.storage.sql.schema import DbSchema
16class TunableConfigSqlData(TunableConfigData):
17 """
18 SQL interface for accessing the stored experiment benchmark (tunable) config data.
20 A configuration in this context is the set of tunable parameter values.
21 """
23 def __init__(self, *,
24 engine: Engine,
25 schema: DbSchema,
26 tunable_config_id: int):
27 super().__init__(tunable_config_id=tunable_config_id)
28 self._engine = engine
29 self._schema = schema
31 @property
32 def config_df(self) -> pandas.DataFrame:
33 with self._engine.connect() as conn:
34 cur_config = conn.execute(
35 self._schema.config_param.select().where(
36 self._schema.config_param.c.config_id == self._tunable_config_id
37 ).order_by(
38 self._schema.config_param.c.param_id,
39 )
40 )
41 return pandas.DataFrame(
42 [(row.param_id, row.param_value) for row in cur_config.fetchall()],
43 columns=['parameter', 'value'])