jcmgray / quimb

A python library for quantum information and many-body calculations including tensor networks.
http://quimb.readthedocs.io
Other
467 stars 107 forks source link

Tutorial Example for Parallel Execution Broken #58

Closed kkissell closed 4 years ago

kkissell commented 4 years ago

With current code and dependencies (CentOS 8.1, python 3.6.8), the basic tests work, but something seemingly unrelated to parallelization is wrong with the tutorial example quimb/docs/examples/ex_mpi_expm_evo.py. See output below. Apparently it's happening because the Evolution method is being applied with a "callable" Hamiltonian argument, but I'm unclear on how that is supposed to be determined.

[kkissell@qsimmer-1 mpi]$ quimb-mpi-python ex_mpi_expm_evo.py Launching quimb in mpi4py.futures mode with mpiexec. I am worker 0 of total 80 runnning main script... Traceback (most recent call last): File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/usr/local/lib64/python3.6/site-packages/mpi4py/futures/main.py", line 72, in main() File "/usr/local/lib64/python3.6/site-packages/mpi4py/futures/main.py", line 60, in main run_command_line() File "/usr/local/lib64/python3.6/site-packages/mpi4py/run.py", line 47, in run_command_line run_path(sys.argv[0], run_name='main') File "/usr/lib64/python3.6/runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname) File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "ex_mpi_expm_evo.py", line 39, in evo = qu.Evolution(psi0, H, method='expm', expm_backend='slepc') File "/usr/local/lib/python3.6/site-packages/quimb/evo.py", line 403, in init raise TypeError("You can't use the 'expm' method " TypeError: You can't use the 'expm' method with a time-dependent Hamiltonian.

jcmgray commented 4 years ago

This is probably to do with a bad interaction with the Lazy class for constructing rows of hamiltonians locally only and the new time-dependent evolution stuff, I'll have a look.

jcmgray commented 4 years ago

That was indeed the main, issue though running the example I found another bug as well to do with initializing the SLEPc interface, should be fixed by https://github.com/jcmgray/quimb/commit/e18791d915fe9ae1fe44ea57d75267b1e7d9238c. Let me know if its working for you now!

jcmgray commented 4 years ago

Closing as I was able to replicate and fix. Feel free to re-open @kkissell if its still not working.

yuyuexi commented 2 years ago

Hi there, i use the same code as in the quimb/docs/examples/ex_mpi_expm_evo.py, it also ends with error

I am worker 0 of total 1 running main script...
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-8feb8bccdc21> in <module>
     26 #     - should see each worker gets given a different ownership rows
     27 #     - but all end up with the results.
---> 28 evo = qu.Evolution(psi0, H, method='expm', expm_backend='slepc')
     29 evo.update_to(5)
     30 

~/anaconda3/lib/python3.8/site-packages/quimb/evo.py in __init__(self, p0, ham, t0, compute, method, int_small_step, expm_backend, expm_opts, progbar)
    360                                 "Hamiltonian.")
    361             elif self._timedep:
--> 362                 raise TypeError("You can't use the 'expm' method "
    363                                 "with a time-dependent Hamiltonian.")
    364             self._update_method = self._update_to_expm_ket

TypeError: You can't use the 'expm' method with a time-dependent Hamiltonian.

The code is as following

import quimb as qu
from mpi4py import MPI

# Get some MPI information
comm = MPI.COMM_WORLD
rank, size = comm.Get_rank(), comm.Get_size()
print(f"I am worker {rank} of total {size} running main script...")

# setup a verbose version of the ham_heis constructor, and make it Lazy
n = 18
shape = (2**n, 2**n)

# this makes the function print some information when called
#     - in order to be pickled is has to be located in the main package
ham_heis_verbose = qu.utils.Verbosify(qu.ham_heis,
                                      highlight='ownership', mpi=True)

H = qu.Lazy(ham_heis_verbose, n=n, sparse=True, shape=shape)

# random initial state
#     - must make sure all processes have the same seed to be pure
psi0 = qu.rand_ket(2**n, seed=42)

# evolve the system, processes split 'hard' work (slepc computations)
#     - should see each worker gets given a different ownership rows
#     - but all end up with the results.
evo = qu.Evolution(psi0, H, method='expm', expm_backend='slepc')
evo.update_to(5)

print(f"{rank}: I have final state norm {qu.expec(evo.pt, evo.pt)}")

I am using Python 3.8.8 and quimb 1.3.0. Did i do something wrong?