-
Notifications
You must be signed in to change notification settings - Fork 47
[Frontend] Split QFuncPlxprInterpreter
into SubroutineInterpreter
#1787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Frontend] Split QFuncPlxprInterpreter
into SubroutineInterpreter
#1787
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1787 +/- ##
==========================================
- Coverage 96.61% 96.61% -0.01%
==========================================
Files 82 82
Lines 9260 9265 +5
Branches 875 875
==========================================
+ Hits 8947 8951 +4
- Misses 254 255 +1
Partials 59 59 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a sensible change!
One thing I'm wondering about is whether we should make it a hard assumption that subroutines always take in the entire register. It is the most generic option, and also what we do with control flow, but ultimately this is quite heavy handed. Take for example a decomposition scenario. For a single qubit operation, a decomposition subroutine would be much more effective (to the overall IR) if it only accepted and produced that single qubit.
I'm not saying the register couldn't be a safe fallback, but maybe we should just be careful in baking that in as a hard assumption.
Hello. You may have forgotten to update the changelog!
|
Yes, I agree with this, but it is going to be difficult to implement without a new interface. There's stopping a user to just say "wire=some_number". I've thought about alternative interfaces like if a subroutine is annotated with wire parameters, then do not pass the register. @subroutine
def foo(w0 : Wire, w1: Wire) # (can only manipulate these wires) But then it becomes impossible to have control flow in the subroutine because we need the register for control flow. Ideally the control flow should also only pass wires. This also may get weird with dynamic qubits. My prefer UI is exposing value qubits to the user. I.e., @subroutine
def foo(q0: Qubit, q1: Qubit):
q0, q1 = qml.CNOT(q0, q1)
return q0, q1 |
I don't think this is necessarily true, with the exception of maybe the frontend? At least in MLIR I feel like I have written examples of control flow around qubits. EDIT: Ah you're focused on the frontend here, yeah that's true, but see below. But even if we assume that it is, this should be easy (and desirable!) to change. |
Not sure I follow here, do you have an example? I think the UI you're showing looks good! |
def foo(wire0: Wire, wire1: Wire):
assert wire0 != 45 and wire1 != 45
qml.Hadamard(45)
qml.CNOT(wire0, wire1) Sorry I meant "there's nothing stopping a user to just say |
Got it! I might need to think about it some more, especially as there are different scenarios to consider (e.g. a user writing a subroutine, an internal transform that replaces one piece of code with another, a user transform, ...). Thanks! |
c7c3bc0
to
0f20608
Compare
Context: A quantum subroutine and the quantum kernel's entry point have almost everything in common. The only differences are:
Description of the Change: Move all the semantics of the quantum instructions except the setup and teardown method's for QFuncPlxprInterpreter into
SubroutineInterpreter
.Benefits: Avoid code duplication once support for subroutines are added in the frontend.