示例#1
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()
示例#2
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)
示例#3
0
def test_fermi_hubbard_default_parameters():
    lattice = HubbardSquareLattice(3, 3)
    model = FermiHubbardModel(lattice)
    assert model.tunneling_parameters == []
    assert model.interaction_parameters == []
    assert model.potential_parameters == []
    assert model.magnetic_field == 0
示例#4
0
def test_fermi_hubbard_square_lattice_random_parameters(
        lattice, parameters, distinguish_edges):
    model = FermiHubbardModel(lattice, **parameters)
    hamiltonian = model.hamiltonian()
    terms_per_parameter = defaultdict(int)
    for term, coefficient in hamiltonian.terms.items():
        spin_orbitals = set(i for i, _ in term)
        if len(spin_orbitals) == 2:
            (i, a, s), (ii, aa, ss) = (lattice.from_spin_orbital_index(i)
                                       for i in spin_orbitals)
            edge_type = ({
                (0, 0): 'onsite',
                (0, 1): 'vertical_neighbor',
                (1, 0): 'horizontal_neighbor'
            } if distinguish_edges else {
                (0, 0): 'onsite',
                (0, 1): 'neighbor',
                (1, 0): 'neighbor'
            })[lattice.delta_mag(i, ii, True)]
            dofs = tuple(sorted((a, aa)))
            if len(term) == 2:
                parameter = (edge_type, dofs, -coefficient)
                assert parameter in parameters['tunneling_parameters']
                terms_per_parameter['tunneling', parameter] += 1
            else:
                assert len(term) == 4
                spin_pairs = (SpinPairs.ALL if lattice.spinless else
                              (SpinPairs.SAME if s == ss else SpinPairs.DIFF))
                parameter = (edge_type, dofs, coefficient, spin_pairs)
                assert parameter in parameters['interaction_parameters']
                terms_per_parameter['interaction', parameter] += 1
        else:
            assert len(term) == 2
            assert len(spin_orbitals) == 1
            spin_orbital = spin_orbitals.pop()
            _, dof, spin_index = lattice.from_spin_orbital_index(spin_orbital)
            potential_coefficient = -coefficient
            if not lattice.spinless:
                (-1)**spin_index
                potential_coefficient -= (((-1)**spin_index) *
                                          parameters.get('magnetic_field', 0))
            if not potential_coefficient:
                continue
            parameter = (dof, potential_coefficient)
            assert parameter in parameters['potential_parameters']
            terms_per_parameter['potential', parameter] += 1
    edge_type_to_n_site_pairs = {
        'onsite': lattice.n_sites,
        'neighbor': lattice.n_neighbor_pairs(False),
        'vertical_neighbor': lattice.n_vertical_neighbor_pairs(False),
        'horizontal_neighbor': lattice.n_horizontal_neighbor_pairs(False)
    }
    for (term_type, parameter), n_terms in terms_per_parameter.items():
        if term_type == 'potential':
            assert n_terms == lattice.n_sites * lattice.n_spin_values
            continue
        n_site_pairs = edge_type_to_n_site_pairs[parameter[0]]
        if term_type == 'tunneling':
            assert n_terms == 2 * n_site_pairs * lattice.n_spin_values
        else:
            assert term_type == 'interaction'
            parameter = InteractionParameter(*parameter)
            expected_n_terms = n_site_pairs
            if parameter.edge_type == 'neighbor':
                expected_n_terms *= len(set(parameter.dofs))
            if not lattice.spinless:
                assert parameter.spin_pairs != SpinPairs.ALL
                if (parameter.edge_type == 'onsite'
                        and parameter.spin_pairs == SpinPairs.DIFF):
                    expected_n_terms *= len(set(parameter.dofs))
                else:
                    expected_n_terms *= 2
            assert n_terms == expected_n_terms