Skip to content

Conversation

@paul0403
Copy link
Member

@paul0403 paul0403 commented Oct 20, 2025

Context:
Higher order primitives can take in dynamically allocated registers

Description of the Change:

  • changelog
  • remove the restriction from docs
  • cond
  • for loop
  • while loop
  • [ ] adjoint involves changing adjoint op's mlir definition, will do in another PR Adjoint op can handle multiple registers #2147
  • subroutine
  • [ ] decomposition? decomp wires will always be allocated from within the scope

Essentially, we need to do the following:

  1. The subregion kernels need to parse their arguments not as *args, qreg, but as *args, *dynamically_allocated_qregs, global_qreg
  2. The subregion's qubit index recorder needs to have the same global wire indices as the outer interpreter, and the values need to be the corresponding qreg managers from the subregion's qreg tracer arguments. We implement this mapping by the new qreg_map in the subregion kernels.
  3. The high-order primitives need to be called with the dynamic qregs.

Benefits:
Higher order primitives can take in dynamically allocated registers

Possible Drawbacks:
Don't know why, but while other subregions have arg signature (args, qreg), subroutine has signature (qreg, args), i.e. it has args in reverse order. This means the subregion wrapper (the thing to be make_jaxpr'd) cannot be reused for subroutines.
This is probably something we can just reorder?

Also, subroutine takes in wire indices through tracer args of the subroutine, even when the indices are static. This is expected, since subroutines are really a seperate function call, instead of just a enclosed subregion. This means its qreg_map logic between inner qregs and outer qregs is different than the others.

Related GitHub Issues:
[sc-99734]

@paul0403 paul0403 added the wip PRs that are a Work-In-Progress label Oct 20, 2025
@paul0403 paul0403 marked this pull request as ready for review October 22, 2025 22:13
@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.43%. Comparing base (75e057b) to head (3cef8b4).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #2130    +/-   ##
========================================
  Coverage   97.43%   97.43%            
========================================
  Files          92       92            
  Lines       10613    10467   -146     
  Branches      998     1014    +16     
========================================
- Hits        10341    10199   -142     
+ Misses        214      211     -3     
+ Partials       58       57     -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paul0403 paul0403 removed the wip PRs that are a Work-In-Progress label Oct 23, 2025
@paul0403 paul0403 requested a review from a team October 24, 2025 16:16
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.

1 participant