-
Notifications
You must be signed in to change notification settings - Fork 189
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
State synthesis for quantum devices #2291
base: main
Are you sure you want to change the base?
Conversation
623ab4b
to
4517712
Compare
I, Ben Howe <[email protected]>, hereby add my Signed-off-by to this commit: 86681ef Signed-off-by: Ben Howe <[email protected]> Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
4517712
to
7969a75
Compare
Signed-off-by: Anna Gringauze <[email protected]>
…antum-device-state
Signed-off-by: Anna Gringauze <[email protected]>
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.
LGTM 👍
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
…antum-device-state
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.
Still reviewing...
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.
Still reviewing...
/// %5 = quake.init_state %4, %2 : (!quake.veq<?>, !cc.ptr<!cc.state>) -> !quake.veq<?> | ||
/// ─────────────────────────────────────────── | ||
/// ... | ||
/// %5 = call @callee.modified_0() : () -> !quake.veq<?> |
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 violates the semantics of Quake: all quantum memory allocations happen at the top-level and cannot be returned from other kernels.
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.
It is only temporary and does not seem to break anything until the Inlining fixes the semantics... But returning allocations (instead of passing them as a parameter) is much easier to implement. Let me know if it is a showstopper, I can revisit passing allocations as a parameter.
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.
Well, it's a bug even if it "works" for now, so I think we ought to deal with it now.
I don't see why returning is any easier. Updating the "init kernel" from something like
func.func @init_kernel() {
%0 = quake.alloca !quake.veq<4>
...
}
to a "modified init kernel" of
func.func @init_kernel.modified(%0 : !quake.veq<4>) {
...
}
is easy enough.
Also, if we pass in the allocated qubits, we don't have to erase them at the top-level or rely on inlining to get things normalized, etc.
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.
The callee can have multiple allocations, so I would need to know how to split the qvector
to pass to those allocations. Not sure how to do that yet (process the function to get allocation sizes first? The size can be a result of a _getNumberOfQubits
call though...)
I need time to try changing to passing allocations as parameters, probably won't fit into this release, unless I only support a trivial case of one allocation in a callee kernel. Do you think this part can be done in a later PR?
…antum-device-state
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
…antum-device-state
Signed-off-by: Anna Gringauze <[email protected]>
…antum-device-state
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Signed-off-by: Anna Gringauze <[email protected]>
Synthesize state pointer for quantum devices:
SimulationState:
hasData
API that returns true iff the vector data exists on the state or can be computed.getKernelInfo
API that returns optional kernel name and a list of arguments for the kernel that generated the state.QuantumState:
ArgumentConversion:
call __nvqpp_cudaq_state_get("callee.modified_N")
instruction.veq
allocations.ArgumentConverter
.Passes:
StateInitialization
pass that replacesquake.init_state
instructions by a call tocallee.modified_N()
StateValidation
pass that validates the syntheszed MLIR for quantum hardware.quake.init_state
instructions in MLIR.Synthesis:
Tests:
targettests/execution/qvector_init_from_state.cpp
test that runs for various quantum backends emulationNotes
Currently state pointer synthesis is only supported for kernels implemented as
operator()
inside a struct.TODO (in subsequent PRs)
cudaq::qkernel
to support c-like kernels in state pointer synthesisRequires: #2354