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

Generalize exp_pauli()

Open poojarao8 opened this issue 2 years ago • 2 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

It will be great to have the exp_paul function take the spin_op as the input or the string form of it. I believe the issue with H.to_string() is that it dumps coefficients and exp_pauli takes pauli words only, but I haven't fully investigated it yet.

import cudaq
from cudaq import spin

kernel = cudaq.make_kernel()
qreg = kernel.qalloc(1)

H = spin.z(0)
    
kernel.exp_pauli(0.3, qreg, H)
#kernel.exp_pauli(0.3, qreg, H.to_string()) ###This would work great too.

cudaq.sample(kernel)

poojarao8 avatar Oct 12 '23 00:10 poojarao8

In C++, we have H.to_string(/*printCoeffs*/ false);. This just needs to be exposed in py_spin_operator.cpp, although just taking the spin_op as input (with an exception thrown if its more than one term) is cleaner / better.

amccaskey avatar Oct 12 '23 11:10 amccaskey

import cudaq
from cudaq import spin

kernel = cudaq.make_kernel()
qreg = kernel.qalloc(1)

H = spin.z(0)
    
kernel.exp_pauli(0.3, qreg, H.to_string(False))

print(cudaq.sample(kernel))

works well. Is it enough? Do you need more enhencement?

ikkoham avatar May 22 '24 07:05 ikkoham

Closing due to no response and options provided.

bettinaheim avatar Aug 07 '24 07:08 bettinaheim