Ejemplo n.º 1
0
    def test_correlation(self):
        ghz = (MPS_computational_state('0000') +
               MPS_computational_state('1111')) / 2**0.5

        assert ghz.correlation(qu.pauli('Z'), 0, 1) == pytest.approx(1.0)
        assert ghz.correlation(qu.pauli('Z'), 1, 2) == pytest.approx(1.0)
        assert ghz.correlation(qu.pauli('Z'), 3, 1) == pytest.approx(1.0)
        assert ghz.correlation(qu.pauli('Z'), 3, 1,
                               B=qu.pauli('Y')) == pytest.approx(0.0)

        assert ghz.H @ ghz == pytest.approx(1.0)
Ejemplo n.º 2
0
 def test_solve_bigger(self):
     n = 14
     chi = 16
     ham = MPO_ham_mbl(n, dh=8, seed=42)
     p0 = MPS_computational_state('00110111000101')
     dmrgx = DMRGX(ham, p0, chi)
     assert dmrgx.solve(tol=1e-5, sweep_sequence='R')
     assert dmrgx.state[0].dtype == float
Ejemplo n.º 3
0
    def test_auto_split_detection(self):
        psi0 = MPS_computational_state('00')
        CNOT = qu.controlled('not')
        ISWAP = qu.iswap()
        G = qu.rand_uni(4)

        opts = {'contract': 'auto-split-gate', 'where': (0, 1)}

        psi_cnot = psi0.gate(CNOT, **opts)
        psi_iswap = psi0.gate(ISWAP, **opts)
        psi_G = psi0.gate(G, **opts)

        assert (psi_cnot.max_bond() == psi_iswap.max_bond() ==
                psi_G.max_bond() == 2)

        assert len(psi_cnot.tensors) == len(psi_iswap.tensors) == 4
        assert len(psi_G.tensors) == 3
Ejemplo n.º 4
0
 def test_gate_swap_and_split(self):
     n = 10
     p = MPS_computational_state('0' * n)
     assert p.bond_sizes() == [1] * (n - 1)
     G = qu.rand_uni(4)
     p.gate_(G, (1, n - 2), contract='swap+split')
     assert p.bond_sizes() == [1] + [2] * (n - 3) + [1]
Ejemplo n.º 5
0
 def test_magnetization(self):
     binary = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
     p = MPS_computational_state(binary)
     mzs = [p.magnetization(i) for i in range(len(binary))]
     assert_allclose(mzs, 0.5 - np.array(binary))