GregDMeyer / dynamite

Fast quantum evolution and eigensolving using Krylov subspace methods via the PETSc/SLEPc libraries.
MIT License
33 stars 6 forks source link

Tensor product of states? #12

Open vipasu opened 3 years ago

vipasu commented 3 years ago

Hi,

The package is quite neat and user friendly, so kudos!

One thing I was trying to do was build up states which are tensor products of smaller states. I was wondering if it makes sense to suggest including such functionality in the library? The operation shouldn't be too difficult, but just wasn't sure if it was in the scope of what others would find useful as well.

Thanks, Vincent

vipasu commented 3 years ago

Ah, I just realized that I'm not sure how to convert the np array back to a State object. Do you have any suggestions for a workaround?

GregDMeyer commented 3 years ago

Hi Vince!! Yes, that sounds like it would potentially be useful for sure! I can add to my TODO to add it, it shouldn't be too hard.

For now, regarding your second question, you should be able to use slice notation to copy an np.array into a state. So, once you have a State object state of the correct size initialized, and a numpy array ary, you can just do

state.vec[:] = ary

and it will copy all the values in ary to the state.

It gets a little more complicated if you are using multiple processes with MPI, because you need to be careful about which process should "own" which part of the array. But for single-threaded operation this should work fine. (Let me know if it breaks!)