Datasets
Pytorch provides two classes:DataSet and DataLoader.
If you’re not familiar with them, please review them here
Classiq provides two simple datasets, which are mainly used in our examples.
They can be found in classiq/applications/qnn/data_sets.py.
DatasetNot
This dataset is used for training a network to learn the “NOT” operation. More specifically, learning the angle to a parametrizedRx gate (spoiler - the correct answer is pi).
This dataset has 2 items:
- the data is
|00...0>, the label is|11...1>. - the data is
|11...1>, the label is|00...0>.
def DatasetNot.__init__(self, n: int, ...)).
Transformers
Additionally, we provide 2Transforms for this class. (Their PyTorch documentation can be found here), which serve our example.
Note that these transformers are automatically used.
Feel free to keep reading about them, though this is not mandatory.
In our example, we wish to
A) encode the input state onto the quantum circle
B) execute the PQC
C) measure the PQC
D) post-process the measurement results
Our transformers help steps A and D.
First, state_to_weights transforms the state, into parameters for the encoding Rx gates. This is used for step A
In other words, the state |0> is transformed into the angle 0, and the state |1> is transformed into the angle pi.
Second, state_to_label transforms the expected output state into a single float number.
More specifically, since we generate this data, we set the expected output state to be a pure state (in the Z basis).
Additionally, we define the post-processing to return the probability of measuring |00...0> in the output state.
Thus, for the output |00...0>, the post processed output is 1, corresponding to 100%, and for the output |11...1>, the post processed output is 0.
DatasetXor
This dataset is used for training a network to learn the “XOR” operation. This may take, similar toDatasetNot, the amount of qubits in the constructor.
The “XOR” operation on more than 2 inputs is defined as “a quantum program that outputs a 1 when the number of 1s at its inputs is odd, and a 0 when the number of incoming 1s is even” (credit: wikipedia)