Skip to content

Commit

Permalink
Add back tests for dummy time-dependent QobjEvos.
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Jun 24, 2022
1 parent 72c26ee commit 4e3add8
Showing 1 changed file with 46 additions and 23 deletions.
69 changes: 46 additions & 23 deletions qutip/tests/solve/test_bofin_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
)


def assert_raises_steady_state_time_dependent(hsolver):
""" Assert that calling .steady_state() on a HEOMSolver with
a time-dependent Hamiltonian raises the appropriate exception.
"""
with pytest.raises(ValueError) as err:
hsolver.steady_state()
assert str(err.value) == (
"A steady state cannot be determined for a time-dependent"
" system"
)


class TestHierarchyADOs:
def mk_exponents(self, dims):
return [
Expand Down Expand Up @@ -471,8 +483,8 @@ def C(sigma, mu):

_HAMILTONIAN_EVO_KINDS = {
"qobj": lambda H: H,
"qobjevo": lambda H: QobjEvo([H]),
"listevo": lambda H: [H],
"qobjevo_const": lambda H: QobjEvo([H]),
"qobjevo_timedep": lambda H: QobjEvo([H, lambda t: 1.0]),
}


Expand Down Expand Up @@ -609,8 +621,8 @@ def solve_method(rho0):

@pytest.mark.parametrize(['evo'], [
pytest.param("qobj", id="qobj"),
pytest.param("qobjevo", id="qobjevo"),
pytest.param("listevo", id="listevo"),
pytest.param("qobjevo_const", id="qobjevo_const"),
pytest.param("qobjevo_timedep", id="qobjevo_timedep"),
])
@pytest.mark.parametrize(['liouvillianize'], [
pytest.param(False, id="hamiltonian"),
Expand All @@ -636,11 +648,15 @@ def test_pure_dephasing_model_bosonic_bath(
expected = dlm.analytic_results(tlist)
np.testing.assert_allclose(test, expected, atol=atol)

rho_final, ado_state = hsolver.steady_state()
test = dlm.state_results([rho_final])
expected = dlm.analytic_results([100])
np.testing.assert_allclose(test, expected, atol=atol)
assert rho_final == ado_state.extract(0)
if evo != "qobjevo_timedep":
rho_final, ado_state = hsolver.steady_state()
test = dlm.state_results([rho_final])
expected = dlm.analytic_results([100])
np.testing.assert_allclose(test, expected, atol=atol)
assert rho_final == ado_state.extract(0)
else:
assert_raises_steady_state_time_dependent(hsolver)


@pytest.mark.parametrize(['terminator'], [
pytest.param(True, id="terminator"),
Expand Down Expand Up @@ -710,8 +726,8 @@ def test_underdamped_pure_dephasing_model_underdamped_bath(

@pytest.mark.parametrize(['evo'], [
pytest.param("qobj"),
pytest.param("qobjevo"),
pytest.param("listevo"),
pytest.param("qobjevo_const"),
pytest.param("qobjevo_timedep"),
])
@pytest.mark.parametrize(['liouvillianize'], [
pytest.param(False, id="hamiltonian"),
Expand All @@ -738,10 +754,14 @@ def test_discrete_level_model_fermionic_bath(self, evo, liouvillianize):
analytic_current = dlm.analytic_current()
np.testing.assert_allclose(analytic_current, current, rtol=1e-3)

rho_final, ado_state = hsolver.steady_state()
current = dlm.state_current(ado_state)
analytic_current = dlm.analytic_current()
np.testing.assert_allclose(analytic_current, current, rtol=1e-3)
if evo != "qobjevo_timedep":
rho_final, ado_state = hsolver.steady_state()
current = dlm.state_current(ado_state)
analytic_current = dlm.analytic_current()
np.testing.assert_allclose(analytic_current, current, rtol=1e-3)
else:
assert_raises_steady_state_time_dependent(hsolver)


@pytest.mark.parametrize(['bath_cls', 'analytic_current'], [
pytest.param(LorentzianBath, 0.001101, id="matsubara"),
Expand Down Expand Up @@ -872,9 +892,9 @@ class TestHSolverDL:
])
@pytest.mark.parametrize(['evo', 'combine'], [
pytest.param("qobj", True, id="qobj-combined"),
pytest.param("qobjevo", True, id="qobjevo-combined"),
pytest.param("listevo", True, id="listevo-combined"),
pytest.param("qobj", False, id="qobj-uncombined"),
pytest.param("qobjevo_const", True, id="qobjevo-const-combined"),
pytest.param("qobjevo_timedep", True, id="qobjevo-timedep-combined"),
pytest.param("qobjevo_timedep", False, id="qobjevo-timedep-uncombined"),
])
@pytest.mark.parametrize(['liouvillianize'], [
pytest.param(False, id="hamiltonian"),
Expand Down Expand Up @@ -902,11 +922,14 @@ def test_pure_dephasing_model(
expected = dlm.analytic_results(tlist)
np.testing.assert_allclose(test, expected, atol=atol)

rho_final, ado_state = hsolver.steady_state()
test = dlm.state_results([rho_final])
expected = dlm.analytic_results([100])
np.testing.assert_allclose(test, expected, atol=atol)
assert rho_final == ado_state.extract(0)
if evo != "qobjevo_timedep":
rho_final, ado_state = hsolver.steady_state()
test = dlm.state_results([rho_final])
expected = dlm.analytic_results([100])
np.testing.assert_allclose(test, expected, atol=atol)
assert rho_final == ado_state.extract(0)
else:
assert_raises_steady_state_time_dependent(hsolver)

@pytest.mark.parametrize(['bnd_cut_approx', 'tol'], [
pytest.param(True, 1e-4, id="bnd_cut_approx"),
Expand Down

0 comments on commit 4e3add8

Please sign in to comment.