def test_trans_invar(self): with pytest.raises(ValueError): psi = MPS_rand_state(10, 7, cyclic=False, trans_invar=True) psi = MPS_rand_state(10, 7, cyclic=True, trans_invar=True) z0 = psi.expec(psi.gate(qu.pauli('Z'), 0, contract=True)) z3 = psi.expec(psi.gate(qu.pauli('Z'), 0, contract=True)) z7 = psi.expec(psi.gate(qu.pauli('Z'), 0, contract=True)) assert_allclose(z0, z3) assert_allclose(z3, z7)
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_swap_gating(self): psi0 = MPS_rand_state(20, 5) CNOT = qu.controlled('not') psi0XX = psi0.gate(CNOT, (4, 13)) psi0XX_s = psi0.gate_with_auto_swap(CNOT, (4, 13)) assert psi0XX.H @ psi0XX_s == pytest.approx(1.0)