Example #1
0
    def test_project_eig(self, backend):
        Hl = qu.Lazy(qu.ham_heis, 4, sparse=True, shape=(16, 16))
        Pl = qu.Lazy(qu.zspin_projector, 4, shape=(16, 6))

        ge, gs = qu.eigh(Hl, P=Pl, k=1, backend=backend)

        assert ge == pytest.approx(-2)
        assert qu.expec(gs, gs) == pytest.approx(1.0)
Example #2
0
 def test_basic(self, sparse):
     ownership = (0, 7)
     hl = qu.Lazy(qu.ham_heis, n=4, sparse=sparse, shape=(16, 16))
     print(hl)
     h = 1 * hl(ownership=ownership)
     h_ex = qu.ham_heis(n=4, sparse=sparse)[slice(*ownership), :]
     assert_allclose(h.A, h_ex.A)
Example #3
0
# 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} runnning 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)}")

# Now lets demonstrate using the MPI pool construct
pool = qu.get_mpi_pool()