Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong overlap for non-Hermitian matrices #39

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

Wrong overlap for non-Hermitian matrices #39

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

Comments

@goerz
Copy link
Member

@goerz goerz commented Feb 18, 2019

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
@goerz goerz added the bug label Feb 18, 2019
@goerz goerz added this to the 1.0 Publication milestone Feb 18, 2019
@goerz goerz self-assigned this Feb 18, 2019
@goerz goerz closed this in 09136c3 Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.