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)
Beispiel #2
0
    def test_explicit_sweeps(self):
        n = 8
        chi = 16
        ham = MPO_ham_mbl(n, dh=4, seed=42)
        p0 = MPS_rand_state(n, 2).expand_bond_dimension(chi)

        b0 = p0.H
        p0.align_(ham, b0)
        en0 = (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 = eigh(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, tol=1e-10)
Beispiel #3
0
 def test_sparse(self):
     a = qu.rand_herm(10, sparse=True, density=0.9)
     vt = qu.eigvecsh(a, sigma=0, k=1)
     assert qu.is_eigenvector(vt, a)
     vf = qu.rand_ket(10)
     assert not qu.is_eigenvector(vf, a)
Beispiel #4
0
 def test_dense_false(self):
     a = qu.rand_herm(10)
     v = qu.rand_ket(10)
     assert not qu.is_eigenvector(v, a)
Beispiel #5
0
 def test_dense_true(self):
     a = qu.rand_herm(10)
     v = qu.eigvecsh(a)
     for i in range(10):
         assert qu.is_eigenvector(v[:, [i]], a)
Beispiel #6
0
 def test_sparse(self):
     a = rand_herm(10, sparse=True, density=0.9)
     vt = seigvecs(a, sigma=0, k=1)
     assert is_eigenvector(vt, a)
     vf = rand_ket(10)
     assert not is_eigenvector(vf, a)
Beispiel #7
0
 def test_dense_true(self):
     a = rand_herm(10)
     v = eigvecs(a)
     for i in range(10):
         assert is_eigenvector(v[:, i], a)