def test_svd_compress(comp, mp): if mp == "mpo": mps = Mpo(holstein_model) M = 22 else: mps = Mps.random(holstein_model, 1, 10) if mp == "mpdm": mps = MpDm.from_mps(mps) mps.canonicalise().normalize() M = 36 if comp: mps = mps.to_complex(inplace=True) print(f"{mps}") mpo = Mpo(holstein_model) if comp: mpo = mpo.scale(-1.0j) print(f"{mpo.bond_dims}") std_mps = mpo.apply(mps, canonicalise=True).canonicalise() print(f"std_mps: {std_mps}") mps.compress_config.bond_dim_max_value = M mps.compress_config.criteria = CompressCriteria.fixed svd_mps = mpo.contract(mps) dis = svd_mps.distance(std_mps) / std_mps.dmrg_norm print(f"svd_mps: {svd_mps}, dis: {dis}") assert np.allclose(dis, 0.0, atol=1e-3) assert np.allclose(svd_mps.dmrg_norm, std_mps.dmrg_norm, atol=1e-4)
def test_variational_compress(comp, mp): if mp == "mpo": mps = Mpo(holstein_model) M = 20 else: mps = Mps.random(holstein_model, 1, 10) if mp == "mpdm": mps = MpDm.from_mps(mps) mps.canonicalise().normalize() M = 36 if comp: mps = mps.to_complex(inplace=True) print(f"{mps}") mpo = Mpo(holstein_model) if comp: mpo = mpo.scale(-1.0j) print(f"{mpo.bond_dims}") std_mps = mpo.apply(mps, canonicalise=True).canonicalise() print(f"std_mps: {std_mps}") # 2site algorithm mps.compress_config.vprocedure = [[M, 1.0], [M, 0.2], [M, 0.1]] + [ [M, 0], ] * 10 mps.compress_config.vmethod = "2site" var_mps = mps.variational_compress(mpo, guess=None) dis = var_mps.distance(std_mps) / std_mps.dmrg_norm print(f"var2_mps: {var_mps}, dis: {dis}") assert np.allclose(dis, 0.0, atol=1e-4) assert np.allclose(var_mps.dmrg_norm, std_mps.dmrg_norm, atol=1e-4) # 1site algorithm with 2site result as a guess # 1site algorithm is easy to be trapped in a local minimum var_mps.compress_config.vprocedure = [ [M, 0], ] * 10 var_mps.compress_config.vmethod = "1site" var_mps = mps.variational_compress(mpo, guess=var_mps) dis = var_mps.distance(std_mps) / std_mps.dmrg_norm print(f"var1_mps: {var_mps}, dis: {dis}") assert np.allclose(dis, 0.0, atol=1e-4) assert np.allclose(var_mps.dmrg_norm, std_mps.dmrg_norm, atol=1e-4)