Inconsistent calculation result
Hi Kwant Users I notice an inconsistency in calculation result using Python IDLE (3.5.1, Anaconda3). The issue is that every time I execute the same code, it gives me a different result.The test code that I use is the example code for graphene quantum dot calculation (2.7.1) . First, I used the different parameter (r=3). Each time I executed the same code, it returned different wavefunction. If I use a large r (r=8), the wavefunction(n=225) is consistent. But if I plot the wavefunction 22 instead of 225 as an example, then the wavefunction is different for each time. I tested the code within jupyter notebook and it doesn't show any inconsistencies. Can anyone advise me what raises this issue ? Is it because of Kwant package or Python IDLE or the calculation script itself? If I still want to use Python IDLE to do the calculation. How can I make sure my calculation result is correct? The test code is copied at the end of the email. Thanks in advance. Sincerely, Liming Test code: ================================================================ ================================================================ # Tutorial 2.7.1. 2D example: graphene quantum dot # ================================================ # # Physics background # ------------------ # - graphene edge states # # Kwant features highlighted # -------------------------- # - demonstrate different ways of plotting import kwant from matplotlib import pyplot lat = kwant.lattice.honeycomb() a, b = lat.sublattices def make_system(r=8, t=-1, tp=-0.1): def circle(pos): x, y = pos return x**2 + y**2 < r**2 sys = kwant.Builder() sys[lat.shape(circle, (0, 0))] = 0 sys[lat.neighbors()] = t sys.eradicate_dangling() if tp: sys[lat.neighbors(2)] = tp return sys def plot_system(sys): kwant.plot(sys) # the standard plot is ok, but not very intelligible. One can do # better by playing wioth colors and linewidths # use color and linewidths to get a better plot def family_color(site): return 'black' if site.family == a else 'white' def hopping_lw(site1, site2): return 0.04 if site1.family == site2.family else 0.1 kwant.plot(sys, site_lw=0.1, site_color=family_color, hop_lw=hopping_lw) def plot_data(sys, n): import scipy.linalg as la sys = sys.finalized() ham = sys.hamiltonian_submatrix() evecs = la.eigh(ham)[1] wf = abs(evecs[:, n])**2 # the usual - works great in general, looks just a bit crufty for # small systems kwant.plotter.map(sys, wf, oversampling=10, cmap='gist_heat_r') # use two different sort of triangles to cleanly fill the space def family_shape(i): site = sys.sites[i] return ('p', 3, 180) if site.family == a else ('p', 3, 0) def family_color(i): return 'black' if sys.site(i).family == a else 'white' kwant.plot(sys, site_color=wf, site_symbol=family_shape, site_size=0.5, hop_lw=0, cmap='gist_heat_r') # plot by changing the symbols itself def site_size(i): return 3 * wf[i] / wf.max() kwant.plot(sys, site_size=site_size, site_color=(0, 0, 1, 0.3), hop_lw=0.1) def main(): # plot the graphene system in different styles sys = make_system() plot_system(sys) # compute a wavefunction (number 225) and plot it in different # styles sys = make_system(tp=0) plot_data(sys, 22) # Call the main function if the script gets executed (as opposed to imported). # See <http://docs.python.org/library/__main__.html>. if __name__ == '__main__': main()
Hi, Hi Kwant Users
I notice an inconsistency in calculation result using Python IDLE (3.5.1, Anaconda3).
The issue is that every time I execute the same code, it gives me a different result.The test code that I use is the example code for graphene quantum dot calculation (2.7.1) .
First, I used the different parameter (r=3). Each time I executed the same code, it returned different wavefunction. If I use a large r (r=8), the wavefunction(n=225) is consistent. But if I plot the wavefunction 22 instead of 225 as an example, then the wavefunction is different for each time. I tested the code within jupyter notebook and it doesn't show any inconsistencies.
Can anyone advise me what raises this issue ? Is it because of Kwant package or Python IDLE or the calculation script itself?
This works for me using Python 2, which gives me a clue as to what the problem is. The order of the Kwant sites in the finalized system (and hence the sort order of wavefunctions) is essentially given by the order that some keys are pulled out of a dictionary during finalization. For a given script this order was consistent across different runs in Python 2, but is not in Python 3 [1] The next question is the following: even if the order of sites is changed each time the script is run, a given site still corresponds to a given spatial position, so why does the (absolute value squared of the) wavefunction *look* different each time it is plotted? I believe that the answer lies in the symmetry of the system that you are studying. If I look at eigenvalues 21 and 22 I see that they are identical, i.e. there is a degeneracy (which is endowed by the symmetry of your system). The ordering of these two eigenstates is therefore arbitrary, and given that a different problem is being solved each time the script is run (the sites have been rearranged), it would not surprise me that these two eigenstates are ordered differently sometimes. This explanation is corroborated by the fact that when I run your script with the bleeding edge version of Kwant (notably after this merge request had been applied [2]) then I see consistent results across runs of the script. TLDR; degenerate eigenstates are being rearranged due to non-deterministic Python 3 dictionaries, this will be fixed in the next Kwant release Happy Kwanting, Joe [1]: https://docs.python.org/3/whatsnew/3.3.html [2]: https://gitlab.kwant-project.org/kwant/kwant/merge_requests/23
participants (2)
-
Joseph Weston
-
L.M J