示例#1
0
def test_hubbard_square_lattice_edge_types():
    lattice = HubbardSquareLattice(3, 3)
    assert sorted(lattice.edge_types) == sorted(
        ('onsite', 'neighbor', 'vertical_neighbor', 'horizontal_neighbor'))
    lattice.validate_edge_type('onsite')
    lattice.validate_edge_type('neighbor')
    with pytest.raises(ValueError):
        lattice.validate_edge_type('banana')
    with pytest.raises(ValueError):
        lattice.site_pairs_iter('banana')
def test_hubbard_square_lattice(x_dimension, y_dimension, n_dofs, spinless,
                                periodic):
    lattice = HubbardSquareLattice(x_dimension,
                                   y_dimension,
                                   n_dofs=n_dofs,
                                   spinless=spinless,
                                   periodic=periodic)

    n_spin_values = 2 - spinless
    sites = tuple(
        (x, y)
        for y, x in itertools.product(range(y_dimension), range(x_dimension)))
    site_indices = tuple(lattice.to_site_index(site) for site in sites)
    assert (sites == tuple(
        lattice.from_site_index(site_index) for site_index in site_indices))
    assert (site_indices == tuple(lattice.site_indices) == tuple(
        range(x_dimension * y_dimension)))

    tuple(
        itertools.product(range(x_dimension), range(y_dimension),
                          range(n_dofs), range(n_spin_values)))

    spin_orbital_linear_indices = tuple(
        lattice.to_spin_orbital_index(*indices)
        for indices in itertools.product(site_indices, range(n_dofs),
                                         range(n_spin_values)))
    assert spin_orbital_linear_indices == tuple(range(lattice.n_spin_orbitals))

    for i, ii in zip(range(lattice.n_sites),
                     lattice.site_pairs_iter('onsite')):
        assert ii == (i, i)

    n_neighbor_pairs = 2 * ((x_dimension * (y_dimension - (not periodic))) +
                            ((x_dimension - (not periodic)) * y_dimension))
    neighbor_pairs = tuple(lattice.site_pairs_iter('neighbor'))
    assert (2 * len(tuple(lattice.site_pairs_iter('neighbor', False))) ==
            len(neighbor_pairs) == n_neighbor_pairs)
    for i, j in neighbor_pairs:
        assert sum(lattice.delta_mag(i, j, True)) == 1

    assert len(tuple(
        lattice.dof_pairs_iter(False))) == n_dofs * (n_dofs + 1) / 2
    assert len(tuple(
        lattice.dof_pairs_iter(True))) == n_dofs * (n_dofs - 1) / 2
    spin_pairs_all = tuple(lattice.spin_pairs_iter())
    assert len(spin_pairs_all) == n_spin_values**2
    spin_pairs_same = tuple(lattice.spin_pairs_iter(SpinPairs.SAME))
    assert spin_pairs_same == tuple((s, s) for s in range(n_spin_values))
    spin_pairs_diff = tuple(lattice.spin_pairs_iter(SpinPairs.DIFF))
    assert spin_pairs_diff == () if spinless else ((0, 1), (1, 0))
示例#3
0
def test_hubbard_square_lattice_1xd(d):
    for shape, periodic in itertools.product(((1, d), (d, 1)), (True, False)):
        lattice = HubbardSquareLattice(*shape, periodic=periodic)
        assert lattice.n_sites == d
        assert (len(tuple(lattice.neighbors_iter())) ==
                2 * len(tuple(lattice.neighbors_iter(False))) == 2 *
                (d - (not periodic)))
        assert (len(tuple(lattice.diagonal_neighbors_iter())) == len(
            tuple(lattice.diagonal_neighbors_iter(False))) == 0)
        assert (len(tuple(lattice.site_pairs_iter('diagonal_neighbor'))) == len(
            tuple(lattice.diagonal_neighbors_iter(False))) == 0)