qutip / qutip

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

ZVODE error #822

Closed shiMusa closed 3 years ago

shiMusa commented 6 years ago

Hi QuTip team,

when I run multiple mesolve calculations in parallel using

enumerate(pool.imap(parallel_calculation, taus))

I sometimes get the following error

ZVODE-- At current T (=R1), MXSTEP (=I1) steps taken on this call before reaching TOUT In above message, I1 = 1000 In above message, R1 = 0.9633584757678D+00 D:\...\Anaconda3\lib\site-packages\scipy\integrate\_ode.py:869: UserWarning: zvode: Excess work done on this call. (Perhaps wrong MF.) 'Unexpected istate=%s' % istate))

Interestingly this only happens sometimes and as far as I can tell not in the single-threaded case... Any ideas? Thanks

ajgpitch commented 6 years ago

We use the scipy ode solver. In their documentation https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html they state that for the ZVODE solver

Warning This integrator is not re-entrant. You cannot have two ode instances using the “zvode” integrator at the same time.

This does seem a big shame, as there are of course many good reasons to want to parallelise solving ODEs. Not really sure that there is any easy way around this. Only one of the ode integrators does not carry this warning. We currently don't have any setting that allows switching integrator method

shiMusa commented 6 years ago

Hmmm... interestingly it seems to work sometimes... I think the only way to work around it, is to execute the same program in parallel python consoles? That way each program should live in it's own bubble... I hope :S It's a shame. My problem is so stupidly simple to parallelize.

Thanks anyway.

ajgpitch commented 6 years ago

I'm not really sure why they (Scipy) say it cannot be run in parallel. It must be something in the underlying Fortran. I can't believe it would write anything to file, maybe to environment vars. If that were the case then separate consoles might do it. You could also try some batch processing SW like SLURM if you are on Linux. https://slurm.schedmd.com/ You try asking the Scipy people Please report back if you have any success with anything

nonhermitian commented 6 years ago

Just use the built in QuTiP parallel_map or parfor.

shiMusa commented 6 years ago

Thanks, but I don't want to parallelize a single mesolve-call, but I want to run many distinct mesolve-calls at the same time. Edit: Ok, I'll take a close look tomorrow... Thanks.

shiMusa commented 6 years ago

My current workaround is to write at batch-file that spawns many instances of the program with specific arguments for each instance. Seems to work for now...

nonhermitian commented 6 years ago

The parallel tools in QuTiP can be used for any embarrassing easy parallel computation.

ajgpitch commented 6 years ago

@nonhermitian so do you think we should be able to parallelise using parallel_map when using solvers that use zvode, despite the warning (cited about) given in the Scipy docs?

nonhermitian commented 6 years ago

Have done it many times. There are tutorial notebooks that do it as well.

nonhermitian commented 6 years ago

Each lives in its own interpreter.

jakelishman commented 3 years ago

Closing now as this isn't really a QuTiP issue. SciPy's comment about ZVODE not being re-entrant is only relevant for shared-memory parallelisation (threading), not multiple processes.