예제 #1
0
def test_number_nn():
    s = site.SpinHalfSite('Sz')
    chain = lattice.Chain(2, s)
    assert chain.number_nearest_neighbors() == 2
    assert chain.number_next_nearest_neighbors() == 2
    ladd = lattice.Ladder(2, s)
    assert ladd.number_nearest_neighbors(0) == 3
    assert ladd.number_nearest_neighbors(1) == 3
    assert ladd.number_next_nearest_neighbors(0) == 2
    assert ladd.number_next_nearest_neighbors(1) == 2
    square = lattice.Square(2, 2, s)
    assert square.number_nearest_neighbors() == 4
    assert square.number_next_nearest_neighbors() == 4
    triang = lattice.Triangular(2, 2, s)
    assert triang.number_nearest_neighbors() == 6
    assert triang.number_next_nearest_neighbors() == 6
    hc = lattice.Honeycomb(2, 2, s)
    assert hc.number_nearest_neighbors(0) == 3
    assert hc.number_nearest_neighbors(1) == 3
    assert hc.number_next_nearest_neighbors(0) == 6
    assert hc.number_next_nearest_neighbors(1) == 6
    kag = lattice.Kagome(2, 2, s)
    assert kag.number_nearest_neighbors(0) == 4
    assert kag.number_nearest_neighbors(1) == 4
    assert kag.number_nearest_neighbors(2) == 4
    assert kag.number_next_nearest_neighbors(0) == 4
    assert kag.number_next_nearest_neighbors(1) == 4
    assert kag.number_next_nearest_neighbors(2) == 4
예제 #2
0
def test_pairs():
    lattices = [
        lattice.Chain(2, None),
        lattice.Ladder(2, None),
        lattice.Square(2, 2, None),
        lattice.Triangular(2, 2, None),
        lattice.Honeycomb(2, 2, None),
        lattice.Kagome(2, 2, None)
    ]
    for lat in lattices:
        print(lat.__class__.__name__)
        found_dist_pairs = lat.find_coupling_pairs(5, 3.)
        dists = sorted(found_dist_pairs.keys())
        for i, name in enumerate([
                'nearest_neighbors', 'next_nearest_neighbors', 'next_next_nearest_neighbors',
                'fourth_nearest_neighbors', 'fifth_nearest_neighbors'
        ]):
            if name not in lat.pairs:
                assert i > 2  # all of them should define up to next_next_nearest_neighbors
                continue
            print(name)
            defined_pairs = lat.pairs[name]
            found_pairs = found_dist_pairs[dists[i]]
            assert len(defined_pairs) == len(found_pairs)
            defined_pairs = pairs_with_reversed(defined_pairs)
            found_pairs = pairs_with_reversed(found_pairs)
            assert defined_pairs == found_pairs
예제 #3
0
def test_lattice_order():
    s = site.SpinHalfSite('Sz')
    # yapf: disable
    chain = lattice.Chain(4, s)
    order_default = np.array([[0, 0], [1, 0], [2, 0], [3, 0]])
    npt.assert_equal(chain.order, order_default)
    chain = lattice.Chain(4, s, order='folded')
    order_folded = np.array([[0, 0], [3, 0], [1, 0], [2, 0]])
    npt.assert_equal(chain.order, order_folded)
    chain = lattice.Chain(5, s, order='folded')
    order_folded = np.array([[0, 0], [4, 0], [1, 0], [3, 0], [2, 0]])
    ladder = lattice.Ladder(3, s, order='folded')
    order_folded = np.array([[0, 0], [0, 1], [2, 0], [2, 1], [1, 0], [1, 1]])
    npt.assert_equal(ladder.order, order_folded)
    square = lattice.Square(2, 2, s, order='default')
    order_default = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0]])
    npt.assert_equal(square.order, order_default)
    square = lattice.Square(4, 3, s, order='snake')
    order_snake = np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0], [1, 1, 0], [1, 0, 0],
                            [2, 0, 0], [2, 1, 0], [2, 2, 0], [3, 2, 0], [3, 1, 0], [3, 0, 0]])
    npt.assert_equal(square.order, order_snake)
    square = lattice.Square(2, 3, s, order=("standard", (True, False), (1, 0)))
    order_Fsnake = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0]])
    npt.assert_equal(square.order, order_Fsnake)

    hc = lattice.Honeycomb(2, 3, s, order='default')
    order_hc_def = np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0], [0, 0, 1], [0, 1, 1], [0, 2, 1],
                             [1, 0, 0], [1, 1, 0], [1, 2, 0], [1, 0, 1], [1, 1, 1], [1, 2, 1]])
    npt.assert_equal(hc.order, order_hc_def)
    hc = lattice.Honeycomb(2, 3, s, order=('standard', (True, False, False), (0.3, 0.1, -1.)))
    order_hc_mix = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0],
                             [0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 1, 1], [0, 2, 1], [1, 2, 1]])
    npt.assert_equal(hc.order, order_hc_mix)

    kag = lattice.Kagome(2, 3, s, order=('grouped', [[1], [0, 2]]))
    order_kag_gr = np.array([[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 0, 0], [0, 0, 2], [0, 1, 0],
                             [0, 1, 2], [0, 2, 0], [0, 2, 2],
                             [1, 0, 1], [1, 1, 1], [1, 2, 1], [1, 0, 0], [1, 0, 2], [1, 1, 0],
                             [1, 1, 2], [1, 2, 0], [1, 2, 2]])
    npt.assert_equal(kag.order, order_kag_gr)
    kag = lattice.Kagome(2, 4, s, order=('grouped', [[0], [2, 1]], [1, 0, 2]))
    order_kag_gr = np.array([[0, 0, 0], [1, 0, 0], [0, 0, 2], [0, 0, 1], [1, 0, 2], [1, 0, 1],
                             [0, 1, 0], [1, 1, 0], [0, 1, 2], [0, 1, 1], [1, 1, 2], [1, 1, 1],
                             [0, 2, 0], [1, 2, 0], [0, 2, 2], [0, 2, 1], [1, 2, 2], [1, 2, 1],
                             [0, 3, 0], [1, 3, 0], [0, 3, 2], [0, 3, 1], [1, 3, 2], [1, 3, 1]])
    npt.assert_equal(kag.order, order_kag_gr)
예제 #4
0
def test_CouplingModel_fermions():
    for bc, bc_MPS in zip(['open', 'periodic'], ['finite', 'infinite']):
        fermion_lat = lattice.Chain(5, fermion_site, bc=bc, bc_MPS=bc_MPS)
        M = model.CouplingModel(fermion_lat)
        M.add_coupling(1.2, 0, 'Cd', 0, 'C', 1, 'JW')
        M.add_coupling(1.2, 0, 'Cd', 0, 'C', -1, 'JW')
        M.test_sanity()
        M.calc_H_MPO()
        M.calc_H_bond()
예제 #5
0
def test_CouplingModel():
    for bc in ['open', 'periodic']:
        spin_half_lat = lattice.Chain(5, spin_half_site, bc=bc, bc_MPS='finite')
        M = model.CouplingModel(spin_half_lat)
        M.add_coupling(1.2, 0, 'Sz', 0, 'Sz', 1)
        M.test_sanity()
        M.calc_H_MPO()
        if bc == 'periodic':
            with pytest.raises(ValueError, match="nearest neighbor"):
                M.calc_H_bond()  # should raise a ValueError
                # periodic bc but finite bc_MPS leads to a long-range coupling
        else:
            M.calc_H_bond()
예제 #6
0
def test_CouplingModel():
    spin_half_lat = lattice.Chain(5, spin_half_site, bc_MPS='finite')
    for bc in ['open', 'periodic']:
        M = model.CouplingModel(spin_half_lat, bc)
        M.add_coupling(1.2, 0, 'Sz', 0, 'Sz', 1)
        M.test_sanity()
        M.calc_H_MPO()
        if bc == 'periodic':
            with nose.tools.assert_raises(ValueError):
                M.calc_H_bond()  # should raise a ValueError
                # periodic bc but finite bc_MPS leads to a long-range coupling
        else:
            M.calc_H_bond()
예제 #7
0
def test_number_nn():
    s = site.SpinHalfSite('Sz')
    chain = lattice.Chain(2, s)
    assert chain.number_nearest_neighbors() == 2
    assert chain.number_next_nearest_neighbors() == 2
    square = lattice.Square(2, 2, s)
    print(square.number_next_nearest_neighbors())
    assert square.number_nearest_neighbors() == 4
    assert square.number_next_nearest_neighbors() == 4
    hc = lattice.Honeycomb(2, 2, s, s)
    assert hc.number_nearest_neighbors(0) == 3
    assert hc.number_nearest_neighbors(1) == 3
    assert hc.number_next_nearest_neighbors(0) == 6
    assert hc.number_next_nearest_neighbors(1) == 6
예제 #8
0
def test_number_nn():
    s = site.SpinHalfSite('Sz')
    chain = lattice.Chain(2, s)
    assert chain.count_neighbors() == 2
    assert chain.count_neighbors(key='next_nearest_neighbors') == 2
    ladd = lattice.Ladder(2, s)
    for u in [0, 1]:
        assert ladd.count_neighbors(u) == 3
        assert ladd.count_neighbors(u, key='next_nearest_neighbors') == 2
    square = lattice.Square(2, 2, s)
    assert square.count_neighbors() == 4
    assert square.count_neighbors(key='next_nearest_neighbors') == 4
    triang = lattice.Triangular(2, 2, s)
    assert triang.count_neighbors() == 6
    assert triang.count_neighbors(key='next_nearest_neighbors') == 6
    hc = lattice.Honeycomb(2, 2, s)
    for u in [0, 1]:
        assert hc.count_neighbors(u) == 3
        assert hc.count_neighbors(u, key='next_nearest_neighbors') == 6
    kag = lattice.Kagome(2, 2, s)
    for u in [0, 1, 2]:
        assert kag.count_neighbors(u) == 4
        assert kag.count_neighbors(u, key='next_nearest_neighbors') == 4
예제 #9
0
"""A collection of tests for (classes in) :mod:`tenpy.models.model`.

.. todo ::
    A lot more to test, e.g. conversions of the different models
"""
# Copyright 2018 TeNPy Developers

import itertools

from tenpy.models import model, lattice
import tenpy.networks.site
import tenpy.linalg.np_conserved as npc
import test_mpo

spin_half_site = tenpy.networks.site.SpinHalfSite('Sz')
spin_half_lat = lattice.Chain(2, spin_half_site)

fermion_site = tenpy.networks.site.FermionSite('N')
fermion_lat = lattice.Chain(5, fermion_site)


def test_CouplingModel():
    for bc in ['open', 'periodic']:
        M = model.CouplingModel(spin_half_lat, bc)
        M.add_coupling(1.2, 0, 'Sz', 0, 'Sz', 1)
        M.test_sanity()
        M = model.CouplingModel(fermion_lat, bc)
        M.add_coupling(1.2, 0, 'Cd', 0, 'C', 1, 'JW')
        M.test_sanity()