def test_canonize_cyclic(self, dtype, block): k = MPS_rand_state(40, 10, dtype=dtype, cyclic=True) b = k.H k.add_tag('KET') b.add_tag('BRA') kb = (b | k) assert not np.allclose(k[block].H @ k[block], 1.0) assert not np.allclose(b[block].H @ b[block], 1.0) k.canonize_cyclic(block, bra=b) assert_allclose(k[block].H @ k[block], 1.0, rtol=2e-4) assert_allclose(b[block].H @ b[block], 1.0, rtol=2e-4) ii = kb.select(block, which='!any') ^ all if isinstance(block, slice): start, stop = block.start, block.stop else: start, stop = block, block + 1 assert len(kb.select_tensors(block, 'any')) == 2 * (stop - start) ul, = bonds(kb[k.site_tag(start - 1), 'BRA'], kb[k.site_tag(start), 'BRA']) ur, = bonds(kb[k.site_tag(stop - 1), 'BRA'], kb[k.site_tag(stop), 'BRA']) ll, = bonds(kb[k.site_tag(start - 1), 'KET'], kb[k.site_tag(start), 'KET']) lr, = bonds(kb[k.site_tag(stop - 1), 'KET'], kb[k.site_tag(stop), 'KET']) ii = ii.to_dense((ul, ur), (ll, lr)) assert_allclose(ii, np.eye(ii.shape[0]), rtol=0.001, atol=0.001)
def test_gate_no_contract(self, bsz, propagate_tags, contract): p = MPS_rand_state(5, 7) q = p.copy() G = qu.rand_uni(2**bsz) p = p.gate(G, where=[i for i in range(2, 2 + bsz)], tags='G', contract=contract) TG = p['G'] if propagate_tags or contract: assert p.site_tag(2) in TG.tags assert p.H @ p == pytest.approx(1.0) assert abs(q.H @ p) < 1.0 assert len(p.tensors) == 6 - int(contract) * bsz assert set(p.outer_inds()) == {'k{}'.format(i) for i in range(5)}
def test_gate_no_contract(self, bsz, propagate_tags, contract): p = MPS_rand_state(5, 7, tags={'PSI0'}) q = p.copy() G = qu.rand_uni(2**bsz) p = p.gate_(G, where=[i for i in range(2, 2 + bsz)], tags='G', contract=contract, propagate_tags=propagate_tags) TG = p['G'] if propagate_tags or contract: assert p.site_tag(2) in TG.tags assert ('PSI0' in TG.tags) == (propagate_tags is True) or contract assert (p.H & p) ^ all == pytest.approx(1.0) assert abs((q.H & p) ^ all) < 1.0 assert len(p.tensors) == 6 - int(contract) * bsz assert set(p.outer_inds()) == {f'k{i}' for i in range(5)}