qutip / qutip

QuTiP: Quantum Toolbox in Python
https://qutip.org
BSD 3-Clause "New" or "Revised" License
1.69k stars 635 forks source link

QuTiP 5 - Inconsistent return in `correlation_2op_2t()` #2018

Closed christian512 closed 1 year ago

christian512 commented 1 year ago

Bug Description

Recent changes in correlation_2op_2t() modified the type of return value.

Previously, if tlist = None the correlation function returned a 1D array for the values at taulist. Now it returns a 2D array instead with shape (1, n).

For backwards compatability should we return a 1D array? If not, we should at least change the description of the function

Code to Reproduce the Bug

from qutip import correlation_2op_2t, destroy, coherent_dm
import numpy as np
N = 2
taulist = np.linspace(0, 10.0, 200)
a = destroy(N)
H = 2 * np.pi * a.dag() * a
rho0 = coherent_dm(N, 2.0)
G1 = correlation_2op_2t(H, rho0, None, taulist, [], a.dag(), a)
print(G1.shape)

Code Output

(1,200)

Expected Behaviour

A 1D array with shape (200,).

Your Environment

QuTiP Version:      5.0.0.dev0+1ede0b8
Numpy Version:      1.23.4
Scipy Version:      1.9.3
Cython Version:     0.29.32
Matplotlib Version: 3.6.2
Python Version:     3.10.7
Number of CPUs:     4
BLAS Info:          OPENBLAS
INTEL MKL Ext:      False
Platform Info:      Linux (x86_64)

Additional Context

No response

Ericgig commented 1 year ago

Should we have it fails if tlist is None? This function explicitly says it's 2 time correlation.

christian512 commented 1 year ago

Just changing the docstring to something like "If tlist is None, tlist=[0] is assumed and the corresponding correlation matrix returned." should be enough, I think. The implementation in QuTiP 4 returned this 1D array, which confused me. Changing the behavior broke one tutorial notebook, but a clear docstring should help users to see what the problem is.

hodgestar commented 1 year ago

Documentation updated in #2021.