示例#1
0
def test_dmrg_shared_exec_iterative_solve_one_sweep():
    max_mps_rank = 5
    num = 7
    mpo_rank = 5
    size = 5
    num_iter = 10
    T.set_backend("numpy")

    h = qtn.MPO_rand_herm(num, mpo_rank, size)
    dmrg_quimb = qtn.DMRG2(h, bond_dims=[max_mps_rank])

    h_tensors = load_quimb_tensors(h)
    mps_tensors = load_quimb_tensors(dmrg_quimb.state)

    # dmrg based on ad
    mps_tensors, energy = dmrg_shared_exec_iterative_solve(
        h_tensors, mps_tensors, num_iter=num_iter, max_mps_rank=max_mps_rank)

    # dmrg based on quimb
    opts = {'max_bond': max_mps_rank}
    for _ in range(num_iter):
        quimb_energy = dmrg_quimb.sweep_right(canonize=True,
                                              verbosity=0,
                                              **opts)

    # We only test on energy (lowest eigenvalue of h), rather than the output
    # mps (eigenvector), because the eigenvectors can vary a lot while keeping the
    # eigenvalue unchanged.
    assert (abs(energy - quimb_energy) < 1e-5)
示例#2
0
    def test_no_default_term(self):
        N = 10
        builder = qtn.SpinHam(1 / 2)

        for i in range(N - 1):
            builder[i, i + 1] += 1.0, 'Z', 'Z'

        H = builder.build_mpo(N)

        dmrg = qtn.DMRG2(H)
        dmrg.solve(verbosity=1)

        assert dmrg.energy == pytest.approx(-2.25)
示例#3
0
def test_dmrg_one_sweep():
    max_mps_rank = 5
    num = 4
    T.set_backend("numpy")

    h = qtn.MPO_ham_heis(num)
    dmrg_quimb = qtn.DMRG2(h, bond_dims=[max_mps_rank])

    h_tensors = load_quimb_tensors(h)
    mps_tensors = load_quimb_tensors(dmrg_quimb.state)

    # dmrg based on ad
    mps_tensors, energy = dmrg(h_tensors,
                               mps_tensors,
                               max_mps_rank=max_mps_rank)

    # dmrg based on quimb
    opts = {'max_bond': max_mps_rank}
    quimb_energy = dmrg_quimb.sweep_right(canonize=True, verbosity=0, **opts)

    # We only test on energy (lowest eigenvalue of h), rather than the output
    # mps (eigenvector), because the eigenvectors can vary a lot while keeping the
    # eigenvalue unchanged.
    assert (abs(energy - quimb_energy) < 1e-8)