コード例 #1
0
def test_random_mps_invalid_dimensions_raises_error(backend_dtype_values):
    with pytest.raises(ValueError):
        FiniteMPS.random(d=[3, 4],
                         D=[2, 3],
                         dtype=backend_dtype_values[1],
                         backend=backend_dtype_values[0])
    with pytest.raises(ValueError):
        FiniteMPS.random(d=[3, 4, 4, 2],
                         D=[2, 3],
                         dtype=backend_dtype_values[1],
                         backend=backend_dtype_values[0])
コード例 #2
0
def test_random_mps(backend_dtype_values):
    mps = FiniteMPS.random(d=[3, 4, 5],
                           D=[2, 3],
                           dtype=backend_dtype_values[1],
                           backend=backend_dtype_values[0])
    assert len(mps) == 3
    assert mps.physical_dimensions == [3, 4, 5]
    assert mps.bond_dimensions == [1, 2, 3, 1]
コード例 #3
0
ファイル: localham_test.py プロジェクト: ZENG-Hui/tn-dmrg
def test_identity_mpo():
    N = 10
    psi = FiniteMPS.random([2 for i in range(10)], [4 for i in range(9)],
                           dtype=np.float64)
    Id = identity_mpo(N)
    lh = LocalHam(Id, psi, "numpy")
    # test shifting right
    for b in range(len(psi) - 1):
        lh.position(b)
        assert np.isclose(lh.energy(), 1, atol=1e-10)

    # test shifting back left
    for b in range(len(psi) - 2, -1, -1):
        lh.position(b)
        assert np.isclose(lh.energy(), 1, atol=1e-10)
コード例 #4
0
def test_finiteFreeFermions2d(N1, N2, D):
    def adjacency(N1, N2):
        neighbors = {}
        mat = np.arange(N1 * N2).reshape(N1, N2)
        for n in range(N1 * N2):
            x, y = np.divmod(n, N2)
            if n not in neighbors:
                neighbors[n] = []
            if y < N2 - 1:
                neighbors[n].append(mat[x, y + 1])
            if x > 0:
                neighbors[n].append(mat[x - 1, y])
        return neighbors

    adj = adjacency(N1, N2)
    tij = np.zeros((N1 * N2, N1 * N2))
    t = -1
    v = -1
    for n, d in adj.items():
        for ind in d:
            tij[n, ind] += t
            tij[ind, n] += t
    tij += np.diag(np.ones(N1 * N2) * v)

    eta, _ = np.linalg.eigh(tij)
    expected = min(np.cumsum(eta))

    t1 = t
    t2 = t
    dtype = np.float64
    mpo = FiniteFreeFermion2D(t1, t2, v, N1, N2, dtype)
    mps = FiniteMPS.random([2] * N1 * N2, [D] * (N1 * N2 - 1),
                           dtype=np.float64)
    dmrg = FiniteDMRG(mps, mpo)
    actual = dmrg.run_one_site()
    np.testing.assert_allclose(actual, expected)