def test_bsz2_start_left(self): tn = MPS_rand_state(6, bond_dim=7) env = MovingEnvironment(tn, begin='left', bsz=2) assert len(env().tensors) == 4 env.move_right() assert len(env().tensors) == 4 env.move_right() assert len(env().tensors) == 4 with pytest.raises(ValueError): env.move_to(5) env.move_to(4) assert env.pos == 4 assert len(env().tensors) == 4
def test_bsz1_start_right(self): tn = MPS_rand_state(6, bond_dim=7) env = MovingEnvironment(tn, begin='right', bsz=1) assert env.pos == 5 assert len(env().tensors) == 3 env.move_left() assert env.pos == 4 assert len(env().tensors) == 3 env.move_left() assert env.pos == 3 assert len(env().tensors) == 3 env.move_to(0) assert env.pos == 0 assert len(env().tensors) == 3
def test_bsz1_start_left(self): tn = MPS_rand_state(6, bond_dim=7) env = MovingEnvironment(tn, n=6, start='left', bsz=1) assert env.pos == 0 assert len(env().tensors) == 2 env.move_right() assert env.pos == 1 assert len(env().tensors) == 3 env.move_right() assert env.pos == 2 assert len(env().tensors) == 3 env.move_to(5) assert env.pos == 5 assert len(env().tensors) == 2
def test_bsz2_start_right(self): tn = MPS_rand_state(6, bond_dim=7) env = MovingEnvironment(tn, n=6, start='right', bsz=2) assert env.pos == 4 assert len(env().tensors) == 3 env.move_left() assert env.pos == 3 assert len(env().tensors) == 4 env.move_left() assert env.pos == 2 assert len(env().tensors) == 4 with pytest.raises(ValueError): env.move_to(-1) env.move_to(0) assert env.pos == 0 assert len(env().tensors) == 3
def test_cyclic_moving_env_init_right(self, n, bsz, ssz): p = MPS_rand_state(n, 4, cyclic=True) norm = p.H | p mes = MovingEnvironment(norm, begin='right', bsz=bsz, cyclic=True, ssz=ssz) assert len(mes.envs) == n // 2 + n % 2 assert mes.pos == n - 1 assert len(mes.envs[n - 1].tensors) == 2 * bsz + 2 assert len(mes.envs[n - n // 2].tensors) == 2 * bsz + 1 assert 0 not in mes.envs assert n // 2 - 1 not in mes.envs for i in reversed(range(-n, n - 1)): mes.move_left() assert mes.pos == i % n cur_env = mes() assert len(cur_env.tensors) == 2 * bsz + 2 assert (cur_env ^ all) == pytest.approx(1.0)
def test_cyclic_moving_env_init_left(self, n, bsz, ssz): nenv = 2 p = MPS_rand_state(n, 4, cyclic=True) norm = p.H & p mes = MovingEnvironment(norm, begin='left', bsz=bsz, cyclic=True, ssz=ssz) assert len(mes.envs) == n // 2 + n % 2 assert mes.pos == 0 assert len(mes.envs[0].tensors) == 2 * bsz + nenv assert len(mes.envs[n // 2 - 1].tensors) == 2 * bsz + 1 assert n // 2 + n % 2 not in mes.envs assert n - 1 not in mes.envs for i in range(1, 2 * n): mes.move_right() assert mes.pos == i % n cur_env = mes() assert len(cur_env.tensors) == 2 * bsz + nenv assert (cur_env ^ all) == pytest.approx(1.0)