Skip to content

Commit

Permalink
Merge pull request #2423 from pmenczel/stochastic-fixes
Browse files Browse the repository at this point in the history
Stochastic solvers small bugfix
  • Loading branch information
pmenczel committed May 9, 2024
2 parents d8c6584 + 9e628b3 commit 9dd572e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions qutip/solver/stochastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def measurement(self):
"""
if not self.options["store_measurement"]:
return None
elif len(self.m_ops) == 0:
if self.heterodyne:
return np.empty(shape=(0, 2, len(self.times) - 1))
else:
return np.empty(shape=(0, len(self.times) - 1))
elif self.options["store_measurement"] == "start":
m_expect = np.array(self.m_expect)[:, :-1]
elif self.options["store_measurement"] == "middle":
Expand Down
20 changes: 14 additions & 6 deletions qutip/tests/solver/test_stochastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def _make_system(N, system):
gamma = 0.25
a = destroy(N)

if system == "no sc_ops":
H = a.dag() * a
sc_ops = []

if system == "simple":
H = a.dag() * a
sc_ops = [np.sqrt(gamma) * a]
Expand All @@ -39,7 +43,7 @@ def _make_system(N, system):


@pytest.mark.parametrize("system", [
"simple", "2 c_ops", "H td", "complex", "c_ops td",
"no sc_ops", "simple", "2 c_ops", "H td", "complex", "c_ops td",
])
@pytest.mark.parametrize("heterodyne", [True, False])
def test_smesolve(heterodyne, system):
Expand Down Expand Up @@ -73,13 +77,15 @@ def test_smesolve(heterodyne, system):
)


@pytest.mark.parametrize("system", [
"no sc_ops", "simple"
])
@pytest.mark.parametrize("heterodyne", [True, False])
@pytest.mark.parametrize("method", SMESolver.avail_integrators().keys())
def test_smesolve_methods(method, heterodyne):
def test_smesolve_methods(method, heterodyne, system):
tol = 0.05
N = 4
ntraj = 20
system = "simple"

H, sc_ops = _make_system(N, system)
c_ops = [destroy(N)]
Expand Down Expand Up @@ -138,7 +144,7 @@ def test_smesolve_methods(method, heterodyne):


@pytest.mark.parametrize("system", [
"simple", "2 c_ops", "H td", "complex", "c_ops td",
"no sc_ops", "simple", "2 c_ops", "H td", "complex", "c_ops td",
])
@pytest.mark.parametrize("heterodyne", [True, False])
def test_ssesolve(heterodyne, system):
Expand Down Expand Up @@ -174,14 +180,16 @@ def test_ssesolve(heterodyne, system):
assert res.dW is None


@pytest.mark.parametrize("system", [
"no sc_ops", "simple"
])
@pytest.mark.parametrize("heterodyne", [True, False])
@pytest.mark.parametrize("method", SSESolver.avail_integrators().keys())
def test_ssesolve_method(method, heterodyne):
def test_ssesolve_method(method, heterodyne, system):
"Stochastic: smesolve: homodyne, time-dependent H"
tol = 0.1
N = 4
ntraj = 20
system = "simple"

H, sc_ops = _make_system(N, system)
psi0 = coherent(N, 0.5)
Expand Down

0 comments on commit 9dd572e

Please sign in to comment.