def test_dtypes(self, dtype): H = MPO_ham_heis(8).astype(dtype) dmrg = DMRG2(H) dmrg.opts['local_eig_backend'] = 'scipy' dmrg.solve(max_sweeps=3) res_dtype, = {t.dtype for t in dmrg.state} assert res_dtype == dtype
def test_heisenberg(self, n, l, gap): ham = MPO_ham_heis(n) dmrg = DMRG2(ham) dmrg.solve() gl = gap // 2 gr = gap // 2 + gap % 2 m = n // 2 sysa = range(m - l - gl, m - gl) sysb = range(m + gr, m + l + gr) assert max(sysa) + gap + 1 == min(sysb) ln = dmrg.state.logneg_subsys(sysa, sysb, approx_spectral_opts={'bsz': 16}, verbosity=2) # exact lne = logneg_subsys(groundstate(ham_heis(n, cyclic=False)), [2] * n, sysa, sysb) assert_allclose(lne, ln, rtol=0.1, atol=0.1)
def test_cyclic_solve_big_with_segmenting(self): n = 150 ham = MPO_ham_heis(n, cyclic=True) dmrg = DMRG2(ham, bond_dims=range(10, 30, 2)) dmrg.opts['periodic_segment_size'] = 1 / 3 assert dmrg.solve(tol=1, verbosity=2) assert dmrg.energy == pytest.approx(heisenberg_energy(n), 1e-3)
def test_matches_exact(self, dense, MPO_ham): h = MPO_ham(6) dmrg = DMRG2(h, bond_dims=8) assert dmrg._k.site[0].dtype == float dmrg.opts['eff_eig_dense'] = dense assert dmrg.solve() # XXX: need to dispatch SLEPc seigsys on real input # assert dmrg._k.site[0].dtype == float eff_e, mps_gs = dmrg.energy, dmrg.state mps_gs_dense = mps_gs.to_dense() assert_allclose(mps_gs_dense.H @ mps_gs_dense, 1.0) h_dense = h.to_dense() # check against dense form actual_e, gs = seigsys(h_dense, k=1) assert_allclose(actual_e, eff_e) assert_allclose(abs(expec(mps_gs_dense, gs)), 1.0) # check against actual MPO_ham if MPO_ham is MPO_ham_XY: ham_dense = ham_heis(6, cyclic=False, j=(1.0, 1.0, 0.0)) elif MPO_ham is MPO_ham_heis: ham_dense = ham_heis(6, cyclic=False) actual_e, gs = seigsys(ham_dense, k=1) assert_allclose(actual_e, eff_e) assert_allclose(abs(expec(mps_gs_dense, gs)), 1.0)
def test_realistic(self): seed_rand(42) ham = MPO_ham_heis(20) dmrg = DMRG2(ham, bond_dims=[2, 4]) dmrg.solve() rho_ab = dmrg.state.ptr(range(6, 14)) xf = approx_spectral_function(rho_ab, lambda x: x, tol=0.1, verbosity=2) assert_allclose(1.0, xf, rtol=0.6, atol=0.001)
def test_realistic(self): ham = MPO_ham_heis(20) dmrg = DMRG2(ham, bond_dims=[4, 8]) dmrg.solve() sysa, sysb = range(3, 9), range(12, 17) rho_ab_pt = PTPTLazyMPS(dmrg.state, sysa, sysb) xf = approx_spectral_function(rho_ab_pt, lambda x: x, beta_tol=1e-6, tol=0.05, verbosity=2, max_bond=20) assert_allclose(1, xf, rtol=0.5, atol=0.1)
def test_total_size_2(self): N = 2 builder = SpinHam(1 / 2) for i in range(N - 1): builder[i, i + 1] += 1.0, 'Z', 'Z' H = builder.build_mpo(N) dmrg = DMRG2(H) dmrg.solve(verbosity=1) assert dmrg.energy == pytest.approx(-1 / 4)
def test_realistic_ent(self): n = 12 sysa, sysb = range(3, 6), range(6, 8) ham = MPO_ham_heis(n) dmrg = DMRG2(ham, bond_dims=[2, 4]) dmrg.solve() rho_ab_pt = PTPTLazyMPS(dmrg.state, sysa, sysb) psi0 = dmrg.state.to_dense() lne = logneg_subsys(psi0, [2] * n, sysa=sysa, sysb=sysb) lnx = log2( approx_spectral_function(rho_ab_pt, abs, tol=0.1, verbosity=2)) assert_allclose(lne, lnx, rtol=0.5, atol=0.1)
def test_realistic_ent(self): n = 12 sysa, sysb = range(3, 6), range(6, 8) sysab = (*sysa, *sysb) ham = MPO_ham_heis(n) dmrg = DMRG2(ham, bond_dims=[10]) dmrg.solve() psi0 = dmrg.state.to_dense() lne = logneg_subsys(psi0, [2] * n, sysa=sysa, sysb=sysb) rho_ab = dmrg.state.ptr(sysab, rescale_sites=True) rho_ab_pt = rho_ab.partial_transpose(range(3)) lnx = log2( approx_spectral_function(rho_ab_pt, abs, tol=0.1, verbosity=2)) assert_allclose(lne, lnx, rtol=0.6, atol=0.1)
def test_matches_exact(self, dense, MPO_ham, cyclic): n = 6 h = MPO_ham(n, cyclic=cyclic) tol = 3e-2 if cyclic else 1e-4 dmrg = DMRG2(h, bond_dims=[4, 8, 12]) assert dmrg._k[0].dtype == float dmrg.opts['local_eig_ham_dense'] = dense dmrg.opts['periodic_segment_size'] = 1.0 dmrg.opts['periodic_nullspace_fudge_factor'] = 1e-6 assert dmrg.solve(tol=tol / 10, verbosity=1) # XXX: need to dispatch SLEPc eigh on real input # assert dmrg._k[0].dtype == float eff_e, mps_gs = dmrg.energy, dmrg.state mps_gs_dense = mps_gs.to_dense() assert_allclose(expec(mps_gs_dense, mps_gs_dense), 1.0, rtol=tol) h_dense = h.to_dense() # check against dense form actual_e, gs = eigh(h_dense, k=1) assert_allclose(actual_e, eff_e, rtol=tol) assert_allclose(abs(expec(mps_gs_dense, gs)), 1.0, rtol=tol) # check against actual MPO_ham if MPO_ham is MPO_ham_XY: ham_dense = ham_heis(n, cyclic=cyclic, j=(1.0, 1.0, 0.0)) elif MPO_ham is MPO_ham_heis: ham_dense = ham_heis(n, cyclic=cyclic) actual_e, gs = eigh(ham_dense, k=1) assert_allclose(actual_e, eff_e, rtol=tol) assert_allclose(abs(expec(mps_gs_dense, gs)), 1.0, rtol=tol)