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
Faster dm norm in solvers #2408
Conversation
qutip/solver/solver_base.py
Outdated
@@ -102,7 +102,10 @@ def _restore_state(self, data, *, copy=True): | |||
state = Qobj(data, **self._state_metadata, copy=copy) | |||
|
|||
if data.shape[1] == 1 and self._options['normalize_output']: | |||
state = state * (1 / state.norm()) | |||
if state._isherm: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is meant to check whether the state is a density matrix, yes? Surely there must be a better way if this doesn't always work. Also definitely worth a comment if the check remains a bit obscure.
Are there any use cases where the state is an operator and we want to use norm instead of tr? If no, we could just do As a side note, in cases with non-Hermitian "density matrices", it probably does not make much sense to normalize the output in any way. That is, I don't think it matters too much whether we use norm or tr in such a case, because probably neither is intended by the user... (But maybe there are some use cases I am not aware of?) |
The only operator we normalise are density matrices, so My issue is that in these cases, we still set the
We don't set the flag when the input are super operators? We try to check if the Liouvillian preserve hermiticity (not easy for time dependant operator)? Junk in, junk out? |
A problem can also happen if the input is not a superoperator:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the isherm
issue is separate from this PR. I created issue #2410 about that.
Description
The trace norm was used to normalized dm in mesolve and other open solvers.
This is computed as
tr( sqrtm(op @ op.dag()) )
which is quite slow.For density matrices, this is equivalent to the normal trace.
By using the trace,
mesolve
can be twice as fast.Related issues or PRs
fix #2406
ps. While we check if the input is a dm to set the
isherm
flag, we don't check the liouvillian.Since we accept any super-operator as Liouvillian, we could wrongly set the flag in some cases.