Problems with memory allocation (?) in KWANT 1.3
Dear KWANT team, I am currently trying to write a program to try to calculate the spin Hall angle in a 4-terminal normal metal using Kwant 1.3 and the conservation law module. The scattering region is a square 40x40. I run in to a problem when trying to run it. The error message I get is: *** Error in `python3': malloc(): memory corruption: 0x00000000034f0de0 *** ======= Backtrace: ========= and then a bunch of stuff, and in the end [Finished in 29.6s with exit code -6] It seems to crash when I make the system too big or for too many energies. But, I don't understand why it doesn't work to solve the problem at one energy, store the result (which is just one number), and then for another. It seems the results from the other runs are somehow stored? I am not that experienced when it comes to programming, so I don't know if the problem is at my end or not. Thanks in advance, Camilla ------------------------------ Here is my code as well: import kwant import tinyarray as ta import numpy as np from scipy import sparse import matplotlib from matplotlib import pyplot s0 = ta.array([[1, 0], [0, 1]]) sx = ta.array([[0, 1], [1, 0]]) sy = ta.array([[0, -1j], [1j, 0]]) sz = ta.array([[1, 0], [0, -1]]) def calculate_sh_conductance(smatrix, leadIn, leadOut): con = -smatrix.transmission((leadOut, 0),(leadIn, 0)) + smatrix.transmission((leadOut, 1),(leadIn, 1)) return con def make_system(t=1.0, W=40, L=40, lead_W = 40): # Now we must specify the number of orbitals per site. lat = kwant.lattice.square(norbs=2) syst = kwant.Builder() """ We define the system below. The s-parameters are site parameters. The onsite has 1 site-parameter, while the hopping has two. The form of the functions must be like this, because Kwant requires it. """ syst[(lat(x, y) for x in range(L) for y in range(W))] = \ lambda s, alpha, phi: 0*4 * t * s0 # The last term here is the AF onsite coupling. syst[kwant.builder.HoppingKind((1, 0), lat, lat)] = \ lambda s1, s2, alpha, phi: -t * s0 - 1j * alpha * sy syst[kwant.builder.HoppingKind((0, 1), lat, lat)] = \ lambda s1, s2, alpha, phi: -t * s0 + 1j * alpha * sx ### Make the leads ### # Side leads lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)), conservation_law=-sz, time_reversal=s0) lead[(lat(0, j) for j in range(W))] =0* 4 * t * s0 lead[lat.neighbors()] = -t * s0 # Note: no spin-orbit in the lead. # Top/bottom leads lead_tb = kwant.Builder(kwant.TranslationalSymmetry((0,-1)), conservation_law =-sz, time_reversal=s0) # We define the start and end fo the lead start = int(L/2 - lead_W/2) end = int(L/2 + lead_W/2) lead_tb[(lat(j,0) for j in range(start,end))] = 0*4 * t * s0 lead_tb[lat.neighbors()] = -t * s0 syst.attach_lead(lead) syst.attach_lead(lead.reversed()) syst.attach_lead(lead_tb) syst.attach_lead(lead_tb.reversed()) syst = syst.finalized() return syst def main(): syst = make_system(t=1.0, W=40, L=40, lead_W = 40) energies = np.linspace(-4,4, 200) socos = 0.5 fig = pyplot.figure(figsize=(13,8)) ax = fig.add_subplot(1, 1, 1) print("Starting spin calculation") conductance = [] # Calculate spin Hall conductance for energy in energies: smatrix= kwant.smatrix(syst, energy=energy, args=(socos, 0)) addi = calculate_sh_conductance(smatrix, 0, 3) conductance.append(addi) print(energy) ax.plot(energies, conductance, label="SOC %s" % socos) ax.legend(fontsize='x-large'); pyplot.show() if __name__ == '__main__': main()
Hi Camilla, Thanks for the bug report!
I am currently trying to write a program to try to calculate the spin Hall angle in a 4-terminal normal metal using Kwant 1.3 and the conservation law module. The scattering region is a square 40x40. I run in to a problem when trying to run it. The error message I get is:
*** Error in `python3': malloc(): memory corruption: 0x00000000034f0de0 *** ======= Backtrace: =========
and then a bunch of stuff, and in the end
[Finished in 29.6s with exit code -6]
Wow! After a bit of investigation it appears that this is a bug in numpy, more specifically in 'numpy.linalg.lstsq', which Kwant uses internally when time reversal symmetry is specified. I see this bug in numpy 1.12.0 and even as far back as 1.8.2, so unfortunately downgrading numpy is not an option. However, I notice that using an equivalent function from scipy does not exhibit this problem, so I will push a fix for this in a few minutes. As you are using the latest development version, I assume that you are installing Kwant using the conda package on the 'kwant' channel. If this is the case, once my fix is pushed and the new development version is built, it will be automatically available and you *should* just be able to go `conda update -c kwant kwant` to get the fix. Happy Kwanting, Joe
Hi and thanks, I tried installing the newest Kwant version now, using: pip3 install git+https://gitlab.kwant-project.org/kwant/kwant.git@master but now I get a new error message (same code): File "/home/camilla/Kwant/Tests/conservation.py", line 91, in <module> main() File "/home/camilla/Kwant/Tests/conservation.py", line 68, in main syst = make_system(t=1.0, W=40, L=40, lead_W = 40) File "/home/camilla/Kwant/Tests/conservation.py", line 56, in make_system syst.attach_lead(lead) File "/home/camilla/.local/lib/python3.5/site-packages/kwant/builder.py", line 1402, in attach_lead self.leads.append(BuilderLead(lead_builder, tuple(interface))) File "/home/camilla/.local/lib/python3.5/site-packages/kwant/builder.py", line 566, in __init__ self.interface = tuple(sorted(interface)) TypeError: unorderable types: tinyarray.ndarray_int() < tinyarray.ndarray_int() [Finished in 1.4s with exit code 1] should I have installed differently. According to pip3 I have installed kwant (1.3.0a0.dev123+g3961899) Sincerely, Camilla
Hi Camilla, It appears that for some reason you have an old version of tinyarray; please also install the development version of tinyarray using pip3 install git+https://gitlab.kwant-project.org/kwant/tinyarray.git@master Best, Anton On Fri, Mar 10, 2017 at 11:09 AM, Camilla Espedal <camilla.espedal@ntnu.no> wrote:
Hi and thanks,
I tried installing the newest Kwant version now, using:
pip3 install git+https://gitlab.kwant-project.org/kwant/kwant.git@master
but now I get a new error message (same code):
File "/home/camilla/Kwant/Tests/conservation.py", line 91, in <module> main() File "/home/camilla/Kwant/Tests/conservation.py", line 68, in main syst = make_system(t=1.0, W=40, L=40, lead_W = 40) File "/home/camilla/Kwant/Tests/conservation.py", line 56, in make_system syst.attach_lead(lead) File "/home/camilla/.local/lib/python3.5/site-packages/kwant/builder.py", line 1402, in attach_lead self.leads.append(BuilderLead(lead_builder, tuple(interface))) File "/home/camilla/.local/lib/python3.5/site-packages/kwant/builder.py", line 566, in __init__ self.interface = tuple(sorted(interface)) TypeError: unorderable types: tinyarray.ndarray_int() < tinyarray.ndarray_int() [Finished in 1.4s with exit code 1]
should I have installed differently. According to pip3 I have installed kwant (1.3.0a0.dev123+g3961899)
Sincerely,
Camilla
Hi again,
I tried installing the newest Kwant version now, using:
pip3 install git+https://gitlab.kwant-project.org/kwant/kwant.git@master
but now I get a new error message (same code):
File "/home/camilla/Kwant/Tests/conservation.py", line 91, in <module> main() File "/home/camilla/Kwant/Tests/conservation.py", line 68, in main syst = make_system(t=1.0, W=40, L=40, lead_W = 40) File "/home/camilla/Kwant/Tests/conservation.py", line 56, in make_system syst.attach_lead(lead) File "/home/camilla/.local/lib/python3.5/site-packages/kwant/builder.py", line 1402, in attach_lead self.leads.append(BuilderLead(lead_builder, tuple(interface))) File "/home/camilla/.local/lib/python3.5/site-packages/kwant/builder.py", line 566, in __init__ self.interface = tuple(sorted(interface)) TypeError: unorderable types: tinyarray.ndarray_int() < tinyarray.ndarray_int() [Finished in 1.4s with exit code 1]
This means that you have a not-recent-enough version of tinyarray. Are you running the code in exactly the same environment as before? It's possible that pip downgraded your tinyarray because we have not yet updated Kwant's setup.py to point to the newest tinyarray because it is not released yet (and therefore not on PyPI). To get the latest tinyarray you should be able to just: pip3 install git+https://gitlab.kwant-project.org/kwant/tinyarray.git@master
should I have installed differently. According to pip3 I have installed kwant (1.3.0a0.dev123+g3961899)
That is the correct version, with the fix I pushed last night. Hope that helps, Joe
participants (3)
-
Anton Akhmerov
-
Camilla Espedal
-
Joseph Weston