NVIDIA/cuda-quantum

Remove the requirement of the expectation() handle

zohimchandani opened this issue · 0 comments

Required prerequisites

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

Describe the feature

Let's compare the sample and observe workflow:

import cudaq 
from cudaq import spin 

hamiltonian = spin.z(0)

@cudaq.kernel
def kernel():
    
    qvector = cudaq.qvector(1)
    
    h(qvector)

sample_result = cudaq.sample(kernel)

print(sample_result)
observe_result = cudaq.observe(kernel, hamiltonian)

print(observe_result.expectation())

We don't have to do sample_result.bitstring(). It is expected that the user wants a bitstring as an output here.

Similarly, when using observe, from a user perspective, it is expected that they expect an expectation value hence the requirement for .expectation() is cumbersome.

It would be nice to move this one layer behind the user experience as it helps the code to match between different modes of operation and reduces rewriting parts for larger examples.

Thanks team.