How to use the openfermion.ops.up_index function in openfermion

To help you get started, we’ve selected a few openfermion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github quantumlib / OpenFermion / src / openfermion / hamiltonians / _hubbard.py View on Github external
# Avoid double-counting edges when one of the dimensions is 2
        # and the system is periodic
        if x_dimension == 2 and periodic and site % 2 == 1:
            right_neighbor = None
        if y_dimension == 2 and periodic and site >= x_dimension:
            bottom_neighbor = None

        # Add hopping terms with neighbors to the right and bottom.
        if right_neighbor is not None:
            hubbard_model += _hopping_term(
                    up_index(site), up_index(right_neighbor), -tunneling)
            hubbard_model += _hopping_term(
                    down_index(site), down_index(right_neighbor), -tunneling)
        if bottom_neighbor is not None:
            hubbard_model += _hopping_term(
                    up_index(site), up_index(bottom_neighbor), -tunneling)
            hubbard_model += _hopping_term(
                    down_index(site), down_index(bottom_neighbor), -tunneling)

        # Add local pair Coulomb interaction terms.
        hubbard_model += _coulomb_interaction_term(
                n_spin_orbitals, up_index(site), down_index(site), coulomb,
                particle_hole_symmetry)

        # Add chemical potential and magnetic field terms.
        hubbard_model += number_operator(
                n_spin_orbitals, up_index(site),
                -chemical_potential - magnetic_field)
        hubbard_model += number_operator(
                n_spin_orbitals, down_index(site),
                -chemical_potential + magnetic_field)
github quantumlib / OpenFermion / src / openfermion / utils / _unitary_cc.py View on Github external
doubles_1.append(double_amplitudes[virtual_up, occupied_up,
                                           virtual_down, occupied_down])

    # Get doubles amplitudes associated with two spatial occupied-virtual pairs
    for (p, q), (r, s) in itertools.combinations(
            itertools.product(range(n_virtual), range(n_occupied)), 2):
        # Get indices of spatial orbitals
        virtual_spatial_1 = n_occupied + p
        occupied_spatial_1 = q
        virtual_spatial_2 = n_occupied + r
        occupied_spatial_2 = s

        # Get indices of spin orbitals
        # Just get up amplitudes, since down and cross terms should be the same
        virtual_1_up = up_index(virtual_spatial_1)
        occupied_1_up = up_index(occupied_spatial_1)
        virtual_2_up = up_index(virtual_spatial_2)
        occupied_2_up = up_index(occupied_spatial_2)

        # Get amplitude
        doubles_2.append(double_amplitudes[virtual_1_up, occupied_1_up,
                                           virtual_2_up, occupied_2_up])

    return singles + doubles_1 + doubles_2
github quantumlib / OpenFermion / src / openfermion / utils / _unitary_cc.py View on Github external
virtual_down, occupied_down])

    # Get doubles amplitudes associated with two spatial occupied-virtual pairs
    for (p, q), (r, s) in itertools.combinations(
            itertools.product(range(n_virtual), range(n_occupied)), 2):
        # Get indices of spatial orbitals
        virtual_spatial_1 = n_occupied + p
        occupied_spatial_1 = q
        virtual_spatial_2 = n_occupied + r
        occupied_spatial_2 = s

        # Get indices of spin orbitals
        # Just get up amplitudes, since down and cross terms should be the same
        virtual_1_up = up_index(virtual_spatial_1)
        occupied_1_up = up_index(occupied_spatial_1)
        virtual_2_up = up_index(virtual_spatial_2)
        occupied_2_up = up_index(occupied_spatial_2)

        # Get amplitude
        doubles_2.append(double_amplitudes[virtual_1_up, occupied_1_up,
                                           virtual_2_up, occupied_2_up])

    return singles + doubles_1 + doubles_2
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _hubbard.py View on Github external
right_neighbor = _right_neighbor(
                site, x_dimension, y_dimension, periodic)
        bottom_neighbor = _bottom_neighbor(
                site, x_dimension, y_dimension, periodic)

        # Avoid double-counting edges when one of the dimensions is 2
        # and the system is periodic
        if x_dimension == 2 and periodic and site % 2 == 1:
            right_neighbor = None
        if y_dimension == 2 and periodic and site >= x_dimension:
            bottom_neighbor = None

        # Add hopping terms with neighbors to the right and bottom.
        if right_neighbor is not None:
            hubbard_model += _hopping_term(
                    up_index(site), up_index(right_neighbor), -tunneling)
            hubbard_model += _hopping_term(
                    down_index(site), down_index(right_neighbor), -tunneling)
        if bottom_neighbor is not None:
            hubbard_model += _hopping_term(
                    up_index(site), up_index(bottom_neighbor), -tunneling)
            hubbard_model += _hopping_term(
                    down_index(site), down_index(bottom_neighbor), -tunneling)

        # Add local pair Coulomb interaction terms.
        hubbard_model += _coulomb_interaction_term(
                n_spin_orbitals, up_index(site), down_index(site), coulomb,
                particle_hole_symmetry)

        # Add chemical potential and magnetic field terms.
        hubbard_model += number_operator(
                n_spin_orbitals, up_index(site),
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _mean_field_dwave.py View on Github external
mean_field_dwave_model += hermitian_conjugated(hopping_term)

            # Add pairing term
            operators = ((up_index(site), 1),
                         (down_index(right_neighbor), 1))
            pairing_term = FermionOperator(operators, sc_gap / 2.)
            operators = ((down_index(site), 1),
                         (up_index(right_neighbor), 1))
            pairing_term += FermionOperator(operators, -sc_gap / 2.)
            mean_field_dwave_model -= pairing_term
            mean_field_dwave_model -= hermitian_conjugated(pairing_term)

        # Add transition to neighbor below.
        if site + x_dimension + 1 <= n_sites or (periodic and y_dimension > 2):
            # Add spin-up hopping term.
            operators = ((up_index(site), 1), (up_index(bottom_neighbor), 0))
            hopping_term = FermionOperator(operators, -tunneling)
            mean_field_dwave_model += hopping_term
            mean_field_dwave_model += hermitian_conjugated(hopping_term)
            # Add spin-down hopping term
            operators = ((down_index(site), 1),
                         (down_index(bottom_neighbor), 0))
            hopping_term = FermionOperator(operators, -tunneling)
            mean_field_dwave_model += hopping_term
            mean_field_dwave_model += hermitian_conjugated(hopping_term)

            # Add pairing term
            operators = ((up_index(site), 1),
                         (down_index(bottom_neighbor), 1))
            pairing_term = FermionOperator(operators, -sc_gap / 2.)
            operators = ((down_index(site), 1),
                         (up_index(bottom_neighbor), 1))
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _hubbard.py View on Github external
hubbard_model += _hopping_term(
                    down_index(site), down_index(right_neighbor), -tunneling)
        if bottom_neighbor is not None:
            hubbard_model += _hopping_term(
                    up_index(site), up_index(bottom_neighbor), -tunneling)
            hubbard_model += _hopping_term(
                    down_index(site), down_index(bottom_neighbor), -tunneling)

        # Add local pair Coulomb interaction terms.
        hubbard_model += _coulomb_interaction_term(
                n_spin_orbitals, up_index(site), down_index(site), coulomb,
                particle_hole_symmetry)

        # Add chemical potential and magnetic field terms.
        hubbard_model += number_operator(
                n_spin_orbitals, up_index(site),
                -chemical_potential - magnetic_field)
        hubbard_model += number_operator(
                n_spin_orbitals, down_index(site),
                -chemical_potential + magnetic_field)

    return hubbard_model