-
Notifications
You must be signed in to change notification settings - Fork 213
Add demo on loading classical data with low-depth circuits #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…nist/requirements.in and update the reference types in demonstrations_v2/low_depth_circuits_mnist/metadata.json
Your preview is ready 🎉!You can view your changes here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made an initial skim and left comments. Overall a very nice/complete first draft.
Still pending from my side:
- In depth review of the text for clarity
- In depth review of the code for efficiency and output
But basically I think 1 or two more rounds of review and this should be ready to go.
# effectively shifting the gates with the dashed outlines to the right, the gates are applied | ||
# sequentially outward starting from the center. This reduces the circuit depth while maintaining its | ||
# expressivity. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should solve the figure rendering issue.
# |
circuit_layout = dataset_params.circuit_layout_d4 | ||
circuit = get_circuit(circuit_layout) | ||
params_01 = np.asarray(dataset_params.params_d4)[selection] | ||
states_01 = np.asarray([circuit(params) for params in tqdm(params_01, desc="States for depth 4")]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tqdm
causes this to render many lines with a scroll bar. Maybe we can reduce the number of prints?
# 3. Quantum classifiers | ||
# ---------------------- | ||
# | ||
# In this demo, we train a **variational quantum circuit** as classifier. Our datasets require |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# In this demo, we train a **variational quantum circuit** as classifier. Our datasets require | |
# In this demo, we train a **variational quantum circuit** as a classifier. Our datasets require |
# - **Quantum‑kernel SVMs** — replacing inner products by quantum state overlaps. | ||
# - **Tensor‑network (MPS/MPO) classifiers** for large qubit counts. | ||
# | ||
# In this demo we use a small linear VQC. The circuit consisits of two qubit gates correspdonding to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# In this demo we use a small linear VQC. The circuit consisits of two qubit gates correspdonding to | |
# In this demo we use a small linear VQC. The circuit consists of two qubit gates corresponding to |
# | ||
# We start by **casting** the FRQI amplitude vectors and their digit labels into JAX arrays. Next, the | ||
# states and labels are shuffled from a pseudorandom key derived from the global ``SEED``. Then, the | ||
# data is split into training and validation. Finally, we gather the tensors corresponding in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# data is split into training and validation. Finally, we gather the tensors corresponding in the | |
# data is split into training and validation. Finally, we gather the tensors corresponding to the |
r"""Loading classical data with low-depth circuits | ||
============================================== | ||
|
||
The encoding of arbitrary classical data into quantum states usually comes at a high computational |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to make sure to preserve your style of writing, so feel free to ignore any suggestions that you don't agree with.
The encoding of arbitrary classical data into quantum states usually comes at a high computational | |
Encoding arbitrary classical data into quantum states usually comes at a high computational |
inherent structure (such as image data) which can be leveraged to load them with a much smaller cost | ||
on a quantum computer. The paper **“Typical Machine Learning Datasets as Low‑Depth Quantum | ||
Circuits”** (2025) [`1 <#References>`__] develops an efficient algorithm for finding low-depth | ||
quantum circuits to load classical image data as quantum states. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe?
quantum circuits to load classical image data as quantum states. | |
quantum circuits to load classical image data into quantum states. |
Low‑Depth Quantum Circuits”** (2025). We will discuss the following three steps: 1) Quantum image | ||
states, 2) Low-depth image circuits, 3) Training a small variational‑quantum‑circuit (VQC) | ||
classifier on the dataset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't mind getting a bit more information about what we will discuss. For example, we can include a verb in each item of the list:
- Define how images can be encoded in quantum states
- Introduce low-depth image circuits to generate these states
- ...
(just examples, no need to use those)
|
||
|
||
###################################################################### | ||
# Downloading the quantum image dataset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can link the datasets page in here somewhere https://pennylane.ai/datasets/collection/low-depth-image-circuits
# ===================== ============================================================= | ||
# Attribute Description | ||
# ===================== ============================================================= | ||
# ``exact_state`` The exact state that the corresponding circuit should prepare | ||
# ``labels`` The correct labels classifying the corresponding images | ||
# ``circuit_layout_d4`` The layout of the depth 4 circuit | ||
# ``circuit_layout_d8`` The layout of the depth 8 circuit | ||
# ``params_d4`` Parameters for the depth 4 circuit | ||
# ``params_d8`` Parameters for the depth 8 circuit | ||
# ``fidelities_d4`` Fidelities between the depth 4 state and the exact state | ||
# ``fidelities_d8`` Fidelities between the depth 8 state and the exact state | ||
# ===================== ============================================================= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Title:
Add demo on loading classical data with low-depth circuits
Summary:
This pull request adds a new demonstration on how to efficiently load classical image data into quantum states using low-depth quantum circuits, based on the paper "Typical Machine Learning Datasets as Low‑Depth Quantum Circuits". The demo uses the MNIST dataset and shows how to train a variational quantum classifier on the encoded data. This demo leverages the new qml.data module for dataset loading.
Relevant references:
Possible Drawbacks:
The dataset required for this demo is large (~1GB), which might be a consideration for users with limited bandwidth or storage.
Related GitHub Issues:
None
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
Promote the new
qml.data
feature for loading datasets and show a PennyLane implementation of a recent paper on efficient data loading for QML.QML researchers, students, and practitioners interested in efficient data loading techniques and their application to image classification tasks.
Quantum Machine Learning, Quantum Datasets, Image Loading, Low-depth circuits, Variational Quantum Classifier, MNIST, PennyLane, qml.data
(more details here)