Repository: qutip/qutip

Issue:
qutip.propagator and array with a single value
Hi,

I may have missed something but from the docstrings, I would expect the last two lines of this example script to actually return the same thing:

```python
>>> import numpy as np
>>> import qutip
>>> omega_0 = 1.0 * 2 * np.pi
>>> Omega = 0.1 * 2 * np.pi
>>> omega_d = 1.5 * 2 * np.pi
>>> T = 2 * np.pi / omega_d

>>> H0 = omega_0 / 2.0 * qutip.sigmaz()
>>> H1 = Omega * qutip.sigmax()
>>> H2 = Omega * qutip.sigmay()

>>> H = [H0, [H1, 'cos(w_d * t)'], [H2, 'sin(w_d * t)']]
>>> args = {'w_d': omega_d}

>>> (qutip.propagator(H, t, c_op_list=[], args=args) - qutip.propagator(H, [t], c_op_list=[], args=args)).norm()
0.04271636357907908

>>> (qutip.propagator(H, t, c_op_list=[], args=args) - qutip.propagator(H, [0, t], c_op_list=[], args=args)).norm()
0.0
```

That is, I would expect `qutip.propagator(H, t, c_op_list=[], args=args)` to give the same result as `qutip.propagator(H, [t], c_op_list=[], args=args)` (single `t` value or array of times with a single `t` element). This does not seem to be the case here, with a not negligible difference.

Is this an expected behavior (which would probably deserve more emphasis in the doc)?

Thanks!
Best,


Discussion:
Hi,
The documentation is not clear for this and propagator is a little strange for `t`.

Propagator uses the `t` as a list the same way `tlist` is used by `sesovle` or `mesolve` and those solver support continuing an evolution:
```
H = [op1, [op2, f]]
res1 = qutip.sesolve(H, psi0, tlist=[0,1,2,3,4])
res2 = qutip.sesolve(H, res1.states[-1], tlist=[4,5,3,7,8])
```
So if `tlist` is a list with one element, it does no evolution and the propagator is 1 (`qeye`).

If you were to compute propagators with `tlist` with 3 or more elements, you would receive a list of propagator and the first one would always be 1.

I am not sure where or if it is documented that evolution starts at the first element of the list of time, not at zero.

Hope this help.




Hi,

Thanks for digging into this! Given the docstring of `qutip.propagator`, this behavior was unexpected for me https://github.com/qutip/qutip/blob/master/qutip/propagator.py#L62-L76.

Changing the propagator to consider a list with a single element as a single float value (`[t]` would be the same as `t`) would break the current API and could eventually break some scripts built using QuTiP and using the fact that `qutip.propagator` of `[t]` gives identity.

The best way to fix this would probably be to edit the docstring to emphasize the expected behavior for a single `t` value and for a list of times.

P.S.: Not directly related to this issue but when looking for QuTiP doc on search engines, it often sends to documentation for old versions of QuTiP. Typically http://qutip.org/docs/4.0.2/apidoc/functions.html#module-qutip.propagator. What about putting a banner on these legacy documentations online stating that "You are reading the documentation of an older version of QuTiP. Latest documentation is available at http://qutip.org/docs/latest/apidoc/functions.html#module-qutip.propagator" (for instance)?

Best,
About the old documentation versions coming up: I think the idea to mitigate this was the introduction of /latest/, which eventually should trump older results on the search engine. For the disclaimer, it could be nice and maybe easy to add a generic banner (valid for all functions).
I am a new user of QuTiP. When using `mesolve()` with a single-element `tlist` I run into the same issue. After spending a lot of time debugging and finally reaching here, I think this behavior could be noted in the documentation...

Resolving patch:
diff --git a/qutip/solver/propagator.py b/qutip/solver/propagator.py
--- a/qutip/solver/propagator.py
+++ b/qutip/solver/propagator.py
@@ -28,7 +28,11 @@ def propagator(H, t, c_ops=(), args=None, options=None, **kwargs):
         that can be made into :obj:`.QobjEvo` are also accepted.
 
     t : float or array-like
-        Time or list of times for which to evaluate the propagator.
+        Time or list of times for which to evaluate the propagator. If a single
+        time ``t`` is passed, the propagator from ``0`` to ``t`` is computed.
+        When ``t`` is a list, the propagators from the first time in the list
+        to each elements in ``t`` is returned. In that case, the first output
+        will always be the identity matrix.
 
     c_ops : list, optional
         List of Qobj or QobjEvo collapse operators.


Test patch: