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)
def rand_tn1d_sect(n, bd, dtype=complex): mps = qtn.MPS_rand_state(n + 2, bd, dtype=dtype) mpo = qtn.MPO_rand_herm(n + 2, 5, dtype=dtype) norm = qtn.TensorNetwork(qtn.align_TN_1D(mps.H, mpo, mps)) lix = qtn.bonds(norm[0], norm[1]) rix = qtn.bonds(norm[n], norm[n + 1]) to = norm[1:n + 1] return qtn.TNLinearOperator1D(to, lix, rix, 1, n + 1)
def rand_tn1d_sect(n, bd, dtype=complex): mps = qtn.MPS_rand_state(n + 2, bd, dtype=dtype) mpo = qtn.MPO_rand_herm(n + 2, 5, dtype=dtype) norm = qtn.TensorNetwork(qtn.align_TN_1D(mps.H, mpo, mps)) # greedy not good and contracting with large bsz norm.structure_bsz = 2 lix = qtn.bonds(norm[0], norm[1]) rix = qtn.bonds(norm[n], norm[n + 1]) to = norm[1:n + 1] return qtn.TNLinearOperator1D(to, lix, rix, 1, n + 1)