A Comparative Analysis of Hybrid-Quantum Classical Neural Networks
A Comparative Analysis of Hybrid-Quantum Classical Neural Networks
Networks
Kamila Zaman1,2,* , Tasnim Ahmed1,2,* , Muhammad Abdullah Hanif1,2 , Alberto Marchisio1,2 , and
Muhammad Shafique1,2 ,
1 eBrain Lab, Division of Engineering, New York University Abu Dhabi (NYUAD), Abu Dhabi, UAE
2 Center for Quantum and Topological Systems (CQTS), NYUAD Research Institute, NYUAD, Abu Dhabi, UAE
{kz2137,tasnim.ahmed,mh6117,alberto.marchisio,muhammad.shafique}@nyu.edu
ABSTRACT
arXiv:2402.10540v1 [quant-ph] 16 Feb 2024
1 INTRODUCTION processing for machine learning tasks, opening new avenues for
Merging Quantum Computing (QC) with Machine Learning algorithm and architecture exploration [1]. The most renowned
(ML) forms the emerging Quantum Machine Learning (QML) HQML algorithms employ variational quantum circuits, featuring
paradigm [7, 8, 11, 12]. It represents an excellent opportunity for parameterized quantum gates optimized by classical computers
researchers and industries to make phenomenal discoveries and to achieve specific goals. These variational quantum circuits
unravel efficient ways to solve complex real-world problems with in QML, known as Quantum Neural Networks (QNNs), hold
significant direction towards practicality and improved accuracy significant promise due to their expressiveness and reduced
compared to classical systems. QML opens new avenues for the trainable parameters, garnering considerable development interest.
community to discover, build, and align their designs to different Given the recent breakthroughs of classical algorithms such as
levels of the quantum stack. However, the currently developed Convolutional Neural Networks (CNNs) for image classification
Noisy-Intermediate Scale Quantum (NISQ) devices [9] have a tasks, numerous QNN architectures have been developed for
limited number of qubits, with small-scale resilience to noise, classification tasks. However, those architectures are either
therefore, making it difficult to develop and practically realize the implemented as basic building blocks or lack the verification
potential of standalone quantum machine learning algorithms. of their usability against a benchmark model for classification
The limitation of NISQ devices has motivated the development of tasks. The observations in Figure 1, based on our implementation
hybrid quantum-classical machine learning algorithms (HQML), of permutations of two different algorithms, show that different
which are NISQ-compatible algorithms. architectures of the same algorithms have different impacts
HQML algorithms have emerged as an important paradigm on classification tasks. Thus, it is imperative to explore the
that amalgamates the power of both classical and quantum architectures, applications, and usefulness of QNN algorithms and
evaluate their accuracy to identify efficient model configurations
*These authors contributed equally to this work. that can be deemed as reference benchmarks for future research.
Methodology for analysing Classical Input
Evaluation
HQML Algorithms
HQML Models Comparison Quantum Convolution Quantum ResNet Quanvolution Neural
(QuanNN, QCNN & Data Preprocessing between 3 HQML Neural Network (QCNN) (QResNet) Network (QuanNN)
QResNet) algorithms
Convolution Layer Classical
Entangling Layer
Pretrained Quantum Encoding
Variations Interpreting Classical Pooling
ResNet18
results to analyse
QC Frameworks Circuit Layer
the performance Quantum Encoding
(Qiskit & PennyLane) Repetition Quantum Encoding Quanvolution Layer
correlation with
Quantum (Quantum Circuit
Qubit Count model variations
Convolution Kernel)
Variations Quantum Circuit
Quantum Pooling Layers
Classical Output
In this paper, we explore three different QNN algorithms
amongst the pool of hybrid algorithms, namely, Quanvolutional
Neural Networks [5], Quantum Convolutional Neural Figure 3: Pipeline of the implemented hybrid QML
Networks [2], and Quantum ResNet [6] and perform an extensive algorithms. Each model utilizes a classical fully connected
comparative analysis. Our methodology first involves identifying layer to transform quantum circuit measurement into
efficient architectures amongst the commonly used QNNs and classification probabilities. In the QCNN, classical
understanding their practical utility for classification tasks. Then convolutional and pooling layers are used for image
we assess how variations of such algorithms impact their accuracy downsizing to match the qubit count of a circuit.
and robustness under architectural permutations of each algorithm.
The architectural permutations are based on the implementation
of interchangeable variational circuit layers over different qubit 2.1 Quanvolutional Neural Networks
counts, varying repetition of the layers, and considering their
The Quanvolutional Neural Network (QuanNN) is an innovative
optimal placement. By implementing the varied models, we
hybrid quantum-classical architecture developed in [5], which
evaluate the performance of QNNs based on the accuracy of
enhances the capabilities of classical CNNs by harnessing the
the training process, which provides us with an understanding
potential of quantum computation. This architecture introduces
of hybrid quantum-classical convergence in correlation with
a new type of transformation layer called the quanvolutional
our experimental approach. Such a comprehensive analysis is
layer, akin to classical convolutional layers, composed of
necessary to establish an understanding of the correlation between
multiple quanvolutional filters which locally transform input
circuit architectures, their robustness, and utility in QML.
data, extracting valuable features for classification. These
filters correspond to a certain circuit design, which can either
1.1 Our Novel Contributions
be generated randomly or based on a specific entanglement,
An overview of our novel contributions is shown in Figure 2. Their namely Basic Entangling or Strongly Entangling. The reason
brief descriptions with key features is presented below. we chose the QuanNN as one of our benchmarking models is
• We propose a methodology to investigate QNN models’ circuit because of its generalizability which can be achieved by adhering
permutations and their effect on the accuracy for classification to the following conditions: specifying an arbitrary integer
tasks. (Section 3) number of quanvolutional filters in each layer, stacking multiple
• We analyze the effect of different circuit layer variations1 , quanvolutional layers in the network, defining layer-specific
namely, Random Circuit, Basic Entangling, and Strongly parameters like encoding method, entanglement, and average
Entangling. (Section 4.2) quantum gates per qubit in the quantum circuit. To formalize
• We investigate the repetition of different layers to analyze the classical data transformation using quanvolutional filters:
effect of circuit depth and complexity. (Section 4.3) (1) Start with a single filter q operating on subsections ux of dataset
• We test the scalability of the algorithms by varying qubit counts images.
(Section 4.4) (2) Encode ux into an initialized state ix using an encoding
function e.
2 SELECTED HYBRID QML ALGORITHMS (3) Apply the quantum circuit to ix, producing an output quantum
An overview of the hybrid QML algorithms is shown in Figure 3. state ox.
A brief description of the key features of each algorithm and their (4) Decode ox to ensure consistent outputs, resulting in the final
implementations is presented in the following paragraphs. decoded state fx.
(5) This entire process, denoted as the “quanvolutional filter
1 The circuit variations are studied only for QNN models that support different types transformation” Q, is fx = Q(ux, e, q, d).
of entanglement.
2
Quantum Model Configurations Trained HQML Models
.
QC Frameworks Quantum
..
Encoding Quantum Layer Variations Quantum Layer Variations
..
.
|0.4⟩ U(θ1)
Algorithms Qubits
Entangling Layers .
HQML Models Layers Repetition
|0.1⟩
.
U(θ2)
QuanNN 4&9 Basic,
1, 2, 3, 4,
|0.5⟩ U(θ3)
Random &
5&6 ..
Data Preprocessing QResNet 4&9 Strong
.
|0.2⟩ U(θ4)
. QCNN 4&8
Basic Entangling &
Pooling Layers
..
Evaluation .
..
.
..
.
[x1, x2, x3, x4]
2.2 Quantum Convolutional Neural Networks outcomes demonstrate the QResNet’s superior capability of
Similar to the QuanNN, the Quantum Convolutional Neural learning an unknown unitary transformation and its enhanced
Network (QCNN) is a QML algorithm inspired by CNNs that was robustness with noisy data, compared to state-of-the-art methods.
introduced in [2]. Unlike the QuanNN, the QCNN does not have These findings motivate us to further explore and fine-tune this
room for lots of circuit design variations. The QCNN has a fully promising architecture. Our choice of the QResNet stems from our
quantum implementation of convolutional and pooling layers. desire to test this HQML architecture and its impact on pre-trained
We chose this architecture in our experiments because it is one classical models.
of the state-of-the-art QML models and the classical counterpart
represents the state-of-the-art in classical image recognition. 3 COMPARATIVE ANALYSIS METHODOLOGY
Moreover, it is important to note that the QCNN presented
in [2] makes use of only 𝑂 (𝑙𝑜𝑔(𝑁 )) variational parameters for With the aim of understanding hybrid-quantum classical neural
input sizes of 𝑁 qubits. This allows for its efficient training and networks in-depth, we divide our problem into interdependent
implementation on realistic, near-term quantum devices. experimental sections as shown in Figure 4. The sectioning allows
The basic structure of the QCNN includes an input encoding us to identify areas of possible efficient implementation and
circuit layer, a convolutional circuit layer, a pooling circuit layer, improvements for the HQML algorithms discussed in Section 2.
and a circuit measurement layer, each composed of parametric
quantum gates. It is categorized as an HQML algorithm because it 3.1 Overview of Analyses
uses classical optimization techniques to update the parameterized
Our experimental sections are summarized in the Quantum Layer
gate weights. In the quantum convolutional and pooling layers,
Variations table in the Quantum Model Configurations group of
the interactions between quantum bits can effectively extract
Figure 4. For each algorithm, we analyze the impact of different
features from the input data based on the types of gates and
architectural permutations based on:
their placement in each layer. Given the current NISQ devices,
the QCNN is limited in terms of scalability and can only be • Entanglement variation of quantum circuit: The predefined
implemented with a small number of qubits. Therefore, it requires circuit structure of QuanNN and QResNet enables us to change
classical layers for downsizing large inputs to match the qubit size. the entanglement type of the circuit. Each circuit has its own
In our implementation, we employ single classical convolution and orientation of CNOT gates and parameterized corresponding to
pooling layers for input downsizing, without loss of key features. the strength of their entanglement. Whereas for QCNN, there is
no room for changing the entanglement type of the circuit, since
2.3 Quantum ResNet it follows the structure defined in [2].
Our decision to employ the Quantum ResNet (QResNet) algorithm • Layer count variation: For each algorithm, a circuit can
was inspired by [6], which introduced a hybrid quantum-classical be applied multiple times to an input, which corresponds to
strategy for deep residual learning. The primary challenge in understanding how the varying depth of a quantum circuit
this approach is to establish a connection between the residual affects the model accuracy.
block structure and the quantum processing layers. In our specific • Qubit count variation: The strength and capability of a
context, our focus lies in experimenting with various quantum circuit depends on the number of qubits it has. Hence, in our
layer types. We delve into an analysis of potential methods and experiments, we vary the qubit counts in the architecture to
variations that combine residual learning with quantum machine analyze how the variation correlates with the models’ learning
learning. Notably, the work in [4] emphasizes that experimental curve and accuracy.
3
3.2 Comparison Metrics Table 1: Training Environment Specifications
We intentionally made our experimental setup simple and precise,
Algorithm Experiment Name
to gain more understanding about how different independent
Software FrameWork PennyLane(PL), Qiskit(QK)
parameters of a circuit’s design of our selection algorithms can
Back-End Simulator lightning.qubit(PL), qasm_simulator(QK)
influence their accuracy. To understand the contribution and
Back-End Machine NVIDIA RTX 6000 Ada
convergence behaviours of the aforementioned variations, we
Deep-Learning Interface Pytorch
focus on analyzing the correlation between a model’s accuracy by
Data-set MNIST [3]
studying their classical accuracies in relation to the learning curve
Training Samples, Testing Samples PL: (100, 100), QK: (500, 100)
attained over the training progress.
Epoch, Batch-Size, LR 5, 5, 0.01
Note: the QCNN is not presented in this comparison because only the circuit depth does not have enough impact on these models’
the Basic Entangling circuit can be implemented in this architecture. accuracy (see labels a, b and c). However, it is quite evident for
QCNN models that increasing the number of layers has a positive
4.3 Results: Layer Count Variations correlation with the accuracy (see label d).
Figure 7 shows the accuracy of the QResNet and QuanNN models Figure 9 shows the learning curve for the QuanNN with Basic
with varying number of layers implemented in PennyLane. From Entangling for different layers implemented in PennyLane. For
the results, we can gauge that there is minor difference between 2, 1 layer, the learning curve is constant throughout and little
3, and 4 layers for QResNet models (see labels b and c). Moreover, improvement is observed (see label c). For more than one layer, we
adding more than 4 layers to the QuanNN does not always can observe that the learning improves with increasing the number
contribute to increasing the accuracy (see labels a and e). For the of layers. However, the optimal peak is until 4 layers (see label b),
QResNet, it can be observed that the accuracy increases quite because beyond that the learning curve drops to being close to
significantly for the QResNet models with 4, 5, and 6 layers (see the 1-layer curve (see label a). Nonetheless, a steady and gradual
d, e, and f), more specifically for circuit with 4 layers. Based on improvement in accuracy is observed for more than one layer.
this observation, we conducted the remaining experiments with For the models implemented in Qiskit, as shown in Figure 10,
4 layers in places where no layer variation was involved. Even we can observe that QCNN models with 3 layers have the highest
though the accuracy of the QResNet is lower than the QuanNN, accuracy towards the end of the first epoch (see label a), however,
the algorithm has some potential because it can improve the with a very steadily increasing learning curve (see label c). As for
accuracy for increasing the number of layers (see labels d and f). the QuanNN models, although the initial accuracy is lower than
In Figure 8, we can observe that the QuanNN and QResNet the QCNN 3L, the models have a rapidly increasing learning curve.
models implemented in Qiskit do not have an overall trend with Moreover, we can see that the learning curve for the QuanNN
respect to increasing the number of layers, which indicates that models peak only until 5 layers (QuanNN 5L), because beyond that,
5
Figure 12: Qiskit: Qubit Count variations across different
entangling circuits for QuanNN, QResNet, and QCNN. The
Figure 10: Qiskit: Initial learning behaviour of different Basic
QCNN accuracy positively correlates with the increasing
Entangling layer variation counts.
number of qubits.