aqmlator.tuner module


This module contains the classes that use optuna for different kinds of optimizations - mainly model and hyperparameter.


Copyright 2023 ACK Cyfronet AGH. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


This work was supported by the EuroHPC PL project funded at the Smart Growth Operational Programme 2014-2020, Measure 4.2 under the grant agreement no. POIR.04.02.00-00-D014/20-00.


class aqmlator.tuner.HyperparameterTuner(features: Sequence[Sequence[float]], classes: Sequence[int], model: QMLModel, *, study_name: str = 'QML_Hyperparameter_Tuner_', add_uuid: bool = True, n_trials: int = 10, n_cores: int = 1, n_seeds: int = 1)[source]

Bases: OptunaOptimizer

This class contains the optuna-based tuner for ML Training hyperparameters.

TODO TR: Consider renaming this class, as it’s only used by the supervised

learning models (as of now).

A constructor for the HyperparameterTuner class.

Parameters:
  • features – The lists of features of the objects that are used during the training.

  • classes – A list of classes corresponding to the given lists of features.

  • model – A model to be trained.

  • study_name – The name of the optuna study. If the study with this name is already stored in the DB, the tuner will continue the study.

  • add_uuid – Flag for specifying if uuid should be added to the study_name.

  • n_cores – The number of cores that optuna can use. The (default) value \(-1\) means all of them.

  • n_trials – The number of trials after which the search will be finished.

  • n_seeds – Number of seeds checked per optuna trial.

find_hyperparameters() None[source]

Finds the (sub)optimal training hyperparameters.

class aqmlator.tuner.MLTaskType(value)[source]

Bases: StrEnum

BINARY_CLASSIFICATION = 'BINARY_CLASSIFICATION'
CLASSIFICATION = 'CLASSIFICATION'
GROUPING = 'GROUPING'
REGRESSION = 'REGRESSION'
class aqmlator.tuner.ModelFinder(task_type: str, features: Sequence[Sequence[float]] | ndarray[Any, dtype[float32]], classes: Sequence[int] | None = None, *, device: Device | None = None, study_name: str = 'QML_Model_Finder_', add_uuid: bool = True, minimal_accuracy: float = 0.8, n_cores: int = -1, n_trials: int = 100, n_epochs: int = 10, n_seeds: int = 5, coupling_map: List[List[int]] | None = None, d_wave_access: bool = False)[source]

Bases: OptunaOptimizer

A class for finding the best QNN model for given data and task.

A constructor for ModelFinder class.

Parameters:
  • features – Features of the objects to be classified. Their order should correspond to that of classes.

  • classes – Classes of the classified objects. Their order should correspond to that of features.

  • study_name – The name of the optuna study. If the study with this name is already stored in the DB, the finder will continue the study.

  • device – The device on which to run the model.

  • add_uuid – Flag for specifying if uuid should be added to the study_name.

  • minimal_accuracy – Minimal accuracy after which the training will end.

  • n_cores – The number of cores that optuna can use. The (default) value \(-1\) means all of them.

  • n_trials – The number of trials after which the search will be finished.

  • n_epochs – The number of QNN training epochs.

  • n_seeds – Number of seeds checked per optuna trial.

  • coupling_map – A list of connected qubits.

  • d_wave_access – Flag for specifying if the model could be run on the D-Wave machine.

find_model() None[source]

Finds the QNN model that best fits the given data.

class aqmlator.tuner.OptunaOptimizer(features: Sequence[Sequence[float]] | ndarray[Any, dtype[float32]], classes: Sequence[int] | None, *, study_name: str = '', add_uuid: bool = True, n_trials: int = 10, n_cores: int = 1, n_seeds: int = 1)[source]

Bases: ABC

A class for all optuna-based optimizers that takes care of the common boilerplate code, especially in the constructor.

A constructor for the OptunaOptimizer class.

Parameters:
  • features – The lists of features of the objects that are used during the training.

  • classes – A list of classes or function values corresponding to the given lists of features.

  • study_name – The name of the optuna study. If the study with this name is already stored in the DB, the tuner will continue the study.

  • add_uuid – Flag for specifying if uuid should be added to the study_name.

  • n_cores – The number of cores that optuna can use. The (default) value \(-1\) means all of them.

  • n_trials – The number of trials after which the search will be finished.

  • n_seeds – Number of seeds checked per optuna trial.