6.6. pilotscope.PilotEvent

class Event(config)[source]

Bases: abc.ABC

Abstract base class for an event.

This class provides the base structure for different event types in an application, and is meant to be subclassed to create concrete event implementations.

__init__(config)[source]
Parameters

config – The configuration of PilotScope.

class QueryFinishEvent(config, interval_count=1)[source]

Bases: pilotscope.PilotEvent.Event, abc.ABC

The process function will be called when interval_count query is finished.

__init__(config, interval_count=1)[source]
Parameters
  • config – The configuration of PilotScope.

  • interval_count – This event will be triggered when per interval_count query is finished.

abstract process(db_controller: pilotscope.DBController.BaseDBController.BaseDBController, data_manager: pilotscope.DataManager.DataManager.DataManager)[source]

This function will be called when interval_count query is finished. The user can implement the function to define the process logic.

Parameters
  • db_controller – A db_controller initialized by the user’s PilotConfig registered in PilotScheduler.

  • data_manager – A data_manager initialized by the user’s PilotConfig registered in PilotScheduler.

class WorkloadBeforeEvent(config, enable=True)[source]

Bases: pilotscope.PilotEvent.Event, abc.ABC

The process function will be called before start to deal with first SQL query of a workload.

__init__(config, enable=True)[source]
Parameters
  • config – The configuration of PilotScope.

  • enable – The event will be triggered when the value is True.

abstract process(db_controller: pilotscope.DBController.BaseDBController.BaseDBController, data_manager: pilotscope.DataManager.DataManager.DataManager)[source]

This function will be called before start to deal with first SQL query of a workload, i.e., the first call to PilotScheduler.execute(). The user can implement the function to define the process logic.

Parameters
  • db_controller – A db_controller initialized by the user’s PilotConfig registered in PilotScheduler.

  • data_manager – A data_manager initialized by the user’s PilotConfig registered in PilotScheduler.

class PeriodicModelUpdateEvent(config, interval_count, pilot_model: Optional[pilotscope.PilotModel.PilotModel] = None, execute_on_init=True)[source]

Bases: pilotscope.PilotEvent.QueryFinishEvent, abc.ABC

The user can inherit this class to implement a periodic model update event.

__init__(config, interval_count, pilot_model: Optional[pilotscope.PilotModel.PilotModel] = None, execute_on_init=True)[source]
Parameters
  • config – The configuration of PilotScope.

  • interval_count – This event will be triggered when per interval_count query is finished.

  • pilot_model – The pilot model to be updated.

  • execute_on_init – Whether to execute the custom_model_update function when the PilotScheduler is initialized.

process(db_controller: pilotscope.DBController.BaseDBController.BaseDBController, data_manager: pilotscope.DataManager.DataManager.DataManager)[source]

This function will be called when interval_count query is finished. The user can implement the function to define the process logic.

Parameters
  • db_controller – A db_controller initialized by the user’s PilotConfig registered in PilotScheduler.

  • data_manager – A data_manager initialized by the user’s PilotConfig registered in PilotScheduler.

abstract custom_model_update(pilot_model: pilotscope.PilotModel.PilotModel, db_controller: pilotscope.DBController.BaseDBController.BaseDBController, data_manager: pilotscope.DataManager.DataManager.DataManager)[source]

The user can implement the function to define the process logic of model update. PilotScope will call this function periodically (i.e., per interval_count queries) for model update. You should to return the updated user model, then PilotScope will save it automatically.

Parameters
  • pilot_model – The pilot model to be updated.

  • db_controller – The database controller to be used for the update operations.

  • data_manager – The data manager that provides access to the application’s data.

Returns

The updated user model (i.e., pilot_model.model).

class PretrainingModelEvent(config: pilotscope.PilotConfig.PilotConfig, bind_pilot_model: pilotscope.PilotModel.PilotModel, data_saving_table, enable_collection=True, enable_training=True)[source]

Bases: pilotscope.PilotEvent.Event, abc.ABC

A pretraining model event is an event that is used to collect data nad pretrain a model before the application starts.

__init__(config: pilotscope.PilotConfig.PilotConfig, bind_pilot_model: pilotscope.PilotModel.PilotModel, data_saving_table, enable_collection=True, enable_training=True)[source]
Parameters
  • config – The configuration of PilotScope.

  • bind_pilot_model – The pilot model to be pre-trained.

  • data_saving_table – The table to save the collected data.

  • enable_collection – A flag indicating whether to enable data collection.

  • enable_training – A flag indicating whether to enable model training.

abstract iterative_data_collection(db_controller: pilotscope.DBController.BaseDBController.BaseDBController, train_data_manager: pilotscope.DataManager.DataManager.DataManager)[source]

This user should implement this function to define the iterative process of custom data collection. Each iteration should return a list where each item is a dict indicating each column’s name and value. All column names should be the same as the columns of self.data_saving_table. PilotScope will save these data into the specified table self.data_saving_table automatically. In addition, this function should return a bool value to indicate whether the iteration should be terminated.

Parameters
  • db_controller – The object that controls the database connection.

  • train_data_manager – The object that manages the training data.

Return two values

A list where each item is a dict indicate each column’s value and a bool value indicate whether the iteration should be terminated.

abstract custom_model_training(bind_pilot_model: pilotscope.PilotModel.PilotModel, db_controller: pilotscope.DBController.BaseDBController.BaseDBController, data_manager: pilotscope.DataManager.DataManager.DataManager)[source]

This user should implement this function to define the custom logic for training the model. PilotScope will call this function after the data collection is finished. You should return the updated user model, then PilotScope will save it automatically.

Parameters
  • bind_pilot_model – The model to be trained.

  • db_controller – The object that controls the database connection.

  • data_manager – The object that manages the data used for training the model.

Returns

The updated user model (i.e., bind_pilot_model.model).