Quantum Neural Networks (QNN)
The Classiq QNN package is integrated with PyTorch so you can definetorch networks with the addition of quantum layers (which are quantum programs).
This topic assumes basic knowledge of classical neural networks.
reshape.
The input and output of each layer is a vector of classical data; for convenience, called a list of floats.
This implies that any quantum layer, assuming the structure of the data transfer between the layers does not change, must take in classical data and return classical data.
This is done by renaming the incoming data as parameters for the quantum program, measuring the quantum layer, and applying classical post-processing calculations.
Examples
One example for post-processing outputs of a quantum layer is returning a single number between0 and 1, indicating the confidence of a single choice.
This is common in cases of binary classification where a single qubit is measured and the output of the quantum layer is the amount of |0> measured divided by the total number of measurements.
Another example for post-processing is returning the probability (or amplitude) of each result.
If the measurement result is this:
Parameters: Inputs Versus Weights
A complete quantum layer takes two types of parameters: “inputs” and “weights”. The “input” parameters handle the encoding of the data (the classicallist of floats), whereas the “weight” parameters undergo gradient descent in the usual NN way.
The “input” parameters are usually handled by the first sub-layer, while the “weight” parameters are usually handled by the rest of the sub-layers.
The Classiq engine distinguishes between the two types of parameters by their initial name:
input_somethingori_somethingfor inputsweight_somethingorw_somethingfor weights
Classiq Engine API
QLayer
Classiq exports the QLayer object, which inherits from torch.nn.Module (like most objects in the torch.nn namespace), and it acts accordingly.
For example:
QLayer object, with explanations about the parameter it gets, are described here.
Datasets
Classiq provides two datasets for play-testing examples.-
“NOT” takes in a single-qubit state (either |0> or |1>) and returns an -qubit state of all-ones or all-zeros, respectively. For example, for :
0 -> |11>,1 -> |00>. -
“XOR” takes in an -qubit state and returns a single classical bit, equal to the bitwise-xor of all the bits from the input state. For example,
101 -> 0,10101 -> 1,10 -> 1,11 -> 0.