Krylov and Lanczos for Density Matrices#2725
Conversation
- Generalize lanczos to states not normalized acc. to L2 (e.g. vectorized dens. matrices) - Simplify Lanczos by index fixes in matrices, little code restructuring
- This is intended to enable manual usage of the Kyrlov algorihtm without too much overhead - WARNING: This break the default behavior of the Integrator when simply initialized and run - Will be reverted when closing the PR
- To be smoothed out later, just added for completeness
- kyrlov solve can handle matrix states now - fixed loss of normalization for matrix states - reverted to old max_step cal for now - added tests, fixed error messages
Co-authored-by: Eric Giguère <[email protected]>
|
Since a lot has changed and I am formally opening this for review, I am putting the checklist and a more detailled description for this PR. The Additionally the solver was fixed in terms of handling different system dimensions and the happy breakdown correctly. Technical TODOs / ideas
Contribution Checklist
|
Ericgig
left a comment
There was a problem hiding this comment.
It does not work for simple example anymore:
N = 20
a = qt.destroy(N)
H = qt.num(N) + a + a.dag()
psi0 = qt.basis(N, N-1)
expected = qt.sesolve(H, psi0, [0, 1]).final_state -
krylov = qt.krylovsolve(H, psi0, [0, 1], krylov_dim=5).final_state
print(expected - krylov).norm()
In master: 2.958730598870145e-06
With this: 1.1326590031741184
| # Kyrlov method works best with dense Hamiltonians. | ||
| # Since rand_herm(.) usually provides sparse matrices, we are summing | ||
| # multiple samplings. | ||
| H = np.sum([qutip.rand_herm(20) for _ in range(30)]) / 30 |
There was a problem hiding this comment.
This is not the way to do this...
There was a problem hiding this comment.
Now it's replaced with the proper density argument.
I had to increase the tolerance to 1e-5. to accomodate a small error (compared to mesolve) in the expectation value over time that is oscillating around 0. At longer times (1000 times longer than in the test), the error stays withing 1e-3, so I deemed this increase reasonable. This error is essentially the same for the master version of the code.
Do let me know if that is still withing desired bounds.
- Fix condition when happy breakdown detected - Readd min step failsafe - Improved error messages
|
The latest version of the code should fix this simple code example. Be aware that when you are using the master version of krylov solve, there is a bug that the actual krylov dimension that is used, is +1 of what you request (so 6 in your example). |
Ericgig
left a comment
There was a problem hiding this comment.
Looking better.
It would be good if there was an explanation on what would make a good krylov dim in the documentation.
|
I implemented all the changes, thanks a lot! As for the krylov dimension in the documentation: I added a paragraph to give some intuition, but it is really hard to determine the "best possible" dimension. I hope it helps a bit. |
|
@Langhaarzombie |
Description
Enables the calculation of time dynamics for density matrices using the Lanczos algorithm for the Krylov subspace method.