modules.applications.qml.generative_modeling.training.qcbm.QCBM
- class QCBM
Bases:
TrainingGenerativeThis module optimizes the parameters of quantum circuit using CMA-ES. This training method is referred to as quantum circuit born machine (QCBM).
- __init__()
Constructor method.
Methods
__init__()Constructor method.
data_visualization(loss_epoch, pmfs_model, ...)Visualizes the data and metrics for training.
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)Raises ValueError as this module has no submodules.
get_depending_parameters(option, config)If the module has parameters depending on certain options, this method should return the parameters for the given option.
This function returns the configurable settings for the quantum circuit born machine.
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.
setup_training(input_data, config)Method to configure the training setup including CMA-ES and tensorboard.
start_training(input_data, config, **kwargs)This function finds the best parameters of the circuit on a transformed problem instance and returns a solution.
- class Config
Bases:
TypedDictAttributes of a valid config.
population_size: int max_evaluations: int sigma: float pretrained: str loss: str
- clear() None. Remove all items from D.
- copy() a shallow copy of D
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values
- 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
- data_visualization(loss_epoch: ndarray, pmfs_model: ndarray, samples: any, epoch: int) ndarray
Visualizes the data and metrics for training.
- Parameters:
loss_epoch -- Loss for the current epoch
pmfs_model -- The probability mass functions from the model
samples -- The samples from the model
epoch -- The current epoch number
- Returns:
Best probability mass function for visualization
- 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
- get_default_submodule(option: str) Core
Raises ValueError as this module has no submodules.
- Parameters:
option -- Option name
- Raises:
ValueError -- If called, since this module has no submodules
- 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
- get_parameter_options() dict
This function returns the configurable settings for the quantum circuit born machine.
- Returns:
Configuration settings for QCBM
return { "population_size": { "values": [5, 10, 100, 200, 10000], "description": "What population size do you want?" }, "max_evaluations": { "values": [100, 1000, 20000, 100000], "description": "What should be the maximum number of evaluations?" }, "sigma": { "values": [0.01, 0.5, 1, 2], "description": "Which sigma would you like to use?" }, "pretrained": { "values": [False], "custom_input": True, "postproc": str, "description": "Please provide the parameters of a pretrained model." }, "loss": { "values": ["KL", "NLL"], "description": "Which loss function do you want to use?" } }
- 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
- setup_training(input_data: dict, config: Config) tuple[float, dict]
Method to configure the training setup including CMA-ES and tensorboard.
- Parameters:
input_data -- A representation of the quantum machine learning model that will be trained
config -- Config specifying the parameters of the training
- Returns:
Random initial parameter and options for CMA-ES
- start_training(input_data: dict, config: dict, **kwargs: dict) dict
This function finds the best parameters of the circuit on a transformed problem instance and returns a solution.
- Parameters:
input_data -- A representation of the quantum machine learning model that will be trained
config -- Config specifying the parameters of the training
kwargs -- Optional additional settings
- Returns:
Dictionary including the information of previous modules as well as of the training