Skip to content

Add QRAM demonstration v1#1840

Open
ShifanXu wants to merge 33 commits into
PennyLaneAI:masterfrom
ShifanXu:add-qram-demo
Open

Add QRAM demonstration v1#1840
ShifanXu wants to merge 33 commits into
PennyLaneAI:masterfrom
ShifanXu:add-qram-demo

Conversation

@ShifanXu

Copy link
Copy Markdown

Before submitting

Please complete the following checklist when submitting a PR:

  • Ensure that your tutorial executes correctly, and conforms to the
    guidelines specified in the README.

  • Remember to do a grammar check of the content you include.

  • All tutorials conform to
    PEP8 standards.
    To auto format files, simply pip install black, and then
    run black -l 100 path/to/file.py.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Title:

Summary:

Relevant references:

Possible Drawbacks:

Related GitHub Issues:


If you are writing a demonstration, please answer these questions to facilitate the marketing process.

  • GOALS — Why are we working on this now?

    Eg. Promote a new PL feature or show a PL implementation of a recent paper.

  • AUDIENCE — Who is this for?

    Eg. Chemistry researchers, PL educators, beginners in quantum computing.

  • KEYWORDS — What words should be included in the marketing post?

  • Which of the following types of documentation is most similar to your file?
    (more details here)

  • Tutorial
  • Demo
  • How-to

@ShifanXu
ShifanXu requested review from a team as code owners July 20, 2026 17:33
@github-actions

Copy link
Copy Markdown

👋 Hey, looks like you've updated some demos!

🐘 Don't forget to update the dateOfLastModification in the associated metadata files so your changes are reflected in Glass Onion (search and recommendations).

Please hide this comment once the field(s) are updated. Thanks!

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown

Your preview is ready 🎉!

You can view your changes here

Deployed at: 2026-07-22 20:11:14 UTC

@drdren

drdren commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Thanks so much @ShifanXu ! I'm excited to see this demo on the website!

Comment thread demonstrations_v2/tutorial_qram/demo.py
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py
Comment thread demonstrations_v2/tutorial_qram/demo.py
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py
Comment thread demonstrations_v2/tutorial_qram/demo.py
Comment thread demonstrations_v2/tutorial_qram/demo.py
#
# .. math:: 1 + 3(2^n - 1)
#
# additional wires. For our 2-qubit address register, that means ten work wires.

@drdren drdren Jul 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that you use "work wires" here but "qubits" in the Select-Only QROM section. I think it would be better to pick one convention because this demo compares resource cost using this term. This applies to print-outs too!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. let's change to work wires!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK!

Comment thread demonstrations_v2/tutorial_qram/demo.py
Comment thread demonstrations_v2/tutorial_qram/demo.py
print("Total qubits:", len(control_wires + target_wires))
print("One-qubit gates:", select_specs.gate_sizes.get(1, 0))
print("Two-qubit gates:", select_specs.gate_sizes.get(2, 0))

@drdren drdren Jul 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, these gate counts look very low compared to the BBQRAM and Hybrid QRAM numbers. This is because we can't decompose fairly to the same gate set or is this correct? We should choose Select-Only QROM in this case?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is due to It such Multi-controlled gates have many ways of decomposition, where we cannot decompose fairly to the same gate set. Here in the code it may only report the gate count of these large mcx gates. We might only report the one/rwo qubti gate counts for bb/hybrid insteaf of select only.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also notice the current comparison mixes resource-counting conventions. The SelectOnlyQRAM circuit is synthesized using the concrete classical bitstrings, so controlled writes corresponding to zero-valued data bits are removed. For this dataset, only six two-address-controlled X operations remain; since the address has two qubits, these are six Toffoli gates, which decompose to 36 CNOTs and 42 T/T† gates before further optimization. BBQRAM, however, is effectively counted closer to a worst-case routing implementation. For a data-independent comparison, Select-only should instead be counted as (Nm=12) Toffoli operations in this example and all constructions should be decomposed under the same ancilla and Clifford+T assumptions. Since the demonstrated operation uses fixed read-only classical data, “Select-only QROM” is also the more precise terminology. Also, in terms of depth, this is a small case when n=2. BB qram performs better in terms of depth asymptotically, where its constant factor could be larger.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! This is excellent! We should have this in the demo itself! I left a comment below, in the "Comparing the three constructions" section, where I believe this discussion ought to be.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I asked Marcus offline. His opinion (did not dive into it) is that if you called for a decomposition down to CNOTs, then it probably did so (Toffolis become T + CNOTs, as you noted). qp.decompose also performs some simplification e.g., cancel inverses. We could maybe count those gates together to see if the PennyLane output matches expectations?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I would say this is mostly due to the fact that the example we give here is too small (n=2), so that the asymptotic scaling of BB QRAM hasn't shown up, where almost no parallelism here for BB QRAM, while select only QRAM can use zero-valued data to simply.

Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py
Comment thread demonstrations_v2/tutorial_qram/demo.py
ShifanXu and others added 9 commits July 21, 2026 18:21
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated
Comment thread demonstrations_v2/tutorial_qram/demo.py Outdated


hybrid_specs = qp.specs(compiled_hybrid_qram)(0)["resources"]
print("Total qubits:", len(control_wires + target_wires + hybrid_work_wires))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! We discussed the language of "work wires" vs "qubits". Which should we use here?

# .. [#hardwareefficient] Connor T. Hann, Chang-Ling Zou, Yaxing Zhang, Yiwen Chu,
# Robert J. Schoelkopf, Steven M. Girvin, and Liang Jiang,
# "Hardware-efficient quantum random access memory with hybrid quantum acoustic systems",
# `https://arxiv.org/abs/1906.11340 <https://arxiv.org/abs/1906.11340>`__, 2019.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# `https://arxiv.org/abs/1906.11340 <https://arxiv.org/abs/1906.11340>`__, 2019.
# `arXiv:1906.11340 <https://arxiv.org/abs/1906.11340>`__, 2019.

Comment on lines +13 to +14
"dateOfPublication": "2026-07-20T00:00:00+00:00",
"dateOfLastModification": "2026-07-20T00:00:00+00:00",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment acts as a reminder for us to update closer to the publication date.



######################################################################
# Even in this small example, the qualitative pattern is already visible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ShifanXu, I love this paragraph and it is necessary to explain the counter-intuitive result that SelectOnlyQRAM appears to be more efficient. But I think we can write a couple of extra sentences that comment on this more explicitly to avoid any confusion in the reader.

You elucidated in a comment above, but I'd love to see that elucidation in this paragraph! Something like: the numbers look worse because (i) SelectOnlyQROM is tailored for a specific problem while the other QRAM forms are for data-independent worst-case scenarios and (ii) this is a small problem; we expect BBQRAM and hybrid QRAM to exhibit more favourable constant-factor resource requires at larger problem sizes.

As an aside, do you believe it is possible to run those larger problems offline and just copy-paste the result here?

# | | | multi-controlled | exponential select |
# | | | writes | cost |
# +------------------------+------------------------+------------------------+------------------------+
# | :class:`~.pennylane.BBQRAM` | :math:`O(2^n+n+m)` | Active routing path | Large width; local |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# | :class:`~.pennylane.BBQRAM` | :math:`O(2^n+n+m)` | Active routing path | Large width; local |
# | ``BBQRAM`` | :math:`O(2^n+n+m)` | Active routing path | Large width; local |

# | | | plus address | |
# | | | load/unload overhead | |
# +------------------------+------------------------+------------------------+------------------------+
# | :class:`~.pennylane.HybridQRAM` | :math:`O(2^{n-k}+n+m)` | Select over | Tunable interpolation |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# | :class:`~.pennylane.HybridQRAM` | :math:`O(2^{n-k}+n+m)` | Select over | Tunable interpolation |
# | ``HybridQRAM`` | :math:`O(2^{n-k}+n+m)` | Select over | Tunable interpolation |

The formatting did not work out.

# | Construction | Width scaling | Depth / gate-cost | Main tradeoff |
# | | | intuition | |
# +========================+========================+========================+========================+
# | :class:`~.pennylane.SelectOnlyQRAM` | :math:`O(n+m)` | :math:`O(2^n m)` | Minimal width; |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# | :class:`~.pennylane.SelectOnlyQRAM` | :math:`O(n+m)` | :math:`O(2^n m)` | Minimal width; |
# | ``SelectOnlyQRAM`` | :math:`O(n+m)` | :math:`O(2^n m)` | Minimal width; |

######################################################################
# The figure below presents a side-by-side conceptual comparison of three different constructions
# included in this demo: (a) a direct address-controlled QRAM implementation for
# :class:`~.pennylane.SelectOnlyQRAM`, (b) a binary routing tree for :class:`~.pennylane.BBQRAM`, and (c) a select-prefix plus

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, do you want to change the terminology to be Select Only QROM here and in all the other places? I just highlighted this place.

# Select-only QRAM
# ----------------
#
# We start with the most direct construction. :class:`~.pennylane.SelectOnlyQRAM` applies the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to select-only QROM too?

@drdren drdren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much @ShifanXu , I enjoyed reading your commentary! I left a few minor comments. The biggest item (which I elaborated on in a comment below) is that we should explicitly comment on why SelectOnlyQROM incorrectly appears to be the cheapest option. As an aside, I am happy to change the language to SelectOnlyQROM; just let me know where.

ShifanXu and others added 5 commits July 22, 2026 15:52
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants