You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, this code generates an error complaining ValueError: tlist must be the same len as the array to interpolate. This is due to a line of wrong code inside propagator() function:
In the last line above, the code forgot to pass tlist=tlist to QobjEvo. This is an optional argument only required when no coefficients are supplied as numpy arrays. Therefore, when we feed a numpy array to propagator and then to QobjEvo, it is reported ValueError: tlist must be the same len as the array to interpolate, while the real error here is because no tlist is provided.
You can compare it to the correct code in mesolve:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[26], line 2
1 tlist = np.linspace(0, 50, 500)
----> 2 q.propagator([[q.sigmax(), np.cos(tlist)]], tlist).states[-1]
File c:\Users\neohu\.conda\envs\de\Lib\site-packages\qutip\solver\propagator.py:62, in propagator(H, t, c_ops, args, options, **kwargs)
59 list_output = True
61 if not isinstance(H, (Qobj, QobjEvo)):
---> 62 H = QobjEvo(H, args=args, **kwargs)
64 if c_ops:
65 H = liouvillian(H, c_ops)
File c:\Users\neohu\.conda\envs\de\Lib\site-packages\qutip\core\cy\qobjevo.pyx:223, inqutip.core.cy.qobjevo.QobjEvo.__init__()
File c:\Users\neohu\.conda\envs\de\Lib\site-packages\qutip\core\cy\qobjevo.pyx:272, inqutip.core.cy.qobjevo.QobjEvo._read_element()
File c:\Users\neohu\.conda\envs\de\Lib\site-packages\qutip\core\coefficient.py:175, in coefficient(base, tlist, args, args_ctypes, order, compile_opt, function_style, boundary_conditions, **kwargs)
173 fortype_in coefficient_builders:
174 if isinstance(base, type_):
--> 175 return coefficient_builders[type_](base, **kwargs)
177 if callable(base):
178 op = FunctionCoefficient(base, args.copy(), style=function_style)
File c:\Users\neohu\.conda\envs\de\Lib\site-packages\qutip\core\cy\coefficient.pyx:418, inqutip.core.cy.coefficient.InterCoefficient.__init__()
ValueError: tlist must be the same len as the array to interpolate
Expected Behaviour
Code should run without error.
Your Environment
Note that this problem is persistent in the latest 5.0.2, because I checked the source code.
QuTiP Version: 5.0.1
Numpy Version: 1.26.4
Scipy Version: 1.12.0
Cython Version: None
Matplotlib Version: None
Python Version: 3.11.5
Number of CPUs: 12
BLAS Info: Generic
INTEL MKL Ext: False
Platform Info: Windows (AMD64)
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Bug Description
The
propagator()
function SHOULD support the array-coefficient format:propagator(H=[[sigmax(), np.cos(tlist)]], tlist=tlist)
However, this code generates an error complaining
ValueError: tlist must be the same len as the array to interpolate
. This is due to a line of wrong code insidepropagator()
function:In the last line above, the code forgot to pass
tlist=tlist
toQobjEvo
. This is an optional argument only required when no coefficients are supplied as numpy arrays. Therefore, when we feed a numpy array topropagator
and then toQobjEvo
, it is reportedValueError: tlist must be the same len as the array to interpolate
, while the real error here is because no tlist is provided.You can compare it to the correct code in
mesolve
:Code to Reproduce the Bug
tlist = np.linspace(0, 50, 500) q.propagator([[q.sigmax(), np.cos(tlist)]], tlist)
Code Output
Expected Behaviour
Code should run without error.
Your Environment
Additional Context
No response
The text was updated successfully, but these errors were encountered: