Exemplo n.º 1
0
 def test_thermal_state_tuple(self):
     full = rand_herm(2**4)
     l, v = eigsys(full)
     for beta in (0, 0.5, 1, 10):
         rhoth1 = thermal_state(full, beta)
         rhoth2 = thermal_state((l, v), beta)
         assert_allclose(rhoth1, rhoth2)
Exemplo n.º 2
0
 def test_eigsys(self, mat_herm_dense, bkd):
     u, a = mat_herm_dense
     evals, v = eigsys(a, backend=bkd)
     assert(set(np.rint(evals)) == set((-1, 2, 4, -3)))
     assert_allclose(evals, [-3, -1, 2, 4])
     for i, j in zip([3, 0, 1, 2], range(4)):
         o = u[:, i].H @ v[:, j]
         assert_allclose(abs(o), 1.)
Exemplo n.º 3
0
    def test_exp_sparse(self):

        a = rand_herm(100, sparse=True, density=0.1)
        k = rand_ket(100)

        out = mfn_multiply_slepc(a, k)

        al, av = eigsys(a.A)
        expected = av @ np.diag(np.exp(al)) @ av.conj().T @ k

        assert_allclose(out, expected)
Exemplo n.º 4
0
    def test_1(self):
        a = rand_herm(100, sparse=True)
        el, ev = eigsys(a.A)
        which = abs(el) < 0.2
        el, ev = el[which], ev[:, which]

        offset = norm(a, 'fro')
        a = a + offset * sp.eye(a.shape[0])

        sl, sv = seigsys_slepc(a, l_win=(-0.2 + offset, 0.2 + offset))
        sl -= offset
        assert_allclose(el, sl)
        assert_allclose(np.abs(sv.H @ ev), np.eye(el.size), atol=1e-11)
Exemplo n.º 5
0
    def test_expm_multiply(self, num_workers, bigsparsemat, big_vec):
        a = bigsparsemat
        k = big_vec

        if ((num_workers is not None) and ALREADY_RUNNING_AS_MPI
                and num_workers > 1 and num_workers != NUM_MPI_WORKERS):
            with pytest.raises(ValueError):
                mfn_multiply_slepc_spawn(a, k, num_workers=num_workers)

        else:
            out = mfn_multiply_slepc_spawn(a, k, num_workers=num_workers)
            al, av = eigsys(a.A)
            expected = av @ np.diag(np.exp(al)) @ av.conj().T @ k
            assert_allclose(out, expected)
Exemplo n.º 6
0
    def test_sqrt_sparse(self):
        import scipy.sparse as sp

        a = rand_pos(32, sparse=True, density=0.1)
        a = a + 0.001 * sp.eye(32)
        k = rand_ket(32)

        out = mfn_multiply_slepc(a, k, fntype='sqrt', isherm=True)

        al, av = eigsys(a.A)
        al[al < 0] = 0.0  # very small neg values spoil sqrt
        expected = av @ np.diag(np.sqrt(al)) @ av.conj().T @ k

        assert_allclose(out, expected, rtol=1e-6)
Exemplo n.º 7
0
 def test_quevo_ham_dense_ket_solve(self, ham_rcr_psi, sparse, presolve):
     ham, trc, p0, tm, pm = ham_rcr_psi
     ham = qu(ham, sparse=sparse)
     if presolve:
         l, v = eigsys(ham)
         sim = QuEvo(p0, (l, v))
         assert sim._solved
     else:
         sim = QuEvo(p0, ham, method='solve')
     sim.update_to(tm)
     assert_allclose(sim.pt, pm)
     assert expec(sim.pt, p0) < 1.0
     sim.update_to(trc)
     assert_allclose(sim.pt, p0)
     assert isinstance(sim.pt, np.matrix)
     assert sim.t == trc
Exemplo n.º 8
0
    def test_explicit_sweeps(self):
        # import pdb; pdb.set_trace()
        n = 8
        chi = 16
        ham = MPO_ham_mbl(n, dh=5, run=42)
        p0 = MPS_neel_state(n).expand_bond_dimension(chi)

        b0 = p0.H
        align_TN_1D(p0, ham, b0, inplace=True)
        en0 = np.asscalar(p0 & ham & b0 ^ ...)

        dmrgx = DMRGX(ham, p0, chi)
        dmrgx.sweep_right()
        en1 = dmrgx.sweep_left(canonize=False)
        assert en0 != en1

        dmrgx.sweep_right(canonize=False)
        en = dmrgx.sweep_right(canonize=True)

        # check normalized
        assert_allclose(dmrgx._k.H @ dmrgx._k, 1.0)

        k = dmrgx._k.to_dense()
        h = ham.to_dense()
        el, ev = eigsys(h)

        # check variance very low
        assert np.abs((k.H @ h @ h @ k) - (k.H @ h @ k)**2) < 1e-12

        # check exactly one eigenvalue matched well
        assert np.sum(np.abs(el - en) < 1e-12) == 1

        # check exactly one eigenvector is matched with high fidelity
        ovlps = (ev.H @ k).A**2
        big_ovlps = ovlps[ovlps > 1e-12]
        assert_allclose(big_ovlps, [1])

        # check fully
        assert is_eigenvector(k, h)