Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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)
return hubbard_model
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),
-chemical_potential - magnetic_field)
hubbard_model += number_operator(
singles = []
doubles_1 = []
doubles_2 = []
# Get singles and doubles amplitudes associated with one
# spatial occupied-virtual pair
for p, q in itertools.product(range(n_virtual), range(n_occupied)):
# Get indices of spatial orbitals
virtual_spatial = n_occupied + p
occupied_spatial = q
# Get indices of spin orbitals
virtual_up = up_index(virtual_spatial)
virtual_down = down_index(virtual_spatial)
occupied_up = up_index(occupied_spatial)
occupied_down = down_index(occupied_spatial)
# Get singles amplitude
# Just get up amplitude, since down should be the same
singles.append(single_amplitudes[virtual_up, occupied_up])
# Get doubles amplitude
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
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)
return hubbard_model
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))
hopping_term = FermionOperator(operators, -tunneling)
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