Hello everyone, While this is working in a system with leads, I am getting an error in the case of a closed system. -------------------------------------------------------------------------------------------------------- sym = kwant.TranslationalSymmetry( lattice.vec((1, 0, 0)), lattice.vec((0, 1, 0)), lattice.vec((0, 0, 1)) ) [....] #Hall bar def onsite(site, B): (x, y, z) = site.pos return stored_model[site] def hopping_Ax(site1, site2, B): x1, y1, z1 = site1.pos x2, y2, z2 = site2.pos return stored_model[site1,site2] * np.exp(-0.5j * B * (x1 + x2) * (y1 - y2)) kwant_model[lattice.shape(shape, (0, 0, 15))] = onsite kwant_model[lattice.neighbors()] = hopping_Ax kwant_sys = wraparound.wraparound(kwant_model).finalized() B = 0.02 # Obtain the Hamiltonian as a dense matrix ham_mat = kwant_sys.hamiltonian_submatrix(args=[B], sparse=True) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) ~\Anaconda3\lib\site-packages\kwant\builder.py in hamiltonian(self, i, j, params, *args) 2000 try: -> 2001 value = value(self.sites[i], *args) 2002 except Exception as exc: ~\Anaconda3\lib\site-packages\wraparound.py in <lambda>(*args) 81 return lambda *args: sum((val(*args) if callable(val) else val) ---> 82 for val in vals) 83 ~\Anaconda3\lib\site-packages\wraparound.py in <genexpr>(.0) 81 return lambda *args: sum((val(*args) if callable(val) else val) ---> 82 for val in vals) 83 ~\Anaconda3\lib\site-packages\wraparound.py in <lambda>(a, *args) 59 assert callable(val) ---> 60 return lambda a, *args: val(a, *args[:mnp]) 61 TypeError: onsite() missing 1 required positional argument: 'B' The above exception was the direct cause of the following exception: UserCodeError Traceback (most recent call last) <ipython-input-19-dd56ba85dfde> in <module>() 1 B = 0.02 2 # Obtain the Hamiltonian as a dense matrix ----> 3 ham_mat = kwant_sys.hamiltonian_submatrix(args=[B], sparse=True) 4 kwant\_system.pyx in kwant._system.hamiltonian_submatrix() ~\Anaconda3\lib\site-packages\kwant\builder.py in hamiltonian(self, i, j, params, *args) 2001 value = value(self.sites[i], *args) 2002 except Exception as exc: -> 2003 _raise_user_error(exc, value) 2004 else: 2005 edge_id = self.graph.first_edge_id(i, j) ~\Anaconda3\lib\site-packages\kwant\builder.py in _raise_user_error(exc, func) 1883 msg = ('Error occurred in user-supplied value function "{0}".\n' 1884 'See the upper part of the above backtrace for more information.') -> 1885 raise UserCodeError(msg.format(func.__name__)) from exc 1886 1887 UserCodeError: Error occurred in user-supplied value function "<lambda>". See the upper part of the above backtrace for more information. -------------------------------------------------------------------------------------------- Eleni Quoting elchatz@auth.gr:
Hello Joseph,
Thank you. It is working when I copy the model and each lead after I have attached them.
Regards,
Eleni
Quoting Joseph Weston
: HI,
I am trying to reproduce the QHE bar device calculations
http://nbviewer.jupyter.org/github/topocm/topocm_content/blob/master/w3_pump...
However, I am having difficulty with the onsite and hopping values as I am using TBModels
https://github.com/Z2PackDev/TBmodels
and therefore the values are not the same for all sites.
I am unsure of the output format of TBModels. Glancing at their documentation I can't see any way of getting the raw matrix elements from a "Model". Looking into the source code it seems that they are stored in a format that will be annoying to query manually.
The problem is that after the scalar values have been passed on to the Builder, these will then be overriden when using functions for the position-dependent Hamiltonian.
I tried making a deep copy of the model, which would then serve as a data structure where to draw the scalar values from when calling the Onsite and Hopping functions. The problem with this is
a) I am getting a KeyError which I am still not sure why it happens b) It does not feel very memory-efficient.
I am wondering if there is another way that this could be done on the Kwant side that I have not been able to think of.
I can't think of a better way to accomplish this. Using TBModels' internal datastructures directly is IMO too much hassle unless your systems are really big.
Did you check that the symmetry of your Kwant system and the TBModels Model are compatible?
Joe
-- Dr. Eleni Chatzikyriakou Computational Physics lab Aristotle University of Thessaloniki elchatz@auth.gr - tel:+30 2310 998109
-- Dr. Eleni Chatzikyriakou Computational Physics lab Aristotle University of Thessaloniki elchatz@auth.gr - tel:+30 2310 998109