modules.applications.qml.generative_modeling.mappings.library_pennylane.LibraryPennylane

class LibraryPennylane

Bases: LibraryGenerative

__init__()

Constructor method.

Parameters:

name -- Name of the model

Methods

__init__()

Constructor method.

get_available_submodule_options()

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)

Returns the default submodule based on the provided option.

get_depending_parameters(option, config)

If the module has parameters depending on certain options, this method should return the parameters for the given option.

get_execute_circuit(circuit, backend, ...)

This method combines the PennyLane circuit implementation and the selected backend and returns a function that will be called during training.

get_parameter_options()

Returns the configurable settings for the PennyLane Library.

get_requirements()

Returns requirements of this module.

get_submodule(option)

Submodule is instantiated according to the information given in self.sub_options.

postprocess(input_data, config, **kwargs)

This method corresponds to the identity and passes the information of the subsequent module back to the preceding module in the benchmarking process.

preprocess(input_data, config, **kwargs)

Base class for mapping the gate sequence to a library such as Qiskit.

select_backend(config, n_qubits)

This method configures the backend.

sequence_to_circuit(input_data)

Method that maps the gate sequence, that specifies the architecture of a quantum circuit to its PennyLane implementation.

class Config

Bases: TypedDict

Attributes of a valid config.

backend: str
n_shots: int
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
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) QCBM | QGAN | Inference

Returns the default submodule based on the provided option.

Parameters:

option -- The option to select the submodule

Returns:

The selected submodule

Raises:

NotImplemented -- If the provided option is not implemented

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

static get_execute_circuit(circuit: callable, backend: device, config: str, config_dict: dict) tuple[any, any]

This method combines the PennyLane circuit implementation and the selected backend and returns a function that will be called during training.

Parameters:
  • circuit -- PennyLane implementation of the quantum circuit

  • backend -- Configured qiskit backend

  • config -- Name of a backend

  • config_dict -- Dictionary including the number of shots

Returns:

Tuple that contains a method that executes the quantum circuit for a given set of parameters twice

get_parameter_options() dict

Returns the configurable settings for the PennyLane Library.

Returns:

Dictionary with configurable settings.

return {
    "backend": {
        "values": ["default.qubit", "default.qubit.jax", "lightning.qubit", "lightning.gpu"],
        "description": "Which backend do you want to use?"
    },

    "n_shots": {
        "values": [100, 1000, 10000, 1000000],
        "description": "How many shots do you want use for estimating the PMF of the 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

postprocess(input_data: dict, config: dict, **kwargs) tuple[dict, float]

This method corresponds to the identity and passes the information of the subsequent module back to the preceding module in the benchmarking process.

Parameters:
  • input_data -- Collected information of the benchmarking procesS

  • config -- Config specifying the number of qubits of the circuit

  • kwargs -- Optional keyword arguments

Returns:

Tuple with input dictionary and the computation time of the function

preprocess(input_data: dict, config: Config, **kwargs) tuple[dict, float]

Base class for mapping the gate sequence to a library such as Qiskit.

Parameters:
  • input_data -- Collection of information from the previous modules

  • config -- Config specifying the number of qubits of the circuit

  • kwargs -- Optional keyword arguments

Returns:

Tuple including dictionary with the function to execute the quantum circuit on a simulator or quantum hardware and the computation time of the function

static select_backend(config: str, n_qubits: int) any

This method configures the backend.

Parameters:
  • config -- Name of a backend

  • n_qubits -- Number of qubits

Returns:

Configured backend

sequence_to_circuit(input_data: dict) dict

Method that maps the gate sequence, that specifies the architecture of a quantum circuit to its PennyLane implementation.

Parameters:

input_data -- Collected information of the benchmarking process

Returns:

Same dictionary but the gate sequence is replaced by its PennyLane implementation