Addendum --- If I manually add the nearest neighbor couplings
Python: Select all
class Field(CouplingModel, NearestNeighborModel):
def __init__(self):
# Define the lattice with custom sites
site = Qumode()
lattice = Chain(lattice_size, site=site, bc='periodic') # Use open boundary conditions
super().__init__(lattice)
nearest_neighbors = [(i, (i + 1) % lattice_size, [1] ) for i in range(lattice_size)]
print("Manually defined nearest-neighbor pairs:", nearest_neighbors)
print("Nearest-neighbor pairs:", nearest_neighbors)
print("Number of sites in the unit cell:", len(lattice.unit_cell)) # Output: 1 -- this is so we can have local symmetries
print("Total number of sites in the lattice:", lattice.N_sites) # Output: 10
# Add the hopping term (q[n] q[n+1])
#for u1, u2, dx in self.lat.pairs['nearest_neighbors']: # doesn't work
for u1, u2, dx in nearest_neighbors:
print(f"u1: {u1}, type: {type(u1)}, u2: {u2}, type: {type(u2)}")
self.add_coupling_term(1.0, u1, 'q', u2, 'q', dx, plus_hc=True) # u1, u2: The unit cell indices of the two sites involved in the interaction. dx = distance between i and j. dx=1 for nearest neighbours
this gives me ==>
Code: Select all
--------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[261], line 1
----> 1 field = Field()
Cell In[259], line 95
93 for u1, u2, dx in nearest_neighbors:
94 print(f"u1: {u1}, type: {type(u1)}, u2: {u2}, type: {type(u2)}")
---> 95 self.add_coupling_term(1.0, u1, 'q', u2, 'q', dx, plus_hc=True)
File ~/.venv_QIBO/lib/python3.9/site-packages/tenpy/models/model.py:1250, in CouplingModel.add_coupling_term(self, strength, i, j, op_i, op_j, op_string, category, plus_hc)
1248 category = "{op_i}_i {op_j}_j".format(op_i=op_i, op_j=op_j)
1249 ct = self.coupling_terms.setdefault(category, CouplingTerms(self.lat.N_sites))
-> 1250 ct.add_coupling_term(strength, i, j, op_i, op_j, op_string)
1251 if plus_hc:
1252 site_i = self.lat.unit_cell[self.lat.order[i, -1]]
File ~/.venv_QIBO/lib/python3.9/site-packages/tenpy/networks/terms.py:540, in CouplingTerms.add_coupling_term(self, strength, i, j, op_i, op_j, op_string)
538 if not 0 <= i < self.L:
539 raise ValueError("We need 0 <= i < N_sites, got i={i:d}".format(i=i))
--> 540 if not i < j:
541 raise ValueError("need i < j")
542 d1 = self.coupling_terms.setdefault(i, dict())
TypeError: '<' not supported between instances of 'int' and 'str'
It seems to work if I swap the operator and index, i.e.
Python: Select all
self.add_coupling_term(1.0, u1,u2, 'q', 'q', dx, plus_hc=True)
but that seems wrong. Oh boy - I'm so confused.