cuda-quantum icon indicating copy to clipboard operation
cuda-quantum copied to clipboard

Make the default shot count for sample and observe the same.

Open mawolf2023 opened this issue 1 year ago • 5 comments

Required prerequisites

  • [X] Search the issue tracker to check if your feature has already been mentioned or rejected in other issues.

Describe the feature

The default shot count is 1000 for sample. A new user would likely assume the same for observe, but observe has a default of 1.

For minimizing confusion, it would be helpful if both were 1000.

mawolf2023 avatar Feb 13 '24 18:02 mawolf2023

The default use of cudaq::observe returns the expectation value of a quantum state. This is a deterministic result (this is in contrast with cudaq::sample, which is not deterministic). Hence its default number of shots is 1.

We provide the ability to define a number of shots for cudaq::observe for the cases in which a user might want a statistically noisy expectation value that is computed from sampled bit strings.

boschmitt avatar Feb 13 '24 19:02 boschmitt

Yes, I do agree with your logic when you consider observe by itself. I did not make that very clear above that I see why it is set to 1. However, I think based on how we are ordering the docs (observe following sample) there is a high probability a user assumes they are obtaining the expectation value from an ensemble of samples (I did). I think that is probably how most users would expect it to work in practice, e.g. for VQE. I think a deterministic expectation value would be the exception and not the norm for a new user. @boschmitt

mawolf2023 avatar Feb 13 '24 19:02 mawolf2023

Yes, I do agree with your logic when you consider observe by itself. I did not make that very clear above that I see why it is set to 1. However, I think based on how we are ordering the docs (observe following sample) there is a high probability a user assumes they are obtaining the expectation value from an ensemble of samples (I did).

Thanks for clarifying. I agree that the current default behavior can be unexpected for a new user, but I believe this is the standard within the quantum computing community. I will look into it a bit more.

For the time being do you think that we can mitigate this issue in the documentation? e.g., by introducing cudaq::observer default behavior as the exact calculation of the expectation value of the quantum state (as-if its being calculated on a infinite number of samples---trying to tie it up with the preceding introduction of cudaq::sample.)

boschmitt avatar Feb 13 '24 20:02 boschmitt

Yeah, I think so. Certainly we can be as clear as possible. Another related item I realized building my basic example. I included kernel.mz in the sample example even though it is the default measurement basis. However, if I leave it in when I go to observe, even in a shot based approach, the state collapses and the collapsed state is the only one "sampled". E.g. If I have a circuit consisting of only a Hadamard, and kernel.mz, observe will collapse to 0 or 1 first, and then use only that result for each shot. So you get 1 or -1. Is this expected as well? @boschmitt

mawolf2023 avatar Feb 14 '24 13:02 mawolf2023

The default target for kernel execution is the GPU-accelerated simulators. As a quantum computing user, if I am targeting a simulator, I expect that requesting an expectation value for an observable return the pure simulated value, not something with shot-based statistical sampling. If I do want that, then I can specify the shots - then I'm being explicit about my intent to compute expected values with inherent statistical noise.

The language specification states that kernels passed to observe cannot have measurements specified. In the future we'll be better about throwing errors for violations of the specification.

amccaskey avatar Feb 23 '24 13:02 amccaskey