Skip to content

Commit

Permalink
Merge pull request #2408 from Ericgig/solver.faster_normalizations
Browse files Browse the repository at this point in the history
Faster dm norm in solvers
  • Loading branch information
Ericgig committed Apr 26, 2024
2 parents 7d6c72e + 9e0279b commit f403c94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion qutip/solver/solver_base.py
Expand Up @@ -85,6 +85,9 @@ def _prepare_state(self, state):

self._state_metadata = {
'dims': state._dims,
# This is herm flag take for granted that the liouvillian keep
# hermiticity. But we do not check user passed super operator for
# anything other than dimensions.
'isherm': state.isherm and not (self.rhs.dims == state.dims)
}
if self.rhs.dims[1] == state.dims:
Expand All @@ -102,7 +105,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.isoper:
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
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 f403c94

Please sign in to comment.