modules.applications.qml.generative_modeling.training.training_generative.TrainingGenerative
- class TrainingGenerative(name: str)
-
The Training module is the base class fot both finding (QCBM) and executing trained models (Inference).
- __init__(name: str)
Constructor method.
- Parameters:
name -- Name of the training instance
Methods
__init__(name)Constructor method.
Gets the list of available options.
get_available_submodules(option)If the module has submodules depending on certain options, this method should adjust the submodule_options accordingly.
get_default_submodule(option)Given an option string by the user, this returns a submodule.
get_depending_parameters(option, config)If the module has parameters depending on certain options, this method should return the parameters for the given option.
Returns the parameters for a given module.
Returns requirements of this module.
get_submodule(option)Submodule is instantiated according to the information given in self.sub_options.
kl_divergence(pmf_model, pmf_target)This function calculates the Kullback-Leibler divergence, that is used as a loss function.
mmd(pmf_model, pmf_target)This function calculates the maximum mean discrepancy, that is used as a loss function.
nll(pmf_model, pmf_target)This function calculates th negative log likelihood, that is used as a loss function.
postprocess(input_data, config, **kwargs)Perform the actual training of the machine learning model.
preprocess(input_data, config, **kwargs)Essential method for the benchmarking process.
sample_from_pmf(pmf, n_shots)This function samples from the probability mass function generated by the quantum circuit.
start_training(input_data, config, **kwargs)This function starts the training of QML model or deploys a pretrained model.
- class Timing
Bases:
objectThis module is an abstraction of time measurement for both CPU and GPU processes.
- start_recording_cpu() None
This is a function to start time measurement on the CPU.
- start_recording_gpu() None
This is a function to start time measurement on the GPU.
- stop_recording_cpu() float
This is a function to stop time measurement on the CPU.
.return: Elapsed time in milliseconds
- stop_recording_gpu() float
This is a function to stop time measurement on the GPU.
- Returns:
Elapsed time in milliseconds
- get_available_submodule_options() list
Gets the list of available options.
- Returns:
List of module options
- get_available_submodules(option: list) list
If the module has submodules depending on certain options, this method should adjust the submodule_options accordingly.
- Parameters:
option -- List of chosen options
- Returns:
List of available submodules
- abstract get_default_submodule(option: str) Core
Given an option string by the user, this returns a submodule.
- Parameters:
option -- String with the chosen submodule
- Returns:
Module of type Core
- get_depending_parameters(option: str, config: dict) dict
If the module has parameters depending on certain options, this method should return the parameters for the given option.
- Parameters:
option -- The chosen option
config -- Current config dictionary
- Returns:
The parameters for the given option
- abstract get_parameter_options() dict
Returns the parameters for a given module.
Should always be in this format:
{ "parameter_name":{ "values":[1, 2, 3], "description":"How many nodes do you need?" }, "parameter_name_2":{ "values":["x", "y"], "description":"Which type of problem do you want?" } }
- Returns:
Available settings for this application
- static get_requirements() list[dict]
Returns requirements of this module.
- Returns:
list of dict with requirements of this module
- get_submodule(option: str) Core
Submodule is instantiated according to the information given in self.sub_options. If self.sub_options is None, get_default_submodule is called as a fallback.
- Parameters:
option -- String with the options
- Returns:
Instance of a module
- kl_divergence(pmf_model: ndarray, pmf_target: ndarray) ndarray
This function calculates the Kullback-Leibler divergence, that is used as a loss function.
- Parameters:
pmf_model -- Probability mass function generated by the quantum circuit
pmf_target -- Probability mass function of the target distribution
- Returns:
Kullback-Leibler divergence
- mmd(pmf_model: ndarray, pmf_target: ndarray) ndarray
This function calculates the maximum mean discrepancy, that is used as a loss function.
- Parameters:
pmf_model -- Probability mass function generated by the quantum circuit
pmf_target -- Probability mass function of the target distribution
- Returns:
Maximum mean discrepancy
- nll(pmf_model: ndarray, pmf_target: ndarray) ndarray
This function calculates th negative log likelihood, that is used as a loss function.
- Parameters:
pmf_model -- Probability mass function generated by the quantum circuit
pmf_target -- Probability mass function of the target distribution
- Returns:
Negative log likelihood
- postprocess(input_data: dict, config: dict, **kwargs) tuple[dict, float]
Perform the actual training of the machine learning model.
- Parameters:
input_data -- Collected information of the benchmarking process
config -- Training settings
kwargs -- Optional additional arguments
- Returns:
Training results and the postprocessing time
- preprocess(input_data: any, config: dict, **kwargs) tuple[any, float]
Essential method for the benchmarking process. This is always executed before traversing down to the next module, passing the data returned by this function.
- Parameters:
input_data -- Data for the module, comes from the parent module if that exists
config -- Config for the module
kwargs -- Optional keyword arguments
- Returns:
The output of the preprocessing and the time it took to preprocess
- sample_from_pmf(pmf: ndarray, n_shots: int) ndarray
This function samples from the probability mass function generated by the quantum circuit.
- Parameters:
pmf -- Probability mass function generated by the quantum circuit
n_shots -- Number of shots
- Returns:
Number of counts in the 2**n_qubits bins
- abstract start_training(input_data: dict, config: any, **kwargs: dict) dict
This function starts the training of QML model or deploys a pretrained model.
- Parameters:
input_data -- A representation of the quantum machine learning model that will be trained
config -- Config specifying the parameters of the training (dict-like Config type defined in children)
kwargs -- Optional additional settings
- Returns:
Solution, the time it took to compute it and some optional additional information