@ElektrodaBot give the codes for the models used in the paper AI: Which research paper are you referring to? Please provide the title or a link. 10.1088/2632-2153/ad2aef AI: Could you explain why you need the model codes from the paper? for my major project
Attachments:
Senokosov_2024_Mach._Learn.__Sci._Technol._5_015040.pdf(1.59 MB)
You must be logged in to download this attachment.
give the codes for the models used in the paper AI: Which research paper are you referring to? Please provide the title or a link. 10.1088/2632-2153/ad2aef AI: Could you explain why you need the model codes from the paper? for my major project
Initial Assessment of Available Information
You're seeking the codes for the models used in the paper with the DOI 10.1088/2632-2153/ad2aef for your major project. The paper is titled "Quantum Machine Learning Models for Image Classification" and explores hybrid quantum neural networks for image classification tasks.
Direct Answer to the Question
As of December 19, 2024, the specific source codes for the models described in the paper are not publicly available in the paper itself or associated repositories. However, there are several approaches you can take to obtain or recreate the models for your project.
Detailed Problem Analysis
Accessing the Paper and Supplementary Materials
- Review the Paper Thoroughly: Carefully read the paper to understand the architectures and methodologies of the models used. - Check for Supplementary Materials: Look for any supplementary information or appendices that might include code snippets, pseudocode, or links to repositories.
Searching for Public Code Repositories
- Authors' Profiles: Visit the authors' personal, institutional, or research group websites. Researchers often share their code on these platforms. - Online Platforms: Search on code-sharing platforms like GitHub, GitLab, or Bitbucket using keywords related to the paper: - Paper title or keywords (e.g., "quantum machine learning", "quanvolutional layer"). - Authors' names. - Community Forums: Check forums or communities focused on quantum computing and machine learning, such as Stack Exchange or specialized groups, where code might be shared.
Contacting the Authors
- Compose a Professional Email: Reach out to the corresponding author listed in the paper. - Introduce yourself and explain your major project. - Politely request access to the model codes or any guidance they can provide. - Be Respectful of Their Decision: Understand that they may not be able to share the code due to intellectual property policies or ongoing research.
Re-implementing the Models
- Understanding the Models: - Model 1: Hybrid Quantum Neural Network (HQNN) with parallel parameterized quantum circuits (PQCs) following classical convolutional layers. - Model 2: HQNN with a "quanvolutional" layer that reduces image resolution through quantum convolution operations. - Tools and Frameworks: - Quantum Computing Libraries: Use frameworks like Qiskit, PennyLane, or Cirq to implement quantum circuits. - Machine Learning Libraries: Integrate with classical ML frameworks like TensorFlow or PyTorch for the hybrid architecture. - Implementation Steps: - Algorithm Translation: Convert the mathematical descriptions and algorithms in the paper into code. - Parameter Initialization: Set up the quantum circuits with the specified parameters and gates. - Integration: Combine the quantum components with classical layers as described. - Verification: - Testing: Validate your implementation using datasets like MNIST, as used in the paper. - Performance Comparison: Compare your results with those reported to ensure accuracy.
Current Information and Trends
- Advancements in Quantum ML: Since the paper's publication, there may be new developments: - Improved quantum algorithms for machine learning tasks. - Enhanced simulators and accessibility to quantum hardware. - Open-Source Projects: Increased contributions to repositories focusing on quantum machine learning models.
Supporting Explanations and Details
- Quantum Computing Knowledge: A solid understanding of quantum mechanics principles (qubits, superposition, entanglement) is essential. - Educational Resources: - Books: "Quantum Computation and Quantum Information" by Nielsen and Chuang. - Online Courses: Quantum computing courses offered by platforms like Coursera or edX. - Community Engagement: Participating in workshops, hackathons, or forums can provide additional support and insights.
Practical Guidelines
- Project Planning: - Timeline: Allocate ample time for learning and implementation due to the complexity of quantum models. - Resources: Ensure you have access to the necessary computational resources, such as quantum simulators. - Simplify If Necessary: - Start Small: Begin with implementing simplified versions of the models. - Classical Baseline: Implement classical equivalents to benchmark performance.
Possible Disclaimers or Additional Notes
- Ethical Considerations: - Intellectual Property: Respect any licensing agreements or restrictions if you obtain code. - Citations: Properly cite the original paper and any resources you use. - Technical Limitations: - Hardware Constraints: Quantum hardware may have limitations like qubit decoherence and gate errors. - Simulation Limits: Quantum simulators may be resource-intensive for larger circuits.
Suggestions for Further Research
- Alternative Resources: - Similar Studies: Look for other papers that might have publicly available code on similar topics. - Pre-trained Models: Explore existing quantum machine learning models that could be adapted for your needs. - Future Trends: - Emerging Technologies: Stay updated on advancements in quantum hardware that could impact your project. - Interdisciplinary Approaches: Consider combining insights from fields like computational physics or advanced AI.
Brief Summary
While the exact codes from the paper are not publicly available, you can still progress by thoroughly studying the paper, reaching out to the authors, and utilizing quantum computing frameworks to implement the models yourself. This endeavor will not only contribute to your major project but also enhance your understanding of cutting-edge quantum machine learning techniques.
Questions for the User
- Project Details: - What specific objectives does your major project aim to achieve using these models? - Experience Level: - What is your background in quantum computing and machine learning? - Resources: - Do you have access to quantum computing platforms or simulators?
Providing more details will allow me to offer more tailored assistance or suggestions.
You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
What are you looking for? The code for the network architecture shown in Fig. 4? You can easily get started in any framework such as Torch or TensorFlow; as for the quantum layers – I’m not sure; it’s best to contact the authors, as the bot suggests, although I don’t think it quite understood the question.
Let’s give it a go @ElektrodaBot, recreate the network architecture shown in Fig. 4 of this article using Python and PyTorch.
What are you trying to achieve? Code for the network architecture shown in Fig. 4? You can easily get started in any framework such as Torch or TensorFlow; as for the quantum layers – I’m not sure, it’s best to write...
Direct answer to the question
Yes — it is possible to recreate the structure from Fig. 4 as a hybrid model PyTorch + PennyLane . Below is the code for the HQNN-Parallel architecture from the article with DOI
10.1088/2632-2153/ad2aef
.
Important note: this is not the authors’ original code , but an engineering reconstruction of the architecture described in the paper. The authors describe the model as a classical convolutional block
Conv → BatchNorm → ReLU → MaxPool
, followed by a dense layer
1568 → n
, then
c
parallel PQC quantum circuits of
q
qubits each, and finally a classical layer
n → 10
. For MNIST, the most successful variant had 4 quantum circuits , 5 qubits per circuit and 3 repetitions of the strong entanglement layer , i.e.
In this work, the input to the quantum section is divided into
c
fragments. Each fragment is of length
q
and is routed to a separate PQC circuit:
Code: text
Log in, to see the code
Each circuit performs:
1. Angle embedding Classical input values control the
RX
rotations.
2. Variational part Rotations of a single qubit and CNOT gates are repeated. As shown in the diagram, I used the following sequence:
Code: text
Log in, to see the code
for each qubit, followed by entanglement via CNOTs in a ring topology.
3. Measurement The expected value of the Pauli-Y operator is measured on each qubit, yielding
q
real numbers per circuit.
The authors provide a formula for the number of parameters in the quantum part:
Code: text
Log in, to see the code
For
q = 5
,
i = 3
,
c = 4
:
Code: text
Log in, to see the code
which means that the quantum part alone has only 180 trainable parameters . ( inspirehep.net )
---
3. Why didn’t I put Softmax at the end?
In PyTorch, for multi-class classification, the following is usually used:
Code: text
Log in, to see the code
This function expects raw logits as input , rather than probabilities after Softmax. Therefore, the model returns the output from the final linear layer
Linear(20, 10)
, without Softmax. The PyTorch documentation describes
If you want to obtain probabilities during evaluation, you do the following only then:
Code: text
Log in, to see the code
---
Minimum training framework for MNIST
Below is an example training run. Practical note: hybrid quantum simulation will be much slower than a standard CNN.
Code: text
Log in, to see the code
---
Practical note on the project
If this is to be a final-year or engineering project, I suggest creating three comparative variants:
Variant A — classic CNN
Replace the quantised layer with a standard
Linear(20, 20)
or
Linear(20, 10)
and compare:
Code: text
Log in, to see the code
Variant B — HQNN-Parallel
This is the model from the code above:
Code: text
Log in, to see the code
Variant C — simplified HQNN
For quicker experiments:
Code: text
Log in, to see the code
This won’t be the variant from the article, but you’ll be able to check the code’s correctness much more quickly.
---
Key corrections compared to the sample answer
1. In the variation section from Fig. 4, it is better to use the rotation:
Code: text
Log in, to see the code
rather than
RX → RY → RZ
, as the figure shows a rotation sequence of
Z
,
Y
,
Z
.
2. At the end of the model, it is generally better not to use ReLU or Softmax if you are using
nn.CrossEntropyLoss()
.
3. For quick execution on a simulator, it is better to use:
Code: text
Log in, to see the code
whereas for a version closer to real quantum hardware:
Code: text
Log in, to see the code
The authors of the paper describe the use of PennyLane and the parameter-shift rule to optimise the parameters of quantum circuits. ( inspirehep.net )
---
Summary
The code above reproduces the HQNN-Parallel structure from Fig. 4 :
-
1 x 28 x 28
input, - two classical convolutional blocks, - flattened to
1568
, - feature reduction to
20
, -
4
parallel quantum circuits, - each with
5
qubits, -
3
repetitions of the variational part, - Pauli-Y measurement, - classification into
10
classes.
If you like, I can also prepare a second version: just the classical CNN equivalent from this paper , so that the number of parameters and accuracy in the table can be fairly compared with the project.
You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
ADVERTISEMENT
Questioning practical hardware use of quantum layers
Below is an example training session. Practical note: a hybrid quantum simulation will be much slower than a standard CNN.
What is the practical application of these quantum layers, apart from scientific research?
@ElektrodaBot Will it ever be possible to implement such layers in hardware – a quantum computer? What is the advantage? Isn’t all this quantum computing just a way of securing research grants?
What practical applications, apart from scientific research, do these quantum layers have?
@ElektrodaBot Will it ever be possible to implement such layers in hardware – a quantum computer? What is the p...
Direct answer
In short: for classifying ordinary images such as MNIST/CIFAR, the practical value of quantum layers is currently very limited . In the article with DOI
10.1088/2632-2153/ad2aef
, the quantum layer is an interesting research experiment: it results in a small number of parameters and demonstrates that a hybrid classical-quantum network can achieve decent results. But from the perspective of an engineer who needs to implement something, a standard CNN on a GPU is faster, cheaper, simpler and more stable.
Will it ever be possible to run such layers on quantum hardware? Yes — it’s already possible on a small scale , though it’s not yet practical as a replacement for a GPU. At present, the setup tends to look like this: a classical computer runs the CNN/ML, whilst the quantum processor acts as a remote accelerator for a small PQC circuit. Frameworks such as PennyLane allow the quantum circuit to be treated as a differentiable element of the model, including via a PyTorch interface. ( docs.pennylane.ai )
Is quantum computing just a way of securing grants? Not entirely, but there is a lot of marketing hype surrounding QML and ‘quantum AI’. Quantum computing itself has very solid foundations: Shor’s algorithm for factorisation and discrete logarithms, quantum simulations in chemistry and materials science, quantum metrology, post-quantum cryptography. However, adding a few ‘quantum layers’ to an MNIST classifier and suggesting an industrial revolution is often more of a scientific demonstration than a production-ready technology.
---
What do these quantum layers actually do?
In the model discussed in the article, a classical CNN block first reduces the image to a feature vector, and then some of the features are fed into parameterised quantum circuits, or PQCs — *Parameterised Quantum Circuits*. The authors present, amongst other things, the HQNN-Parallel architecture, in which the classical part of the CNN is combined with parallel quantum circuits; according to their description, the model achieved 99.21% on the full MNIST dataset with approximately eight times fewer parameters than its classical counterpart. ( arxiv.org )
However, one must be careful with the interpretation.
Fewer parameters do not automatically mean a faster or better model. In a classical CNN, matrix multiplication and convolutions run very efficiently on a GPU/TPU. In contrast, a quantum circuit must be run multiple times, often with many measurement repetitions – so-called *shots* – to estimate the expected values of the operators. During training, gradients are also involved, e.g. via *parameter-shift*, which multiplies the number of circuit executions.
One can therefore encounter a seemingly attractive situation:
Code: text
Log in, to see the code
That is why, in QML projects, one must always compare not only
accuracy
and the number of parameters, but also:
- training time, - inference time, - number of circuit invocations, - number of measurements, - noise robustness, - hardware/cloud cost, - quality of the classical baseline.
---
Where is the potential advantage?
1. Representation in Hilbert space
A system of
n
qubits describes a state in a space of dimension
2^n
. This sounds impressive and, mathematically speaking, does indeed provide a very rich representation space. A quantum layer can act as a specific, non-linear mapping of features onto a space in which certain relationships may be more easily separable.
But there’s a catch: we do not have unrestricted, cheap access to all the amplitudes of this state . After measurement, we obtain a finite number of statistical results, not the entire state vector. This is a common mistake in popular descriptions: ‘2^n dimensions’ does not mean that we get a classical vector of length
2^n
for free.
2. Parametric efficiency
In models similar to the one in the article, the quantum layer may have relatively few parameters. For example, when we have:
Code: text
Log in, to see the code
the number of parameters in the quantum part is:
Code: text
Log in, to see the code
This is attractive as a regulariser or a compact non-linear block. But then again: whilst there are few parameters, the computational cost need not be low.
3. Native quantum data
The most significant advantage of QML may not lie in images, text or Excel spreadsheets, but rather in data derived from quantum systems: the states of molecules, spin systems, measurements from quantum sensors, and material simulations. This eliminates part of the problem of ‘feeding classical data into a quantum computer’. There are studies showing that, when learning from quantum experiments, it is possible in certain tasks to achieve an exponentially smaller number of required experiments than with classical processing of measurement results. ( arxiv.org )
In my opinion, this is a much more significant area of research than the ‘quantum digit classifier’.
---
Why is it still more of a demonstrator for MNIST/CIFAR today?
For classical images, the problem is as follows:
Code: text
Log in, to see the code
This stage:
Code: text
Log in, to see the code
is a critical bottleneck. If we have a 28×28 image, i.e. 784 pixels, we need to encode this data in a quantum state somehow. Popular methods, such as *angle embedding*, encode values as the rotation angles of gates. This is simple, but it does not provide any magical speed-up. More advanced amplitude-based encodings also incur a state preparation cost, which in practice can eat into the potential gain.
For classical image data, today’s engineering calculations are brutal:
Criterion
Traditional CNN on a GPU
HQNN / QML on a simulator or QPU
Training speed
very good
usually poor
Stability
high
problematic
Tools
mature
still under development
Scaling to big data
very good
difficult
Interpretation of results
established practice
still an active area of research
Advantage for MNIST/CIFAR
practically sufficient
no clear advantage in production
Therefore, if someone demonstrates that HQNN achieves results similar to those of CNN, this is scientifically interesting, but it does not mean that GPUs should be removed from the server room.
---
Can this be physically run on a quantum computer?
Yes, but with some caveats.
In practice, such a system would look like this:
Code: text
Log in, to see the code
It is not the case that the entire neural network ‘lives’ within a quantum computer. At least for models such as HQNN, it is a hybrid system. The classical computer still performs:
- data preprocessing, - convolutions, - linear layers, - the loss function, - the optimiser, - parameter updates, - training logistics.
The QPU executes only a small, parameterised quantum circuit.
PennyLane formally enables the construction of such hybrid systems: a QNode represents a quantum circuit executed on a selected device, whilst the
“torch”
interface allows it to be integrated with PyTorch and gradient descent. ( docs.pennylane.ai )
---
Why doesn’t this work properly on real hardware yet?
1. Noise and decoherence
Current quantum processors essentially belong to the NISQ class — *Noisy Intermediate-Scale Quantum*. They have a limited number of qubits, limited coherence time and are not yet fully error-resilient. Reviews of NISQ algorithms emphasise that such devices do exist, but they are not fully error-corrected computers; they operate with noise and limited circuit depth. ( arxiv.org )
For QML, this means that a deep variational circuit may quickly cease to carry useful information. The measurement result will then reflect hardware noise rather than the data structure.
2. Measurement cost
A quantum computer does not return the ‘exact result of a function’ like the classical
Linear
block. It returns samples. To estimate the expected value of an operator, the circuit must be run many times.
For example:
Code: text
Log in, to see the code
And during training, gradients come into play. For the *parameter-shift* method, the gradient for a single parameter often requires two additional circuit evaluations. With 180 parameters, this results in a large number of runs.
3. Barren plateaus
This is one of the most significant problems facing variational quantum algorithms. A *barren plateau* means that the cost function landscape becomes almost flat: gradients decay exponentially with the size of the problem. In such cases, the optimiser has no useful signal as to which way to update the parameters. A 2024 review described this as a key obstacle to variational quantum computing; the source of the problem may include, amongst other things, the ansatz, the initial state, the observable, the loss function and hardware noise. ( arxiv.org )
From the perspective of an electronics engineer or machine learning engineer, this is equivalent to the following situation:
Code: text
Log in, to see the code
4. Latency and queues in the cloud
If the QPU is remote, every execution goes through the API, the scheduler, the task queue and the monitoring system. For training a neural network, where we need thousands or millions of invocations, this is highly disadvantageous. A GPU operates locally and with massive parallelism; a QPU is currently more of a laboratory instrument than a replacement for a graphics card.
---
Will it be possible to achieve a true hardware implementation of such layers?
In my opinion: yes, but not necessarily in the form we see in today’s work on MNIST .
The most likely scenario is not a personal computer with a ‘quantum card’ alongside the GPU, but rather an architecture of the following type:
Code: text
Log in, to see the code
In other words, something similar to today’s accelerators, but with a completely different physical implementation. In its current roadmap, IBM states that it will demonstrate examples of quantum supremacy using quantum hardware and HPC in 2026, the development of larger chips in 2028, and the Starling system as the first fault-tolerant computer around 2029. However, this should be treated as the manufacturer’s roadmap, not a guarantee that we will have a cheap accelerator for training neural networks by 2029. ( ibm.com )
A production version would need to resolve several issues simultaneously:
- error correction, - scaling the number of logical qubits, - fast qubit readout and reset, - low latency in the classical-quantum loop, - circuit compilation for a specific hardware topology, - integration with classical ML frameworks, - a reasonable cost per computation run.
Only then could the quantum layer serve as a genuine ‘accelerator’ within a neural network, rather than a slow laboratory component.
---
Where does quantum computing have a real advantage, and where is it just hype?
Real, solid foundations
It cannot be said that the whole field of quantum computing is just a research funding bubble, as there are solid theoretical results. Shor’s algorithm demonstrates that integer factorisation and the discrete logarithm problem can be solved in polynomial time on a quantum computer, which is of fundamental importance for asymmetric cryptography. ( arxiv.org )
Simulations of quantum systems are also a very important application: chemistry, materials, magnetism, catalysis and superconductivity. This is a natural field of application, as a classical computer must simulate an exponentially growing state space, whereas a quantum computer operates on it physically. In the literature on chemical simulations, this is highlighted as one of the most eagerly anticipated applications of quantum computers. ( journals.aps.org )
A highly ‘overhyped’ area
The area that raises the most marketing-related suspicions is:
Code: text
Log in, to see the code
Particularly when someone promises that a few qubits will solve problems that are traditionally very well handled by:
In QML for classical data, there is currently no widely accepted, practical proof of superiority over well-chosen classical baselines. There are interesting results, there are niche applications, there are demonstrations, but there is not yet an equivalent to: “take this quantum layer, put it into a product, and you’ll get better cost-performance than on a GPU”.
---
My engineering verdict
For the article and similar models
Quantum layers in such models make sense as:
- a research demonstrator, - a way of investigating compact representations, - an experiment with a different type of non-linearity, - preparation of algorithms for future QPUs, - material for a dissertation or research project.
They do not currently make much sense as:
- a replacement for a classical CNN, - a way to speed up image recognition, - a method for reducing the cost of inference, - a production technology for ordinary visual data.
For quantum computing as a whole
No, this isn’t just a way of securing grants. But yes, part of the narrative surrounding ‘quantum AI’ is exaggerated .
The fairest summary is:
Code: text
Log in, to see the code
---
How I would phrase this in a project or paper
If anyone is working on a project based on this article, it’s worth avoiding uncritical statements such as: ‘quantum networks are better’. It’s better to put forward a fair argument:
> Hybrid classical-quantum networks can achieve comparable accuracy with fewer parameters, but for classical image data their practical advantage is currently limited by the cost of data encoding, the number of measurements, hardware noise, training issues and the lack of mature, error-resilient quantum computers.
And provide a comparative table:
Model
Accuracy
Parameters
Training time
Comments
Classic CNN
high
more
low
best industry practice
HQNN on the simulator
similar
less
high
suitable for research
HQNN on QPU
limited
less
very high
noise, shots, queues
QML for quantum data
potentially high
depending on
depending on
the most promising direction
This will be far more technically mature than simply repeating the marketing slogan ‘quantum advantage’.
Summary
Quantum layers in such a model are currently mainly of research and educational value. They may one day be implemented in hardware as part of hybrid classical-quantum accelerators, but at present they are not a practical alternative to GPUs for image classification. The true advantage of quantum computing is more likely to be found in the simulation of quantum systems, chemistry, materials science, cryptography and native quantum data processing than in the classical recognition of MNIST digits.
You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.