Skip to content

Commit

Permalink
Faster dm norm in solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericgig committed Apr 24, 2024
1 parent 75557fe commit f8ae77d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion qutip/solver/solver_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
state = state * (1 / state.tr())
else:
state = state * (1 / state.norm())

return state

Expand Down
2 changes: 1 addition & 1 deletion qutip/tests/solver/test_mesolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def testME_TDDecayliouvillian(self, c_ops):
def test_mesolve_normalization(self, state_type):
# non-hermitean H causes state to evolve non-unitarily
H = qutip.Qobj([[1, -0.1j], [-0.1j, 1]])
H = qutip.sprepost(H, H) # ensure use of MeSolve
H = qutip.spre(H) + qutip.spost(H.dag()) # ensure use of MeSolve
psi0 = qutip.basis(2, 0)
options = {"normalize_output": True, "progress_bar": None}

Expand Down

0 comments on commit f8ae77d

Please sign in to comment.