Finding hamiltonian of system (error in user defined function 'onsite')
Hello All, I want to obtain the hamiltonian for my system, for which I am using the *sys.hamiltonian_submatrix()* command, but I get the following error. *UserCodeError: Error occurred in usersupplied value function "onsite".* Below is the code that I am using. *lat = kwant.lattice.honeycomb(a = a)* *p, q = lat.sublattices* *def make_system():* * def hopping(sitei, sitej, phi, salt):* * xi, yi = sitei.pos* * xj, yj = sitej.pos* * return t * np.exp(0.5j * phi * (xi  xj) * (yi + yj))* * def onsite(site, phi, salt):* * x, y = site.pos* * return 0* * def central_region(pos):* * x, y = pos* * return abs(x) < 2*a and abs(y) < 3*a* * sys = kwant.Builder()* * sys[lat.shape(central_region, (0, 0))] = onsite* * sys[lat.neighbors()] = hopping* * sym = kwant.TranslationalSymmetry((a, 0))* * lead = kwant.Builder(sym)* * lead[lat.shape(lambda s: abs(s[1]) < 2*a, (0, 0))] = 0* * lead[lat.neighbors()] = hopping* * sys.attach_lead(lead)* * sys.attach_lead(lead.reversed())* * return sys.finalized()* *sys = make_system()* *sparse_mat = sys.hamiltonian_submatrix() > Throws the error* What confuses me is that the code works fine (when I do further calculations on sys) if I comment the *hamitonian_submatrix()* command but throws up the error otherwise. That made me think that the code itself should be correct, but I could not figure out why that line gives an error. I would be glad if someone can help me out with the same. Any help will be much appreciated! Sincerely, Shivang Agarwal  *Shivang Agarwal* Junior Undergraduate Discipline of Electrical Engineering IIT Gandhinagar Contact: +919869321451
Dear Shivang, You must supply to the hamiltonian_submatrix extra arguments that onsite expects. Inspecting the error message in more detail would reveal that. In order to figure out how to provide the extra arguments to hamiltonian_submatrix, please consult the documentation. Best, Anton On Thu, Jul 5, 2018 at 7:18 PM Shivang Agarwal <shivang.agarwal@iitgn.ac.in> wrote:
Hello All,
I want to obtain the hamiltonian for my system, for which I am using the sys.hamiltonian_submatrix() command, but I get the following error.
UserCodeError: Error occurred in usersupplied value function "onsite".
Below is the code that I am using.
lat = kwant.lattice.honeycomb(a = a) p, q = lat.sublattices
def make_system():
def hopping(sitei, sitej, phi, salt): xi, yi = sitei.pos xj, yj = sitej.pos return t * np.exp(0.5j * phi * (xi  xj) * (yi + yj))
def onsite(site, phi, salt): x, y = site.pos return 0
def central_region(pos): x, y = pos return abs(x) < 2*a and abs(y) < 3*a
sys = kwant.Builder() sys[lat.shape(central_region, (0, 0))] = onsite sys[lat.neighbors()] = hopping
sym = kwant.TranslationalSymmetry((a, 0)) lead = kwant.Builder(sym) lead[lat.shape(lambda s: abs(s[1]) < 2*a, (0, 0))] = 0 lead[lat.neighbors()] = hopping
sys.attach_lead(lead) sys.attach_lead(lead.reversed())
return sys.finalized()
sys = make_system() sparse_mat = sys.hamiltonian_submatrix() > Throws the error
What confuses me is that the code works fine (when I do further calculations on sys) if I comment the hamitonian_submatrix() command but throws up the error otherwise. That made me think that the code itself should be correct, but I could not figure out why that line gives an error.
I would be glad if someone can help me out with the same. Any help will be much appreciated!
Sincerely, Shivang Agarwal
 Shivang Agarwal Junior Undergraduate Discipline of Electrical Engineering IIT Gandhinagar
Contact: +919869321451
participants (2)

Anton Akhmerov

Shivang Agarwal