From e2cbddd0df45c3a04aa1a0b14f9f8f76d504ec6c Mon Sep 17 00:00:00 2001 From: Eric Giguere Date: Tue, 8 Oct 2024 14:09:18 -0400 Subject: [PATCH] Add a test --- qutip/solver/propagator.py | 16 ++++++++-------- qutip/tests/solver/test_propagator.py | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/qutip/solver/propagator.py b/qutip/solver/propagator.py index 93d1eeae60..f42dd279fd 100644 --- a/qutip/solver/propagator.py +++ b/qutip/solver/propagator.py @@ -60,9 +60,9 @@ def propagator( **kwargs : Extra parameters to use when creating the - :obj:`.QobjEvo` from a list format ``H``. The most common as ``tlist`` - and ``order`` for spline time dependance. See :obj:`.QobjEvo` for the - full list. + :obj:`.QobjEvo` from a list format ``H``. The most common are ``tlist`` + and ``order`` for array-based time dependance. See :obj:`.QobjEvo` for + the full list. Returns ------- @@ -72,9 +72,9 @@ def propagator( Notes ----- - Unlike :func:`.sesolve` or :func:`.mesolve`, the output times ``t`` are not - used for time dependent system with array based. ``tlist`` must be passed - as a keyword argument in those case. ``tlist`` and ``t`` can have different + Unlike :func:`.sesolve` or :func:`.mesolve`, the output times in ``t`` are + not used for array time dependent system. ``tlist`` must be passed as a + keyword argument in those case. ``tlist`` and ``t`` can have different length and values. """ @@ -89,9 +89,9 @@ def propagator( H = QobjEvo(H, args=args, **kwargs) if isinstance(c_ops, list): - c_ops = [QobjEvo(op, args=args, **kwargs) for op in c_ops)] + c_ops = [QobjEvo(op, args=args, **kwargs) for op in c_ops] - if c_ops is not None: + if c_ops: H = liouvillian(H, c_ops) U0 = qeye_like(H) diff --git a/qutip/tests/solver/test_propagator.py b/qutip/tests/solver/test_propagator.py index ffb335cbe3..0db507c2df 100644 --- a/qutip/tests/solver/test_propagator.py +++ b/qutip/tests/solver/test_propagator.py @@ -2,11 +2,11 @@ from scipy.integrate import trapezoid from qutip import (destroy, propagator, Propagator, propagator_steadystate, steadystate, tensor, qeye, basis, QobjEvo, sesolve, - liouvillian) + liouvillian, rand_dm) import qutip import pytest from qutip.solver.brmesolve import BRSolver -from qutip.solver.mesolve import MESolver +from qutip.solver.mesolve import MESolver, mesolve from qutip.solver.sesolve import SESolver from qutip.solver.mcsolve import MCSolver @@ -49,6 +49,20 @@ def testPropHOTd(): assert (U - U2).norm('max') < 1e-4 +def testPropHOTd(): + "Propagator: func array td format + open" + a = destroy(5) + H = a.dag()*a + ts = np.linspace(-0.01, 1.01, 103) + coeffs = np.cos(ts) + Htd = [H, [H, coeffs]] + rho_0 = rand_dm(5) + rho_1_prop = propagator(Htd, 1, c_ops=[a], tlist=ts)(rho_0) + rho_1_me = mesolve(QobjEvo(Htd, tlist=ts), rho_0, [0, 1], [a]).final_state + + assert (rho_1_prop - rho_1_me).norm('max') < 1e-4 + + def testPropObjTd(): a = destroy(5) H = a.dag()*a