qutip / qutip

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

fmmesolve persistent error? #1663

Closed sahrak closed 3 years ago

sahrak commented 3 years ago

Describe the bug I am simply trying to run the code published on the qutip documentation website for the https://qutip.org/docs/latest/guide/dynamics/dynamics-floquet.html

I copied the code under the section: Pre-computing the Floquet modes for one period, and that worked fine, but then at the end of the section they point towards the function 'fsesolve' which would be the 'all-in-one' version of the code given previously, however it doesnt work and i get the error:

~\anaconda3\lib\site-packages\qutip\sesolve.py in _generic_ode_solve(func, ode_args, psi0, tlist, e_ops, opt, progress_bar, dims)
    297     if ode_args:
    298         r.set_f_params(*ode_args)
--> 299     r.set_initial_value(initial_vector, tlist[0])
    300 
    301     e_ops_data = []

KeyError: 0

The code:

import numpy as np
from matplotlib import pyplot
import qutip

delta = 0.0  * 2*np.pi
eps0  = 1.0 * 2*np.pi
A     = 0.25 * 2*np.pi
omega = 1.0 * 2*np.pi
T      = 2*np.pi / omega
tlist  = np.linspace(0.0, 10 * T, 101)
psi0   = qutip.thermal_dm(2,0)

H0 = - delta/2.0 * qutip.sigmax() - eps0/2.0 * qutip.sigmaz()
H1 = A/2.0 * qutip.sigmax()
args = {'w': omega}
H = [H0, [H1, lambda t, args: np.sin(args['w'] * t)]]

output = qutip.fsesolve(H, psi0, tlist, [], args)
p_ex = output.expect[0]

Your Environment QuTiP Version: 4.5.3 Numpy Version: 1.18.5 Scipy Version: 1.6.2 Cython Version: 0.29.23 Matplotlib Version: 3.2.2 Python Version: 3.8.3 Number of CPUs: 6 BLAS Info: INTEL MKL OPENMP Installed: False INTEL MKL Ext: True Platform Info: Windows (AMD64)

Additional context Add any other context about the problem here.

hodgestar commented 3 years ago

@sahrak Thank you for reporting this. The parameters for sesolve changed slightly since the guide was written and the guide wasn't updated. I will make a PR to fix it shortly, but in the mean time you can run:

qutip.floquet.fsesolve(H, psi0=psi0, tlist=tlist, e_ops=[qutip.num(2)], args=args)
hodgestar commented 3 years ago

@sahrak If #1675 works for you, I will merge it.