Coverage for mlos_bench/mlos_bench/storage/sql/tunable_config_data.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-07 01:52 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""An interface to access the tunable config data stored in SQL DB.""" 

6 

7import pandas 

8from sqlalchemy import Engine 

9 

10from mlos_bench.storage.base_tunable_config_data import TunableConfigData 

11from mlos_bench.storage.sql.schema import DbSchema 

12 

13 

14class TunableConfigSqlData(TunableConfigData): 

15 """ 

16 SQL interface for accessing the stored experiment benchmark (tunable) config data. 

17 

18 A configuration in this context is the set of tunable parameter values. 

19 """ 

20 

21 def __init__(self, *, engine: Engine, schema: DbSchema, tunable_config_id: int): 

22 super().__init__(tunable_config_id=tunable_config_id) 

23 self._engine = engine 

24 self._schema = schema 

25 

26 @property 

27 def config_df(self) -> pandas.DataFrame: 

28 with self._engine.connect() as conn: 

29 cur_config = conn.execute( 

30 self._schema.config_param.select() 

31 .where(self._schema.config_param.c.config_id == self._tunable_config_id) 

32 .order_by( 

33 self._schema.config_param.c.param_id, 

34 ) 

35 ) 

36 return pandas.DataFrame( 

37 [(row.param_id, row.param_value) for row in cur_config.fetchall()], 

38 columns=["parameter", "value"], 

39 )