Repository navigation
Conversation
Co-authored-by: Cursor AI assistant
Co-authored-by: Cursor AI assistant
**Context:** Split out of PennyLaneAI#10363. We have a PPM-based decomposition rule for `QROM` but it does not report its resources faithfully (even when acknowledging that we set `exact=False`). - Not all sizes of PPMs that can occur in the decomposition (they depend on the `bitstrings` data) are included in the resources. - The control logic is not reported correctly **Description of the Change:** - Rework `_qrom_measurement_resources`: count CNOTs per iterator variant, count the flag-gated load as a controlled `MultiX`, include the adjoint of the flag `X`, and spread the X-type joint measurements binomially over their widths instead of assuming the worst-case width. - Simplify `_flag_resources` accordingly. - Remove the `pl2do` markers from the Catalyst tests, xfail the one case blocked by PennyLaneAI/catalyst#3366 and PennyLaneAI/catalyst#3376, and make `test_no_phases_error` compare the full state. **Benefits:** Resource estimates that match the decomposition. **Possible Drawbacks:** The widths of the X-type measurements are an estimate that assumes uniformly random bitstrings We will only be able to fix this once we have an umbrella op for flexible-sized PPMs. This PR was prepared with the help of an AI assistant. --------- Co-authored-by: Cursor <cursoragent@cursor.com>
Port the measurement-based uncomputation from Appendix C of arXiv:1902.02134 onto `Adjoint(QROMLoad)` after splitting `QROM` into `QROM` and `QROMLoad`. The fixup lookup is a plain `QROM` and receives all remaining work wires. This commit was authored with the help of an AI assistant (Cursor). Co-authored-by: Cursor <cursoragent@cursor.com>
57a29e7 to
438797f
Compare
The cost estimate in `_adjoint_qrom_load_one_hot_size` creates abstract operators, which bound `symbolic_array` placeholders into the captured program and broke compilation under `qjit`. Pause capture while estimating. Remove the xfail of `test_qjit`, as Catalyst #3376 is merged. This commit was authored with the help of an AI assistant (Cursor). Co-authored-by: Cursor <cursoragent@cursor.com>
…ecomp Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # doc/releases/changelog-dev.md # pennylane/numeric_hamiltonians.py # pennylane/templates/subroutines/qrom.py # tests/templates/subroutines/test_qrom.py
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # doc/releases/changelog-dev.rst # pennylane/templates/subroutines/qrom_load.py # tests/templates/subroutines/test_qrom_load.py
After the measure-and-reset step, the target wires are clean, so they now join the work wires as auxiliary wires for the one-hot register and the fixup `QROM`. The rule no longer requires work wires, and with exactly c - 1 work wires it now beats inverting `QROMLoad`. Also regenerate the thumbnail without background, fold the changelog entry into the `QROMLoad` feature entry, document the control wire requirement, and test that the graph chooses the rule. This commit was authored with the help of an AI assistant (Cursor). Co-authored-by: Cursor <cursoragent@cursor.com>
Adjoint(QROM)Adjoint(QROMLoad)
|
Review by Opus 5.5 on high effort, after multiple iterations.
|
Resolve conflicts by keeping the QROM/QROMLoad split and adapting the Adjoint(QROM) measurement-based uncomputation onto QROM without clean. Co-authored-by: Cursor <cursoragent@cursor.com>
…ecomp Prefer remote Adjoint(QROMLoad) measurement uncomputation over the local Adjoint(QROM) variant after the QROM/QROMLoad split. Co-authored-by: Cursor <cursoragent@cursor.com>
Resolve test_qrom_load conflict by taking the updated select-swap T-count check from split-qrom and keeping the Adjoint(QROMLoad) tests. Co-authored-by: Cursor <cursoragent@cursor.com>
Adjoint(QROMLoad)Adjoint(QROMLoad) and Adjoint(SelectSwap)
|
Re-review by Opus 5.5 on high effort (because
|
KetpuntoG
left a comment
There was a problem hiding this comment.
It is so nice that we can do this kind of decomposition!
Leaving some comments
There was a problem hiding this comment.
I see other images has been updated to the new temporaryAND drawing but this one is still using the previous one
| i.e., of the inverted SWAP network of Select-SWAP. They are not obtained from ``_swap_ops``, | ||
| because the latter applies generic controlled SWAPs and cannot make use of ``y`` being in | ||
| the :math:`|0\rangle` state.""" |
There was a problem hiding this comment.
what is this doing? we are saving 1 cnot per cswap?
| X(one_hot_wires[0]) | ||
| for control, x, y in triples: | ||
| TemporaryAND([control, x, y]) | ||
| CNOT([y, x]) |
There was a problem hiding this comment.
are these the controlled SWAPs with target 0? it would help to add a one-line comment if so
| t0: ──┤↗X├──┤↗Z├──X──X─────────────├●─╭X─├●─╭X─│───H────├QROM(M0)──H──────│─╭X──●┤─╭X──●┤──X─┤ | ||
| t1: ─────────────────┤↗X├──┤↗Z├──X─╰⊕─╰●─│──│──├●─╭X──H─├QROM(M0)──H─╭X──●┤─│────│─╰●──⊕╯────┤ |
There was a problem hiding this comment.
where do these initial measurements come from? should I be looking to fig5?
There was a problem hiding this comment.
Ah okey, those are the Hadamard + measurement
but you are using X directly 👍
| target_wires = base.target_wires | ||
| outcomes = _measure_and_reset(target_wires) | ||
| fixups = math.dot(bitstrings, math.cast(math.stack(outcomes), int)) % 2 | ||
| _phase_fixup(fixups, base.control_wires, Wires(target_wires) + Wires(base.work_wires)) |
| ) | ||
|
|
||
|
|
||
| class SelectSwap(Operator2): |
There was a problem hiding this comment.
I was not aware that this was already merged
To double check, SelectSwap is the QROMLoad version, right? (input 0)

Context:
We can un-load a
QROMLoadwith measurement-based uncomputation, and that will be cheaper than re-loading it.This method is described in App. C in Berry et al. https://arxiv.org/abs/1902.02134.
We can also un-load a garbage-state producing loading op, namely
SelectSwap, with a variation of this that measures out the swap wires as well.Description of the Change:
Add new decompositions to
Adjoint(QROMLoad)andAdjoint(SelectSwap)that use this technique.Benefits:
Cheaper decompositions.
Possible Drawbacks:
Related GitHub Issues: