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

14 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-22 01:18 +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 a SQL DB using the 

6:py:class:`.TunableConfigData` interface. 

7""" 

8 

9import pandas 

10from sqlalchemy.engine import Engine 

11 

12from mlos_bench.storage.base_tunable_config_data import TunableConfigData 

13from mlos_bench.storage.sql.schema import DbSchema 

14 

15 

16class TunableConfigSqlData(TunableConfigData): 

17 """ 

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

19 

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

21 """ 

22 

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

24 super().__init__(tunable_config_id=tunable_config_id) 

25 self._engine = engine 

26 self._schema = schema 

27 

28 @property 

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

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

31 cur_config = conn.execute( 

32 self._schema.config_param.select() 

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

34 .order_by( 

35 self._schema.config_param.c.param_id, 

36 ) 

37 ) 

38 return pandas.DataFrame( 

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

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

41 )