-
Notifications
You must be signed in to change notification settings - Fork 177
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
Perf. improvement for CuStateVecCircuitSimulator::observe
#1002
Conversation
This mode is only activated with env. variable CUDAQ_OBSERVE_FROM_SAMPLING=OFF/0/FALSE. Currently, we didn't use the batched Pauli APIs and skipped it entirely for fp-32. Modify it to use batched Pauli expectation APIs for perf.
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
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.
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 suspect we need some docs for the CUDAQ_OBSERVE_FROM_SAMPLING
environment variable.
@1tnguyen seems like we should also update |
Yes, it's always faster: a lot faster for large Hamiltonians since the time to run change-of-basis gates and then uncompute them is not insignificant. There is an issue with making it the default. Currently, we expect that What do you think? |
I say go for it - make that change here in this PR. |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
This allows a fast batched observation while still allowing per-term data to be progagated up the stack.
- Use Shots > 0 condition to know if sampling is required. - Adjust base shouldObserveFromSampling to set default if needed. Plus, the environment variable can be used to both turn the feature on or off. e.g., for benchmarking purposes.
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
This PR is ready for (re-)review. Ping reviewers... :-) |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
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 will be a very nice optimization. Are all the interface changes invisible to the end user?
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.
👍
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Description
Currently, we don't use the batched Pauli expectation API for multi-term
spin_op
expectation calculation.This API is substantially faster than applying change-of-basis gates then observing
<ZZZ..ZZ>
for each term.Hence, this PR modifies
custatevec
backend to use batched Pauli expectation API by default for deterministiccudaq::observe
(no shots)(1) Change
CircuitSimulator::observe
to returnobserve_result
, which can encapsulate the final expectation value as well as individual terms' expectation values.(2) Use
custatevec
batched API and populate theobserve_result
accordingly.(3) Add a backward compatibility test for the term-by-term mode.
See also: #1477, #1430