Skip to content

Commit

Permalink
Update brmesolve for .expect becoming a list and reactivate shadowed …
Browse files Browse the repository at this point in the history
…spectra coefficient as function test.
  • Loading branch information
hodgestar committed Jun 2, 2022
1 parent 2fc45d8 commit 004045d
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions qutip/tests/solver/test_brmesolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def test_simple_qubit_system(me_c_ops, brme_c_ops, brme_a_ops):
times = np.linspace(0, 10, 100)
me = qutip.mesolve(H, psi0, times, c_ops=me_c_ops, e_ops=e_ops)
brme = brmesolve(H, psi0, times, brme_a_ops, e_ops=e_ops, c_ops=brme_c_ops)
for me_expectation, brme_expectation in zip(
me.expect, brme.expect.values()
):
for me_expectation, brme_expectation in zip(me.expect, brme.expect):
np.testing.assert_allclose(me_expectation, brme_expectation, atol=1e-2)


Expand Down Expand Up @@ -80,9 +78,7 @@ def test_harmonic_oscillator(n_th):

me = qutip.mesolve(H, psi0, times, c_ops, e_ops)
brme = brmesolve(H, psi0, times, a_ops, e_ops)
for me_expectation, brme_expectation in zip(
me.expect, brme.expect.values()
):
for me_expectation, brme_expectation in zip(me.expect, brme.expect):
np.testing.assert_allclose(me_expectation, brme_expectation, atol=1e-2)

num = qutip.num(N)
Expand All @@ -91,30 +87,28 @@ def test_harmonic_oscillator(n_th):
np.testing.assert_allclose(me_num, brme_num, atol=1e-2)


def test_jaynes_cummings_zero_temperature():
def test_jaynes_cummings_zero_temperature_spectral_callable():
"""
brmesolve: Jaynes-Cummings model, zero temperature
"""
N = 10
a = qutip.tensor(qutip.destroy(N), qutip.qeye(2))
sp = qutip.tensor(qutip.qeye(N), qutip.sigmap())
psi0 = qutip.ket2dm(qutip.tensor(qutip.basis(N, 1), qutip.basis(2, 0)))
a_ops = [(a + a.dag(), qutip.coefficient(lambda t, w: kappa * (w >= 0)))]
kappa = 0.05
a_ops = [(a + a.dag(), lambda w: kappa * (w >= 0))]
e_ops = [a.dag()*a, sp.dag()*sp]

w0 = 1.0 * 2*np.pi
g = 0.05 * 2*np.pi
kappa = 0.05
times = np.linspace(0, 2 * 2*np.pi / g, 1000)

c_ops = [np.sqrt(kappa) * a]
H = w0*a.dag()*a + w0*sp.dag()*sp + g*(a+a.dag())*(sp+sp.dag())

me = qutip.mesolve(H, psi0, times, c_ops, e_ops)
brme = brmesolve(H, psi0, times, a_ops, e_ops)
for me_expectation, brme_expectation in zip(
me.expect, brme.expect.values()
):
for me_expectation, brme_expectation in zip(me.expect, brme.expect):
# Accept 5% error.
np.testing.assert_allclose(me_expectation, brme_expectation, atol=5e-2)

Expand Down Expand Up @@ -167,12 +161,12 @@ def test_solver_accepts_list_hamiltonian():
psi0 = (2 * qutip.basis(2, 0) + qutip.basis(2, 1)).unit()
times = np.linspace(0, 10, 100)
me = qutip.mesolve(H, psi0, times, c_ops=c_ops, e_ops=e_ops).expect
brme = brmesolve(H, psi0, times, [], e_ops=e_ops, c_ops=c_ops).expect.values()
brme = brmesolve(H, psi0, times, [], e_ops=e_ops, c_ops=c_ops).expect
for me_expectation, brme_expectation in zip(me, brme):
np.testing.assert_allclose(me_expectation, brme_expectation, atol=1e-8)


def test_jaynes_cummings_zero_temperature():
def test_jaynes_cummings_zero_temperature_spectral_str():
N = 10
a = qutip.tensor(qutip.destroy(N), qutip.qeye(2))
sp = qutip.tensor(qutip.qeye(N), qutip.sigmap())
Expand All @@ -190,7 +184,7 @@ def test_jaynes_cummings_zero_temperature():

me = qutip.mesolve(H, psi0, times, c_ops, e_ops)
brme = brmesolve(H, psi0, times, a_ops, e_ops)
for me_expectation, brme_expectation in zip(me.expect, brme.expect.values()):
for me_expectation, brme_expectation in zip(me.expect, brme.expect):
# Accept 5% error.
np.testing.assert_allclose(me_expectation, brme_expectation, atol=5e-2)

Expand Down

0 comments on commit 004045d

Please sign in to comment.