# solving a linear problem with alternating\_update

**URL:** <https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959>\
**Category:** DMRG and Numerical Methods\
**Tags:** mps, mpo\
**Created:** [September 3, 2024, 9:36pm UTC](https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959 "2024-09-03T21:36:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shengtao](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@Shengtao](https://itensor.discourse.group/u/Shengtao)\
**Post date:** [September 3, 2024, 9:36pm UTC](https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959/1 "2024-09-03T21:36:15Z")

</div>

Hi Matt and Miles,  
I have been looking into the [linsolve(A,b,x\_0;…)](https://github.com/ITensor/ITensorTDVP.jl/blob/main/src/linsolve.jl) function in `ITensorTDVP` that solves the `A|x>=|b>` problem using `alternating_update` (which basically replaces the `eigsolve_updater` in DMRG with a `linsolve_updater`) with @srwhite. If we understand correctly based on [reducedlinearproblem.jl](https://github.com/ITensor/ITensorTDVP.jl/blob/main/src/reducedlinearproblem.jl) and [reducedconstantterm.jl](https://github.com/ITensor/ITensorTDVP.jl/blob/main/src/reducedconstantterm.jl), the algorithm projects both the operator `A` and the constant term `|b>` under the basis of `|x>` that is being optimized. Graphically the reduced problem is defined as:

```auto
*--*--*- -*--*--*--*--*--* <x|
| | | | | | | | | | |
o--o--o--o--o--o--o--o--o--o--o A (A_reduced)
| | | | | | | | | | |
*--*--*- -*--*--*--*--*--* |x>

o--o--o--o--o--o--o--o--o--o--o <b|  
| | | | | | | | | | | (|b_reduced>)
*--*--*- -*--*--*--*--*--* |x>

```

Then `A_reduced` and `|b_reduced>` is fed into the `KrylovKit.linsolve()` together with an initial guess `|x_0_reduced>`. It seems to us this algorithm requires that `|b>` and the final `|x>` share the same MPS basis to some degree. For example, if `A` changes the quantum number by a definite amount, say being a `C^+`, then either the basis of `|x>` needs to be expanded to include a different quantum number sector (which is not necessary since `|x>` also has a definite quantum number), or `A_reduced` will be zero.  
It seems to us more natural to set up the problem in the framework of [reducedcontractproblem.jl](https://github.com/ITensor/ITensorTDVP.jl/blob/main/src/reducedcontractproblem.jl), such that the reduced problem is:

```auto
o--o--o- -o--o--o--o--o--o <b|
| | | | | | | | | | |
o--o--o--o--o--o--o--o--o--o--o A (A_reduced)
| | | | | | | | | | |
*--*--*- -*--*--*--*--*--* |x>

-o--o- (|b_reduced> that is taken out of the sandwich above)
 | |

```

In this way, one seems to avoid the above problem.

Best,  
Shengtao

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [September 3, 2024, 9:43pm UTC](https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959/2 "2024-09-03T21:43:20Z")

</div>

I believe I tried that and couldn’t get it to work but maybe there was something I was missing.

---

<div class="post-metadata">

**Author:** ![Shengtao](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@Shengtao](https://itensor.discourse.group/u/Shengtao)\
**Post date:** [September 3, 2024, 9:54pm UTC](https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959/3 "2024-09-03T21:54:03Z")

</div>

Hi Matt,  
Thanks for the quick response and I will experiment with it myself and will let you know if I find anything.  
Could you share a little more about why it couldn’t work? Was it an ITensor issue or that the CG/GMRES in `KrylovKit.linsolve()` doesn’t converge?

Best,  
Shengtao

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [September 3, 2024, 10:17pm UTC](https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959/4 "2024-09-03T22:17:39Z")

</div>

I found that it didn’t converge to the correct state `|x>`.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [September 3, 2024, 10:19pm UTC](https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959/5 "2024-09-03T22:19:40Z")

</div>

I think if the bases `|x>` and `|b>` were similar, it was ok, but if they were different enough from each other it failed very badly. One limit to think about is if the basis of `|b>` is very small, say a product state. In that limit, my intuition was that `<b|A|x>` was projecting out too much of `A|x>`, but that was just a rough guess about why it was failing.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [September 4, 2024, 1:17am UTC](https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959/6 "2024-09-04T01:17:23Z")

</div>

If you have success with using the `|b>` basis (or some other variation) please let us know!

---

<div class="post-metadata">

**Author:** ![Shengtao](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@Shengtao](https://itensor.discourse.group/u/Shengtao)\
**Post date:** [September 4, 2024, 5:56am UTC](https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959/7 "2024-09-04T05:56:45Z")

</div>

Of course! Steve has suggested to improve the current version by using density-matrix mixing to incorporate some `|b>` into the basis of `|x>`, maybe in a way like running DMRG with noise on for some initial sweeps. I will implement that and let you know how that works.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [September 4, 2024, 2:38pm UTC](https://itensor.discourse.group/t/solving-a-linear-problem-with-alternating-update/1959/8 "2024-09-04T14:38:55Z")

</div>

I think I tried something like that but didn’t push that idea very far, I’m curious to hear if you get something like that working.
