shuaigroup / Renormalizer

Quantum dynamics package based on tensor network states
https://shuaigroup.github.io/Renormalizer/
Apache License 2.0
52 stars 16 forks source link

Add functionality of MPO with block diagonal form #154

Closed SUSYUSTC closed 1 year ago

SUSYUSTC commented 1 year ago

Currently if one add two MPOs by mpo = mpo1 + mpo2 it creates zeros at off-diagonal blocks. In case the final MPO is composed of many small MPOs the computational efficiency is slow. I'll probably add another PR later for diagonal potential MPO, in which case the final MPO is composed of a dense kinetic block and a diagonal potential MPO block.

This pull request adds a StackedMpo class to improve the efficiency by calculating the Hamiltonians corresponding to each MPO part separately and then adding the Hamiltonians. It works for both the direct and iterative approach.

Example:

// original way: mpo = mpo_k + mpo_p
mpo = StackedMpo([mpo_k, mpo_p])
result = optimize_mps(mps.copy(), mpo)  // expect the same result
codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 98.14% and project coverage change: +0.05% :tada:

Comparison is base (9706a29) 84.76% compared to head (9a985d1) 84.81%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #154 +/- ## ========================================== + Coverage 84.76% 84.81% +0.05% ========================================== Files 105 105 Lines 10140 10183 +43 ========================================== + Hits 8595 8637 +42 - Misses 1545 1546 +1 ``` | [Files Changed](https://app.codecov.io/gh/shuaigroup/Renormalizer/pull/154?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=shuaigroup) | Coverage Δ | | |---|---|---| | [renormalizer/mps/gs.py](https://app.codecov.io/gh/shuaigroup/Renormalizer/pull/154?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=shuaigroup#diff-cmVub3JtYWxpemVyL21wcy9ncy5weQ==) | `95.93% <97.50%> (+0.12%)` | :arrow_up: | | [renormalizer/mps/\_\_init\_\_.py](https://app.codecov.io/gh/shuaigroup/Renormalizer/pull/154?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=shuaigroup#diff-cmVub3JtYWxpemVyL21wcy9fX2luaXRfXy5weQ==) | `100.00% <100.00%> (ø)` | | | [renormalizer/mps/mpo.py](https://app.codecov.io/gh/shuaigroup/Renormalizer/pull/154?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=shuaigroup#diff-cmVub3JtYWxpemVyL21wcy9tcG8ucHk=) | `91.15% <100.00%> (+0.09%)` | :arrow_up: | | [renormalizer/mps/tests/test\_gs.py](https://app.codecov.io/gh/shuaigroup/Renormalizer/pull/154?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=shuaigroup#diff-cmVub3JtYWxpemVyL21wcy90ZXN0cy90ZXN0X2dzLnB5) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jjren commented 1 year ago

Excellent PR and many thanks to Jiace. It is better to add a test in mps/tests/test_gs.py. For example, in test_optimization, you can simply add the two mpos together and check if the energy is doubled.

SUSYUSTC commented 1 year ago

Test already added.

atxy-blip commented 1 year ago

The new function looks good to me. Many thanks for your work!

Meanwhile, personally speaking I prefer well-documented code, so maybe you could add new comments and make changes to the original ones accordingly. For example, the following line should contain the new class:

https://github.com/shuaigroup/Renormalizer/blob/9706a29106f0b8213a60bfa18d9f1fa1bcec03f8/renormalizer/mps/gs.py#L55

SUSYUSTC commented 1 year ago

Comments & types added