-
Notifications
You must be signed in to change notification settings - Fork 204
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 <bhowe@nvidia.com>, hereby add my Signed-off-by to this commit: 86681ef Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
4517712
to
7969a75
Compare
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…antum-device-state
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
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 <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…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...
…antum-device-state
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…antum-device-state
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…antum-device-state Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…ate-ops Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…ate-ops Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…ate-ops Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…antum-device-state Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…antum-device-state Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…antum-device-state Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
I, Anna Gringauze <agringauze@nvidia.com>, hereby add my Signed-off-by to this commit: 9563371 Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…antum-device-state Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
StrAttr:$numQubitsFuncName, | ||
StrAttr:$initFuncName |
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.
StrAttr:$numQubitsFuncName, | |
StrAttr:$initFuncName | |
FlatSymbolRefAttr:$numQubitsFuncName, | |
FlatSymbolRefAttr:$initFuncName |
If these are truly artifacts that shall be present in the IR, let's make them Symbol attrs.
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.
If the signatures of those functions are changed by the synthesis, would this instruction get updated with symbols with new signatures during application of the substitution? I can try that and see if the synthesis works.
let arguments = (ins | ||
StrAttr:$numQubitsFuncName, | ||
StrAttr:$initFuncName | ||
); | ||
let results = (outs cc_PointerType:$result); |
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.
We probably want to force this to be a ptr<state>
, no?
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.
Will do, thanks
createArgumentSynthesisPass(const std::vector<std::string> &funcNames, | ||
const std::vector<std::string> &substitutions); |
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.
Why do we need this? ArrayRef
should subsume rigid std::vector
here. I don't think we need this overload?
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.
std::vector<string>
does not get auto-converted to ArrayRef<StringRef>
... I can try ArrayRef<std::string>
instead
return calleeConverters; | ||
} | ||
|
||
std::pair<std::vector<std::string>, std::vector<std::string>> |
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.
Use SmallVector.
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.
I think i tried and something went wrong, will try again
llvm::raw_string_ostream ss(substBuff); | ||
ss << argCon.getSubstitutionModule(); | ||
mlir::SmallVector<mlir::StringRef> substs = {substBuff}; | ||
auto [kernels, substs] = argCon.collectAllSubstitutions(); |
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.
Looks like you got in trouble here by moving the strings into another function, where they go out of scope and vanish.
Let's leave the string creation here, where it is. To change it might look a little nicer, but it is far less efficient. Instead of a single copy of the data, we're building vectors of copies of the data and passing those around. The LLVM Way (tm) is preferred in the compiler code.
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 nested argument converters (for kernels used in get_state calls) have their new kernel names, created during state argument conversion, so I moved the kernel name storage to the ArgumentConverter for the kernel.
I thought about an alternative of having a special "storage" for the new names collection and passing that storage by reference to ArgumentConverter and its children, but that does not seem to solve the problem of efficiency of copying the name for the entry kernel. I appreciate any ideas here!
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:
quake.get_state "callee.num_qubits_N" "callee.init_N"
instruction.callee.num_qubits_N
andcallee.init_N
functions that are created from the callee code and compute allocation size and initialize the allocation, respectively.ArgumentConverter
.Passes:
ReplaceStateWithKernel
pass thatquake.get_num_qubits
instructions by a call tocallee.num_qubits_N()
quake.init_state
instructions by a call tocallee.init_N()
Synthesis:
Tests:
test_argument_conversion
ReplaceStateWithKernel
passArgumentSynthesis
pass with state pointer substitutionstargettests/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