ITensor / ITensorTDVP.jl

Time dependent variational principle (TDVP) of MPS based on ITensors.jl.
MIT License
51 stars 13 forks source link

Generalizing fitting algorithm to MPO-MPO multiplication #47

Open shinaoka opened 1 year ago

shinaoka commented 1 year ago

Thank you for developing the nice library!

I am wondering how to generalize the fitting algorithm to MPO-MPO multiplication. I am slowly understanding the internal structure of this library. This could be achieved by generalizing ProjMPOApply.

https://github.com/ITensor/ITensorTDVP.jl/blob/main/src/projmpo_apply.jl

But, the function tdvp is specialized to MPS. I am not sure if this restriction is strict. Is generalizing it to MPO possible technically?

mtfishman commented 1 year ago

Good question. Ultimately we plan to allow more general inputs to tdvp beyond MPS, for example tree tensor networks (#43), so it seems reasonable to allow MPO as well.

A minimal thing you can do is just convert your MPO to an MPS (there isn't any restriction that MPS must have only one site index per site), and see what breaks. At some point I tested this out for using TDVP to evolve a density matrix. I think it all worked after I generalized some of the projected MPO code to handle the "dangling" indices properly: https://github.com/ITensor/ITensors.jl/commit/0101936601643e5b12bc79a8c73c9535ceb550b9

shinaoka commented 1 year ago

Thank you for the reply.

Ultimately, we plan to allow more general inputs to tdvp beyond MPS, for example tree tensor networks (https://github.com/ITensor/ITensorTDVP.jl/pull/43), so it seems reasonable to allow MPO as well.

That'd be great!

In the meantime, I have just made a quick dirty hack to ITensorTDVP.jl and ITensors.jl. You will find my code in the contract_mpo_mpo branch with a notebook: https://github.com/shinaoka/ITensorTDVP.jl/blob/contract_mpo_mpo/examples/contract_mpo_mpo.ipynb

I had to extend ITensors.replacebond! to MPO in the notebook, but the rest was smooth. The notebook was tested with ITensors v0.3.20.

emstoudenmire commented 1 year ago

Agreed with Matt's answer about mapping to the MPS type and back, and tweaking the code to handle doubled site indices. Sounds like it worked!

So do I understand from your code, literally the only change needed was defining replacebond!, and the rest just worked? That's great if so.

shinaoka commented 1 year ago

@emstoudenmire

the only change needed was defining replacebond!, and the rest just worked?

Correct! Let me clean up the code.

shinaoka commented 1 year ago

Here is a small patch with a test: https://github.com/shinaoka/ITensorTDVP.jl/tree/contract_mpo_mpo_clean

Changing a few lines in function ITensors.contract was enough! All the tests passed with ITensors v0.3.20. Shall I make a PR?

emstoudenmire commented 1 year ago

Yes a PR would be great. Thanks! And for now you could put the MPO version of replacebond! in the contract_mpo_mps.jl file and I'll work myself on a separate PR for ITensors.jl to generalize replacebond! to handle MPOs, and can remove that (nearly) duplicate code myself later.

shinaoka commented 1 year ago

I am a bit confused. Do we need the MPO version of replacebond! at this point?