modules.applications.qml.generative_modeling.training.inference.Inference
- class Inference
Bases:
TrainingGenerativeThis module executes a quantum circuit with parameters of a pretrained model.
- __init__()
Constructor method.
Methods
__init__()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)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.
Returns the configurable settings for this circuit.
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)Method that uses a pretrained model for inference.
- class Config
Bases:
TypedDictAttributes of a valid config.
pretrained: 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
- 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
Returns the configurable settings for this circuit.
- Returns:
Configuration settings for the pretrained model
return { "pretrained": { "values": [False], "custom_input": True, "postproc": str, "description": "Please provide the parameters of a pretrained model." } }
- 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
- start_training(input_data: dict, config: Config, **kwargs: dict) dict
Method that uses a pretrained model for inference.
- Parameters:
input_data -- Dictionary with information needed for inference
config -- Inference settings
kwargs -- Optional additional arguments
- Returns:
Dictionary including the information of previous modules as well as of this module