What is QCL?
It stands for Quantum Circuit Learning.
It is basically a hybrid Quantum Classical Machine Learning model.
It is Pennylane and Pytroch integration.
Pennylane for the quantum part of the code and PyTorch for the classical part.
What is PyTorch?
It is an open-source deep learning framework.
It is developed by MetaAI.
Link: PyTorch
How is it done?
The classical input data is encoded into quantum states.
The parameterized quantum circuit processes this data.
The output is passed through a classical layer to get the final results.
Install the required libraries.
Import all the required libraries.
Mount the drive and read the dataset.
Mounting the Google Drive and accessing the dataset from the Google Drive.
These are the steps to mount the Google Drive through code.
First Upload the dataset into the Drive and make note of the dataset path.
When you run the above code cell this particular pop-up will appear. Click "Connect to Google Drive".
Then select the Google Drive account in which the dataset is uploaded.
Select "Continue"
Select "Continue" and the drive will be mounted.
Now, we are preparing the data for the next steps. First, we drop the target variable from the dataset, which is 'Energy consumption,' to create the X set. Then, the target variable is stored in the y separately. Then, define the columns which are categorical and which are numerical. We set up a preprocessing pipeline that scales the numerical features using StandardScaler and applies OneHotEncoder to the categorical features. After that, we split the data into training and testing. The training data is processed, and the test data is transformed using the same preprocessing steps. Finally, we, normalize the target variable y using a standard scaler.
The below function trains the classical machine learning model on the training data and evaluates the performance on both the training and test sets. It calculates metric MSE and R2 for the model and stores the results in a dictionary.
Now, we set up a quantum circuit with four qubits and two layers. Used to encode the input data using the RY gates, apply learnable rotations, and entangle the qubits using the CNOT gates. At the end, it returns the measurements from each qubit for the QML model.
Now, we define the Hybrid Quantum-Classical model. First, it maps classical inputs to quantum format and passes them through the quantum layer using the pennylane. At the end process the quantum outputs with a final linear layer for predictions - all within PyTorch.
Here, we train the QCL model by converting data into PyTorch tensors, setting up the model, and running it through multiple epochs using mini-batches. Tracking of training and test losses is done. In the end, it evaluates the final performance using MSE and R2 scores, and the results are visualized. Finally, a comparison between the classical and the QCL models is done by plotting a graph and a summary table.
RESULTS: