NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
489 stars 181 forks source link

Ability to initialize a null spin_op #703

Open poojarao8 opened 1 year ago

poojarao8 commented 1 year ago

Required prerequisites

Describe the feature

Currently, a spin_op is initialized as an identity so that when you use an increment operator to add more terms, it adds identity by default (see snippet below). This makes it a little inconvenient to use when building a Hamiltonian with large number of terms because we need to initialize correctly before using the increment operator.

While the current version is useful, it might be better to initialize it as null by default or at least have the option to initialize it as null.

from cudaq import spin
hamiltonian  = cudaq.SpinOperator()
hamiltonian += spin.z(0)
print(hamiltonian) # This is I + Z currently
poojarao8 commented 4 months ago

Hi team, bumping this up because it has come up in discussions with several users.