Skip to content

Commit

Permalink
Improve test_m_ops and test_wigner_spin_q_normalized stability
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericgig committed Mar 6, 2024
1 parent 058c589 commit a1a8bf3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions qutip/tests/solver/test_stochastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,13 @@ def test_m_ops(heterodyne):
solver.dW_factors = [1.] * len(m_ops)
# With dW_factors=0, measurements are computed as expectation values.
res = solver.run(psi0, times, e_ops=m_ops)
std = 1/times[1]**0.5
noise = res.expect[0][1:] - res.measurement[0][0]
assert np.mean(noise) == pytest.approx(0., abs=std/50**0.5 * 4)
assert np.std(noise) == pytest.approx(std, abs=std/50**0.5 * 4)
std = 1 / times[1]**0.5
if heterodyne:
noise = res.expect[0][1:] - res.measurement[0][0][0]
else:
noise = res.expect[0][1:] - res.measurement[0][0]
assert np.mean(noise) == pytest.approx(0., abs=std / 50**0.5 * 5)
assert np.std(noise) == pytest.approx(std, abs=std / 50**0.5 * 5)


def test_feedback():
Expand Down
2 changes: 1 addition & 1 deletion qutip/tests/test_wigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ def test_spin_q_function_normalized(spin, pure):
Q, THETA, _ = qutip.spin_q_function(rho, theta, phi)

norm = d / (4 * np.pi) * np.trapz(np.trapz(Q * np.sin(THETA), theta), phi)
assert_almost_equal(norm, 1, decimal=4)
assert_allclose(norm, 1, atol=2e-4)


@pytest.mark.parametrize(["spin"], [
Expand Down

0 comments on commit a1a8bf3

Please sign in to comment.