How to use the openfermion.utils.number_operator 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
def _coulomb_interaction_term(
        n_sites, i, j, coefficient, particle_hole_symmetry, bosonic=False):
    op_class = BosonOperator if bosonic else FermionOperator
    number_operator_i = number_operator(n_sites, i, parity=2*bosonic - 1)
    number_operator_j = number_operator(n_sites, j, parity=2*bosonic - 1)
    if particle_hole_symmetry:
        number_operator_i -= op_class((), 0.5)
        number_operator_j -= op_class((), 0.5)
    return coefficient * number_operator_i * number_operator_j
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _hubbard.py View on Github external
particle_hole_symmetry=False,
                    bosonic=True)
        if bottom_neighbor is not None:
            # Add hopping term
            hubbard_model += _hopping_term(
                    site, bottom_neighbor, -tunneling, bosonic=True)
            # Add local Coulomb interaction term
            hubbard_model += _coulomb_interaction_term(
                    n_sites, site, bottom_neighbor, dipole,
                    particle_hole_symmetry=False,
                    bosonic=True)

        # Add on-site interaction.
        hubbard_model += (
            number_operator(n_sites, site, 0.5 * interaction, parity=1)
            * (number_operator(n_sites, site, parity=1) - BosonOperator(()))
        )

        # Add chemical potential.
        hubbard_model += number_operator(
                n_sites, site, -chemical_potential, parity=1)

    return hubbard_model
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _hubbard.py View on Github external
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)

    return hubbard_model
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _hubbard.py View on Github external
def _coulomb_interaction_term(
        n_sites, i, j, coefficient, particle_hole_symmetry, bosonic=False):
    op_class = BosonOperator if bosonic else FermionOperator
    number_operator_i = number_operator(n_sites, i, parity=2*bosonic - 1)
    number_operator_j = number_operator(n_sites, j, parity=2*bosonic - 1)
    if particle_hole_symmetry:
        number_operator_i -= op_class((), 0.5)
        number_operator_j -= op_class((), 0.5)
    return coefficient * number_operator_i * number_operator_j
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _hubbard.py View on Github external
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
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _mean_field_dwave.py View on Github external
Default is True.

    Returns:
        mean_field_dwave_model: An instance of the FermionOperator class.
    """
    # Initialize fermion operator class.
    n_sites = x_dimension * y_dimension
    n_spin_orbitals = 2 * n_sites
    mean_field_dwave_model = FermionOperator()

    # Loop through sites and add terms.
    for site in range(n_sites):
        # Add chemical potential
        mean_field_dwave_model += number_operator(
            n_spin_orbitals, up_index(site), -chemical_potential)
        mean_field_dwave_model += number_operator(
            n_spin_orbitals, down_index(site), -chemical_potential)

        # Index coupled orbitals.
        right_neighbor = site + 1
        bottom_neighbor = site + x_dimension
        # Account for periodic boundaries.
        if periodic:
            if (x_dimension > 2) and ((site + 1) % x_dimension == 0):
                right_neighbor -= x_dimension
            if (y_dimension > 2) and (site + x_dimension + 1 > n_sites):
                bottom_neighbor -= x_dimension * y_dimension

        # Add transition to neighbor on right
        if (site + 1) % x_dimension or (periodic and x_dimension > 2):
            # Add spin-up hopping term.
            operators = ((up_index(site), 1), (up_index(right_neighbor), 0))
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _hubbard.py View on Github external
# Add hopping term
            hubbard_model += _hopping_term(site, right_neighbor, -tunneling)
            # Add local Coulomb interaction term
            hubbard_model += _coulomb_interaction_term(
                    n_sites, site, right_neighbor, coulomb,
                    particle_hole_symmetry)
        if bottom_neighbor is not None:
            # Add hopping term
            hubbard_model += _hopping_term(site, bottom_neighbor, -tunneling)
            # Add local Coulomb interaction term
            hubbard_model += _coulomb_interaction_term(
                    n_sites, site, bottom_neighbor, coulomb,
                    particle_hole_symmetry)

        # Add chemical potential. The magnetic field doesn't contribute.
        hubbard_model += number_operator(n_sites, site, -chemical_potential)

    return hubbard_model
github quantumlib / OpenFermion / src / openfermion / hamiltonians / _hubbard.py View on Github external
n_sites, site, right_neighbor, dipole,
                    particle_hole_symmetry=False,
                    bosonic=True)
        if bottom_neighbor is not None:
            # Add hopping term
            hubbard_model += _hopping_term(
                    site, bottom_neighbor, -tunneling, bosonic=True)
            # Add local Coulomb interaction term
            hubbard_model += _coulomb_interaction_term(
                    n_sites, site, bottom_neighbor, dipole,
                    particle_hole_symmetry=False,
                    bosonic=True)

        # Add on-site interaction.
        hubbard_model += (
            number_operator(n_sites, site, 0.5 * interaction, parity=1)
            * (number_operator(n_sites, site, parity=1) - BosonOperator(()))
        )

        # Add chemical potential.
        hubbard_model += number_operator(
                n_sites, site, -chemical_potential, parity=1)

    return hubbard_model