Example #1
0
def test_hubbard_square_lattice_dof_validation(n_dofs):
    lattice = HubbardSquareLattice(3, 3, n_dofs=n_dofs)
    for a in range(n_dofs):
        lattice.validate_dof(a)
    for ab in itertools.combinations(range(n_dofs), 2):
        lattice.validate_dofs(ab, 2)
    for abc in itertools.combinations(range(n_dofs), 3):
        lattice.validate_dofs(abc, 3)
    with pytest.raises(ValueError):
        lattice.validate_dof(-1)
    with pytest.raises(ValueError):
        lattice.validate_dof(n_dofs)
    with pytest.raises(ValueError):
        lattice.validate_dofs((0, 0), 1)
Example #2
0
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))
Example #3
0
def test_hubbard_square_lattice_edge_types():
    lattice = HubbardSquareLattice(3, 3)
    assert sorted(lattice.edge_types) == sorted(
        ('onsite', 'neighbor', 'diagonal_neighbor', 'vertical_neighbor',
         'horizontal_neighbor'))
    lattice.validate_edge_type('onsite')
    lattice.validate_edge_type('neighbor')
    lattice.validate_edge_type('diagonal_neighbor')
    lattice.validate_edge_type('vertical_neighbor')
    lattice.validate_edge_type('horizontal_neighbor')
    with pytest.raises(ValueError):
        lattice.validate_edge_type('banana')
    with pytest.raises(ValueError):
        lattice.site_pairs_iter('banana')
def test_fermi_hubbard_bad_parameters():
    lattice = HubbardSquareLattice(3, 3)
    with pytest.raises(ValueError):
        tunneling_parameters = [('onsite', (0, 0), 1)]
        FermiHubbardModel(lattice, tunneling_parameters=tunneling_parameters)

    with pytest.raises(ValueError):
        FermiHubbardModel(lattice, interaction_parameters=[(0, 0)])
    with pytest.raises(ValueError):
        FermiHubbardModel(lattice, interaction_parameters=[(0, ) * 5])
    with pytest.raises(ValueError):
        interaction_parameters = [('onsite', (0, 0), 1, SpinPairs.SAME)]
        FermiHubbardModel(lattice,
                          interaction_parameters=interaction_parameters)
Example #5
0
def fermi_hubbard_from_general(x_dimension,
                               y_dimension,
                               tunneling,
                               coulomb,
                               chemical_potential=0.,
                               periodic=True,
                               spinless=False,
                               magnetic_field=0):
    lattice = HubbardSquareLattice(x_dimension,
                                   y_dimension,
                                   periodic=periodic,
                                   spinless=spinless)
    interaction_edge_type = 'neighbor' if spinless else 'onsite'
    model = FermiHubbardModel(lattice,
                              tunneling_parameters=(('neighbor', (0, 0),
                                                     tunneling), ),
                              interaction_parameters=((interaction_edge_type,
                                                       (0, 0), coulomb), ),
                              potential_parameters=((0, chemical_potential), ),
                              magnetic_field=magnetic_field)
    return model.hamiltonian()
Example #6
0
        tunneling_parameters = [('onsite', (0, 0), 1)]
        FermiHubbardModel(lattice, tunneling_parameters=tunneling_parameters)

    with pytest.raises(ValueError):
        FermiHubbardModel(lattice, interaction_parameters=[(0, 0)])
    with pytest.raises(ValueError):
        FermiHubbardModel(lattice, interaction_parameters=[(0, ) * 5])
    with pytest.raises(ValueError):
        interaction_parameters = [('onsite', (0, 0), 1, SpinPairs.SAME)]
        FermiHubbardModel(lattice,
                          interaction_parameters=interaction_parameters)


lattices = [
    HubbardSquareLattice(random.randrange(3, 10),
                         random.randrange(3, 10),
                         periodic=periodic,
                         spinless=spinless) for periodic in (False, True)
    for spinless in (False, True) for _ in range(2)
]


@pytest.mark.parametrize(
    'lattice,parameters,distinguish_edges',
    [(lattice, random_parameters(
        lattice, distinguish_edges=distinguish_edges), distinguish_edges)
     for lattice in lattices for _ in range(2)
     for distinguish_edges in (True, False)])
def test_fermi_hubbard_square_lattice_random_parameters(
        lattice, parameters, distinguish_edges):
    model = FermiHubbardModel(lattice, **parameters)
    hamiltonian = model.hamiltonian()
Example #7
0
def test_fermi_hubbard_bad_parameters():
    lattice = HubbardSquareLattice(3, 3)
    with pytest.raises(ValueError):
        tunneling_parameters = [('onsite', (0, 0), 1)]
        FermiHubbardModel(lattice, tunneling_parameters=tunneling_parameters)

    with pytest.raises(ValueError):
        FermiHubbardModel(lattice, interaction_parameters=[(0, 0)])
    with pytest.raises(ValueError):
        FermiHubbardModel(lattice, interaction_parameters=[(0,) * 5])
    with pytest.raises(ValueError):
        interaction_parameters = [('onsite', (0, 0), 1, SpinPairs.SAME)]
        FermiHubbardModel(lattice, interaction_parameters=interaction_parameters)


lattices = [HubbardSquareLattice(random.randrange(3, 10), random.randrange(3, 10),
                                 periodic=periodic, spinless=spinless)
    for periodic in (False, True)
    for spinless in (False, True)
    for _ in range(2)
    ]
@pytest.mark.parametrize('lattice,parameters,distinguish_edges', [
    (lattice, random_parameters(lattice, distinguish_edges=distinguish_edges),
     distinguish_edges)
    for lattice in lattices
    for _ in range(2)
    for distinguish_edges in (True, False)
    ])
def test_fermi_hubbard_square_lattice_random_parameters(
        lattice, parameters, distinguish_edges):
    model = FermiHubbardModel(lattice, **parameters)
    hamiltonian = model.hamiltonian()
def test_hubbard_square_lattice_defaults():
    lattice = HubbardSquareLattice(3, 3)
    assert lattice.n_dofs == 1
    assert lattice.spinless == False
    assert lattice.periodic == True
def test_spin():
    lattice = HubbardSquareLattice(3, 3)
    assert tuple(lattice.spin_indices) == (Spin.UP, Spin.DOWN)
Example #10
0
def test_hubbard_square_lattice_repr(kwargs):
    lattice = HubbardSquareLattice(**kwargs)
    params = ('x_dimension', 'y_dimension', 'n_dofs', 'spinless', 'periodic')
    param_template = ', '.join('{0}={{{0}}}'.format(param) for param in params)
    param_str = param_template.format(**kwargs)
    assert repr(lattice) == 'HubbardSquareLattice({})'.format(param_str)
Example #11
0
def test_hubbard_square_lattice_2x2():
    for periodic in (True, False):
        lattice = HubbardSquareLattice(2, 2, periodic=periodic)
        assert lattice.n_sites == 4
        assert len(tuple(lattice.neighbors_iter(False))) == 4
        assert len(tuple(lattice.neighbors_iter())) == 8