[qref 3] Migrate capture frontend to produce reference semantics MLIR#2663
Draft
[qref 3] Migrate capture frontend to produce reference semantics MLIR#2663
Conversation
JerryChen97
reviewed
Apr 8, 2026
paul0403
commented
Apr 16, 2026
Comment on lines
+533
to
+538
| - name: Run qref frontend lit tests | ||
| run: | | ||
| for file in ./frontend/test/lit/test_qref/*; do\ | ||
| echo "Testing $$file"\; | ||
| python3 "$$file" | ./llvm-build/bin/FileCheck "$$file";\ | ||
| done |
Member
Author
There was a problem hiding this comment.
I added a new CI step (under "frontend tests (gcc)") that only runs the qref lit tests I added in these PRs.
This is because the regular tests will fail until the entire migration is complete. In the meantime, this CI step can be used to verify the qref implementation itself.
This step will be removed once the entire migration is complete: it is just a subset of make lit, running frontend filecheck lit tests only on my newly added qref test files.
…reference semantics (#2664) **Context:** Migrate alloc, dealloc and observable plxpr conversion to reference semantics. Note: this PR only handles the initial allocation from the device initialization. It does not deal with dynamically allocated qubits from `qml.allocate()` within a circuit. These will be handled after the gates are handled, so there's a reasonable way to test them. - [x] Alloc - [x] Dealloc - [x] AllocQubit (not generated by frontend) - [x] DeallocQubit (not generated by frontend) - [x] Compbasis - [x] NamedObs - [x] Hermitian **Related GitHub Issues:** [sc-115868]
paul0403
commented
Apr 17, 2026
paul0403
commented
Apr 21, 2026
…tics (#2672) **Context:** Migrate gate-like ops' plxpr conversion to reference semantics. This PR also handles dynamic allocations and deallocations from `qml.allocate()`. Note: adjointed gates are not handled in this PR. They will be handled in a future PR that specifically handles the adjoint region from plxpr. - [x] CustomOp - [x] MultiRZOp - [x] PCPhaseOp - [x] PauliRotOp - [x] GlobalPhaseOp - [x] QubitUnitaryOp - [x] MeasureOp - [x] SetStateOp - [x] SetBasisStateOp **Related GitHub Issues:** [sc-115869]
…#2694) **Context:** Migrate for loop's plxpr conversion to reference semantics **Description of the Change:** All quantum reference values are captured now via closure from above automatically by jax infra. No need to keep track of quantum value args to the for loop anymore :rocket: :fire: :partying_face: **Benefits:** Much cleaner conversion of plxpr to catalys jaxpr. [sc-115870]
…cs (#2717) **Context:** Migrate while loop's plxpr conversion to reference semantics **Description of the Change:** Delete the conversion from plxpr while loop primitive to catalyst while loop primitive, so we just use the lowering of plxpr while loop primitive directly. **Benefits:** Much cleaner conversion of plxpr to catalys jaxpr. [sc-115871]
…o qref lit tests" This reverts commit b258ac5.
paul0403
commented
Apr 23, 2026
Comment on lines
+237
to
+238
| pass | ||
| # precompile_decomp_rules() # pragma: no cover |
Member
Author
There was a problem hiding this comment.
TODO: reenable precompiled decomp rules when the entire migration is compelte
paul0403
commented
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context:
Migrate capture frontend to produce reference semantics MLIR.
This is the main PR. Each item will come into this PR as its own PR.
Description of the Change:
Expose python bindings for operations in the
qrefMLIR dialect, and define their corresponding jax primitives and lowering rules on these primitivesThe conversion from plxpr to catalyst jaxpr now produces qref primitives whenever possible. This includes allocation, deallocation, extract (now
qref.get; note that reference semantics does not have an insert op), observables, gates and adjointsFor the following primitives, the conversion from the PL version to catalyst version is no longer done. Instead, we define lowering rule on the PL primitives directly:
for_loop,while_loop,if,adjoint. This is because with reference semantics, their MLIR operation now take in and return purely classical values, so the special handling regarding the quantum values in their operands is not needed anymore.At the beginning of the default pipeline, the following passes are added (in this order):
--canonicalize--verify-no-quantum-use-after-free--convert-to-value-semantics--canonicalizeTests are edited correspondingly, mostly to update their expected results to check for reference semantics
pytest/from_plxpr/test_from_plxpr.py:compare_call_jaxprtest util has been removed. Note that the checks for execution results on these tests are kept.Benefits:
--convert-to-value-semanticspass will only create value semantics regions that take in individual qubit values, instead of entire register values.Related GitHub Issues:
closes #2526 [sc-112704]
closes #2527 [sc-112706]