Add QRAM demonstration v1#1840
Conversation
|
👋 Hey, looks like you've updated some demos! 🐘 Don't forget to update the Please hide this comment once the field(s) are updated. Thanks! |
Your preview is ready 🎉!You can view your changes here
|
|
Thanks so much @ShifanXu ! I'm excited to see this demo on the website! |
| # | ||
| # .. math:: 1 + 3(2^n - 1) | ||
| # | ||
| # additional wires. For our 2-qubit address register, that means ten work wires. |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
sounds good. let's change to work wires!
| 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)) | ||
|
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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>
|
|
||
|
|
||
| hybrid_specs = qp.specs(compiled_hybrid_qram)(0)["resources"] | ||
| print("Total qubits:", len(control_wires + target_wires + hybrid_work_wires)) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| # `https://arxiv.org/abs/1906.11340 <https://arxiv.org/abs/1906.11340>`__, 2019. | |
| # `arXiv:1906.11340 <https://arxiv.org/abs/1906.11340>`__, 2019. |
| "dateOfPublication": "2026-07-20T00:00:00+00:00", | ||
| "dateOfLastModification": "2026-07-20T00:00:00+00:00", |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 | |
There was a problem hiding this comment.
| # | :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 | |
There was a problem hiding this comment.
| # | :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; | |
There was a problem hiding this comment.
| # | :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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Should we change this to select-only QROM too?
drdren
left a comment
There was a problem hiding this comment.
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.
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>
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 thenrun
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)