# Wrong overlap for non-Hermitian matrices #39

Closed
opened this issue Feb 18, 2019 · 0 comments
Closed

# Wrong overlap for non-Hermitian matrices#39

opened this issue Feb 18, 2019 · 0 comments
Assignees
Labels
Milestone

 The overlap routine in `Krotov` blindly assumes to be working on (Hermitian) density matrices. This was a deliberate choice (36b59aa), because calculating an unnecessary `.dag()` can be measurably expensive. However, for an optimization with the full Liouville basis the propagated states are not Hermitian, and a wrong overlap could cause serious problems. The `Qobj.isherm` flag could be used to decide whether to call `dag()` or not. ``````>>> import numpy as np >>> import qutip >>> from qutip import ket >>> import krotov >>> Qmagic = (1.0 / np.sqrt(2.0)) * qutip.Qobj( ... np.array( ... [[1, 0, 0, 1j], [0, 1j, 1, 0], [0, 1j, -1, 0], [1, 0, 0, -1j]], ... dtype=np.complex128, ... ), ... dims=[[2, 2], [2, 2]], ... ) >>> def ketbra(a, b): ... return ket(a) * ket(b).dag() ... >>> rho_2 = ketbra('01', '10') >>> (Qmagic.dag() * rho_2).tr() # correct 0.7071067811865475 >>> (Qmagic * rho_2).tr() # wrong 0.7071067811865475j >>> krotov.second_order._overlap(Qmagic, rho_2) # wrong 0.7071067811865475j ``````
closed this in ``` 09136c3 ``` Feb 18, 2019