qutip icon indicating copy to clipboard operation
qutip copied to clipboard

Exception: ODE integration error: Try to increase the allowed number of substeps by increasing the nsteps parameter in the Options class.

Open andriusdc opened this issue 3 years ago • 13 comments

I am having some trouble with the function mesolve. The situation is the following: I have a collection of Hamiltonians and Jump Operators which includes 69 timesteps each, and I want to evolve a initial state to each of this timesteps. However, Qutip is returning "Exception: ODE integration error: Try to increase the allowed number of substeps by increasing the nsteps parameter in the Options class.". I tryied to change nsteps parameter but it just doesnt work for any value of it, no matter how big the number is.

H= Hamiltonian, shape: 69,2,2 list_Jump-op= Jump operators, shape:69,2,2 time= timesteps, shape (69,) estados_val= the different states that I want to evolve on this dynamics, shape( 6,69,2,2) . Note that I am only taking the 0th element on the axis with lenght of 69

predictions=[mesolve(H, Qobj(estados_val[i][0]), time,list_Jump_op,options=Options(nsteps=10000000000000000)) for i in range(len(estados_val))]

The terminal out put is /home/andrius/anaconda3/lib/python3.8/site-packages/scipy/integrate/_ode.py:1013: UserWarning: zvode: Excess accuracy requested. (Tolerances too small.) warnings.warn('{:s}: {:s}'.format(self.class.name,

Exception Traceback (most recent call last) in 40 41 la=10000000000000000 ---> 42 predictions=[mesolve(H, 43 Qobj(estados_val[i][0]), 44 time[1:],list_Jump_op,options=Options(nsteps=la)) for i in range(len(estados_val))]

in (.0) 40 41 la=10000000000000000 ---> 42 predictions=[mesolve(H, 43 Qobj(estados_val[i][0]), 44 time[1:],list_Jump_op,options=Options(nsteps=la)) for i in range(len(estados_val))]

~/anaconda3/lib/python3.8/site-packages/qutip/mesolve.py in mesolve(H, rho0, tlist, c_ops, e_ops, args, options, progress_bar, _safe_mode) 270 func(0., v, *ode_args) + v 271 --> 272 res = _generic_ode_solve(func, ode_args, rho0, tlist, e_ops, options, 273 progress_bar, dims=rho0.dims) 274 res.num_collapse = len(c_ops)

~/anaconda3/lib/python3.8/site-packages/qutip/mesolve.py in _generic_ode_solve(func, ode_args, rho0, tlist, e_ops, opt, progress_bar, dims) 515 516 if not r.successful(): --> 517 raise Exception("ODE integration error: Try to increase " 518 "the allowed number of substeps by increasing " 519 "the nsteps parameter in the Options class.")

Exception: ODE integration error: Try to increase the allowed number of substeps by increasing the nsteps parameter in the Options class.

Expected behavior The time evolution of the 0th states

This is it. Am I doing something wrong with it ?

andriusdc avatar Jul 13 '21 13:07 andriusdc

Yes, this error always comes up when doing something wrong. However, in order to understand what that is, we need to see the actual system being solved.

nonhermitian avatar Jul 13 '21 13:07 nonhermitian

Which additional information do you need ?

andriusdc avatar Jul 13 '21 13:07 andriusdc

@andriusdc The easiest would be if you supplied a short snippet of Python code that when runs, reproduces this error.

hodgestar avatar Jul 13 '21 13:07 hodgestar

@andriusdc If you are having trouble formatting the code nicely, I suggest reading the GitHub markdown guide -- https://guides.github.com/features/mastering-markdown/.

hodgestar avatar Jul 13 '21 13:07 hodgestar

I made a snipped with dummy arrays that reproduce the error. Is it enough?

H=[]

timelist_Jump_op=[]
time=[]
for i in range(t):
    H.append(Qobj(np.ones((2,2))))
    list_Jump_op.append(Qobj(np.ones((2,2))))
    time.append(0.5)

estados_val=np.array([
[[ 0.4952317 +0.j        ,  0.35307695-0.22776115j],
        [ 0.35307695+0.22776115j,  0.5047683 +0.j        ]],

[[ 0.80942518+0.j        ,  0.14798043+0.36381018j],
        [ 0.14798043-0.36381018j,  0.19057482+0.j        ]],

 [[ 0.74030166+0.j        , -0.42252924+0.11715014j],
        [-0.42252924-0.11715014j,  0.25969834+0.j        ]],
[[ 0.76627252+0.j        ,  0.14479804+0.39765874j],
        [ 0.14479804-0.39765874j,  0.23372748+0.j        ]],
[[ 0.69965345+0.j        ,  0.4260361 -0.16920917j],
        [ 0.4260361 +0.16920917j,  0.30034655+0.j        ]],
[[ 0.80355468+0.j        ,  0.36706718-0.15204028j],
        [ 0.36706718+0.15204028j,  0.19644532+0.j        ]]])    

predictions=[mesolve(H,
        Qobj(estados_val[i]),
        time,list_Jump_op,options=Options(nsteps=1000000000)) for i in range(len(estados_val))]`

```
`---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-26-ef5799d8412d> in <module>
     26         [ 0.36706718+0.15204028j,  0.19644532+0.j        ]]])    
     27 
---> 28 predictions=[mesolve(H,
     29         Qobj(estados_val[i]),
     30         time,list_Jump_op,options=Options(nsteps=1000000000)) for i in range(len(estados_val))]

<ipython-input-26-ef5799d8412d> in <listcomp>(.0)
     26         [ 0.36706718+0.15204028j,  0.19644532+0.j        ]]])    
     27 
---> 28 predictions=[mesolve(H,
     29         Qobj(estados_val[i]),
     30         time,list_Jump_op,options=Options(nsteps=1000000000)) for i in range(len(estados_val))]

~/anaconda3/lib/python3.8/site-packages/qutip/mesolve.py in mesolve(H, rho0, tlist, c_ops, e_ops, args, options, progress_bar, _safe_mode)
    270         func(0., v, *ode_args) + v
    271 
--> 272     res = _generic_ode_solve(func, ode_args, rho0, tlist, e_ops, options,
    273                              progress_bar, dims=rho0.dims)
    274     res.num_collapse = len(c_ops)

~/anaconda3/lib/python3.8/site-packages/qutip/mesolve.py in _generic_ode_solve(func, ode_args, rho0, tlist, e_ops, opt, progress_bar, dims)
    515 
    516         if not r.successful():
--> 517             raise Exception("ODE integration error: Try to increase "
    518                             "the allowed number of substeps by increasing "
    519                             "the nsteps parameter in the Options class.")

Exception: ODE integration error: Try to increase the allowed number of substeps by increasing the nsteps parameter in the Options class.`

andriusdc avatar Jul 13 '21 14:07 andriusdc

This fails because time only contain 0.5. You probably meant time.append(0.5*i).

The error message is a catch-all for failure in scipy solver and certainly not clear.

Ericgig avatar Jul 13 '21 15:07 Ericgig

@Ericgig Could we check whether tlist is monotonic when _safe_mode is true? It might make the error clearer.

hodgestar avatar Jul 13 '21 15:07 hodgestar

Yes, we should catch any error before the ode solver when we can,

Ericgig avatar Jul 13 '21 15:07 Ericgig

Here is the actual time array:

np.array([-0.00000000e+00,  5.18297470e-04,  2.07372742e-03,  4.66790472e-03,
        8.30352825e-03,  1.29843922e-02,  1.87154020e-02,  2.55025949e-02,
        3.33531656e-02,  4.22754975e-02,  5.22791985e-02,  6.33751435e-02,
        7.55755230e-02,  8.88938976e-02,  1.03345261e-01,  1.18946111e-01,
        1.35714525e-01,  1.53670253e-01,  1.72834813e-01,  1.93231602e-01,
        2.14886020e-01,  2.37825606e-01,  2.62080191e-01,  2.87682072e-01,
        3.14666199e-01,  3.43070392e-01,  3.72935580e-01,  4.04306071e-01,
        4.37229853e-01,  4.71758940e-01,  5.07949752e-01,  5.45863557e-01,
        5.85566963e-01,  6.27132487e-01,  6.70639199e-01,  7.16173460e-01,
        7.63829779e-01,  8.13711791e-01,  8.65933399e-01,  9.20620106e-01,
        9.77910565e-01,  1.03795841e+00,  1.10093440e+00,  1.16702903e+00,
        1.23645557e+00,  1.30945377e+00,  1.38629436e+00,  1.46728456e+00,
        1.55277483e+00,  1.64316728e+00,  1.73892632e+00,  1.84059204e+00,
        1.94879757e+00,  2.06429163e+00,  2.18796836e+00,  2.32090751e+00,
        2.46442950e+00,  2.62017261e+00,  2.79020378e+00,  2.97718244e+00,
        3.18461090e+00,  3.41723282e+00,  3.68169927e+00,  3.98775156e+00,
        4.35049241e+00,  4.79522366e+00,  5.36937802e+00,  6.17944429e+00,
        7.56522035e+00,             1000])

andriusdc avatar Jul 13 '21 17:07 andriusdc

Hello friends. Any news on that issue ? Is it something coming from Scipy ?

andriusdc avatar Jul 22 '21 13:07 andriusdc

Is the last time a typo? It would work with 10. but going from 7.5 to 1000 is too much work for one step. If you want the state after the evolution stabilized, you should look at steadystate.

Ericgig avatar Jul 22 '21 16:07 Ericgig

Actualy is a arbitrary large number to simulate the system going through total decoherence. Maybe this was cause of the crash ?

andriusdc avatar Jul 23 '21 12:07 andriusdc

Very probably. The integrator doesn't know what you're trying to achieve, and you've set it exact tolerance limits (either implicitly or explicitly), so it has to integrate within those limits. If you want the steady-state solution, you can try qutip.steadystate instead.

jakelishman avatar Jul 25 '21 19:07 jakelishman

I think this issue was fully explained, so closing for now, but please reply if something further is needed.

hodgestar avatar Dec 10 '22 16:12 hodgestar