
Dear all, I am trying new Kwant 1.3 features on a very simple example of graphene monolayer, and, apart from a standard well-working code I add: for x in sys.sites(): x.family.norbs=1 for x in leadxp.sites(): x.family.norbs=1 for x in leadxm.sites(): x.family.norbs=1 (to avoid norbs not defined error) ... J_0 = kwant.operator.Current(sys) wf = kwant.solvers.default.wave_function(sys, energy=0.01, args=[phi,chempot,0]) psi=wf(1) current = J_0(psi) I get the following suspicious message: The size of the file /home/sergey/.local/lib/python3.6/site-packages/kwant/operator.cpython-36m-x86_64-linux-gnu.so is 2734 KB. Do you really want to load it? After answering yes, I get the error message, caused by current = J_0(psi) : "The debugged program raised the exception unhandled ValueError "vector is incorrect shape" File: /home/sergey/.local/lib/python3.6/site-packages/kwant/operator.cpython-36m-x86_64-linux-gnu.so, Line: 529 Break here?" Could anyone guess, what goes wrong? N.B. I have installed Kwant with a command pip3 install kwant Thanks, Sergey

Hi Sergey, Can you post a complete script that reproduces your problem? Sergey Slizovskiy wrote:
I get the following suspicious message: The size of the file /home/sergey/.local/lib/python3.6/site-packages/kwant/operator.cpython-36m-x86_64-linux-gnu.so is 2734 KB. Do you really want to load it?
On my amd64 Linux system the operator*.so files are also of the order of 2-3 MB, so this is not unusual. However, I've never seen the message "Do you really want to load it?" when importing a package. Are you sure that the installation of Kwant went well? You can run all tests using python3 -c 'import kwant; kwant.test(verbose=False)' Since you are on Linux, it could be easier to use binary packages for Kwant that exist for Debian, Ubuntu and Arch. There exist also conda packages, if you like to use that Python distribution. Installing Kwant with pip is like compiling it from source locally. For good performance, you must make sure that Kwant is linked against a decent BLAS + LAPACK and also against MUMPS. Christoph

Hi Christoph, This is a well-working code that computes conductance for graphene with 2 leads (conductance is now commented in the end). The issue appears at line 485. Loading the large package warning may be due to running from Eric6 Python IDE that I use. I have now the latest 1.4 Kwant version installed via pip3 , which added the necessity to remove the default values from "args" parameter list, as it's no longer supported As for ppa install, I might be doing something wrong: (Linux Mint 19 = Ubuntu bionic) sudo add-apt-repository ppa:kwant-project/ppa sudo apt-get update sudo apt-get install kwant returns: "Unable to locate package kwant" The test python3 -c 'import kwant; kwant.test(verbose=False)' returns 21 warnings: (see below) .local/lib/python3.6/site-packages/kwant/tests/test_plotter.py::test_map /home/sergey/.local/lib/python3.6/site-packages/numpy/lib/function_base.py:3652: RuntimeWarning: Invalid value encountered in percentile interpolation=interpolation) /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1300: RuntimeWarning: invalid value encountered in greater overflow_pct = 100 * np.sum(unmasked_data > new_vmax) / len(unmasked_data) /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1301: RuntimeWarning: invalid value encountered in less underflow_pct = 100 * np.sum(unmasked_data < new_vmin) / len(unmasked_data) .local/lib/python3.6/site-packages/kwant/tests/test_plotter.py::test_spectrum /home/sergey/.local/lib/python3.6/site-packages/mpl_toolkits/mplot3d/axes3d.py:1069: UserWarning: Axes3D.figure.canvas is 'None', mouse rotation disabled. Set canvas then call Axes3D.mouse_init(). "Axes3D.figure.canvas is 'None', mouse rotation disabled. " /home/sergey/.local/lib/python3.6/site-packages/numpy/core/fromnumeric.py:83: RuntimeWarning: invalid value encountered in reduce return ufunc.reduce(obj, axis, dtype, out, **passkwargs) .local/lib/python3.6/site-packages/kwant/tests/test_plotter.py::test_density_interpolation /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns .local/lib/python3.6/site-packages/kwant/tests/test_plotter.py::test_current_interpolation /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py:1684: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. field_out[field_slice] += magns .local/lib/python3.6/site-packages/kwant/tests/test_plotter.py::test_current /home/sergey/.local/lib/python3.6/site-packages/kwant/tests/test_plotter.py:522: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. plotter.current(syst, current, file=out) /home/sergey/.local/lib/python3.6/site-packages/kwant/tests/test_plotter.py:526: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. plotter.current(syst, current, ax=ax, file=out) .local/lib/python3.6/site-packages/kwant/tests/test_wraparound.py::test_symmetry /home/sergey/.local/lib/python3.6/site-packages/kwant/tests/test_wraparound.py:169: RuntimeWarning: `particle_hole` and `time_reversal` symmetries are set on the input builder. However they are ignored for the wrapped system, since Kwant lacks a way to express the existence (or not) of a symmetry at k != 0. wrapped = wraparound(syst) .local/lib/python3.6/site-packages/kwant/tests/test_wraparound.py::test_plot_2d_bands /home/sergey/.local/lib/python3.6/site-packages/numpy/core/fromnumeric.py:83: RuntimeWarning: invalid value encountered in reduce return ufunc.reduce(obj, axis, dtype, out, **passkwargs) -- Docs: http://doc.pytest.org/en/latest/warnings.html =================== 282 passed, 21 warnings in 51.40 seconds ===================

Sergey Slizovskiy wrote:
As for ppa install, I might be doing something wrong: (Linux Mint 19 = Ubuntu bionic)
sudo add-apt-repository ppa:kwant-project/ppa sudo apt-get update sudo apt-get install kwant
returns: "Unable to locate package kwant"
Kwant 1.3.3 and Tinyarray packages are available for Ubuntu bionic: https://launchpad.net/~kwant-project/+archive/ubuntu/ppa/+packages No idea what's going wrong with your installation of Linux Mint 19. Christoph

On Fri, Oct 19, 2018 at 11:39 AM Christoph Groth <christoph.groth@cea.fr> wrote:
Sergey Slizovskiy wrote:
sudo add-apt-repository ppa:kwant-project/ppa sudo apt-get update sudo apt-get install kwant
I believe the package name is python3-kwant as written in https://kwant-project.org/install#ubuntu-and-derivatives
Kwant 1.3.3 and Tinyarray packages are available for Ubuntu bionic: https://launchpad.net/~kwant-project/+archive/ubuntu/ppa/+packages
No idea what's going wrong with your installation of Linux Mint 19.
Christoph

Hi,
I am trying new Kwant 1.3 features on a very simple example of graphene monolayer, and, apart from a standard well-working code I add:
for x in sys.sites(): x.family.norbs=1 for x in leadxp.sites(): x.family.norbs=1 for x in leadxm.sites(): x.family.norbs=1 (to avoid norbs not defined error)
...
J_0 = kwant.operator.Current(sys) wf = kwant.solvers.default.wave_function(sys, energy=0.01, args=[phi,chempot,0]) psi=wf(1) current = J_0(psi)
'psi' is a bunch of wavefunctions, but the operators only work on one wavefunction at a time, so you'd have to : currents = [J_0(p) for p in psi] to get the current for each wavefunction. This is actually a pretty common thing to want to do, so it would make sense for the operators to be able to work in a "vectorized" manner. I'll open an enhancement issue on the bugtracker. Happy Kwanting, Joe

Thank you, Joseph, It could be nice to have this in tutorials. In my case, I still get a error Exception "unhandled kwant._common.UserCodeError" Error occurred in user-supplied value function "hopping". Although, my hoppings are pretty innocent and conductance calculation works fine On 18/10/18 17:04, Joseph Weston wrote:
currents = [J_0(p) for p in psi]
Thanks, Sergey

You need to provide the parameters to the current operator when you call it, because it needs to evaluate the Hamiltonian to calculate the current (IIRC this is in the docs). Happy Kwanting, Joe On 10/18/2018 06:16 PM, Sergey Slizovskiy wrote:
Thank you, Joseph, It could be nice to have this in tutorials. In my case, I still get a error Exception "unhandled kwant._common.UserCodeError" Error occurred in user-supplied value function "hopping".
Although, my hoppings are pretty innocent and conductance calculation works fine
On 18/10/18 17:04, Joseph Weston wrote:
currents = [J_0(p) for p in psi]
Thanks,
Sergey

Hi Joe, Thank you, now it works! But I am a bit confused about the physical meaning of the current, created by modes in lead n. How to plot the real current between the two leads? Imagine, as the simplest case, that my geometry is inversion-symmetric, so that lead 0 goes into lead 1 under inversion. Then I expect the current to be inversion-symmetric as well. Thanks, Sergey On 18/10/18 17:30, Joseph Weston wrote:
You need to provide the parameters to the current operator when you call it, because it needs to evaluate the Hamiltonian to calculate the current (IIRC this is in the docs).
Happy Kwanting,
Joe
On 10/18/2018 06:16 PM, Sergey Slizovskiy wrote:
Thank you, Joseph, It could be nice to have this in tutorials. In my case, I still get a error Exception "unhandled kwant._common.UserCodeError" Error occurred in user-supplied value function "hopping".
Although, my hoppings are pretty innocent and conductance calculation works fine
On 18/10/18 17:04, Joseph Weston wrote:
currents = [J_0(p) for p in psi] Thanks,
Sergey

Good morning,
Hi Joe, Thank you, now it works!
Nice!
But I am a bit confused about the physical meaning of the current, created by modes in lead n. How to plot the real current between the two leads? Imagine, as the simplest case, that my geometry is inversion-symmetric, so that lead 0 goes into lead 1 under inversion. Then I expect the current to be inversion-symmetric as well.
Summing the current contributions for *all* the scattering states originating from lead L at an energy E gives you the current you would measure if the fermi levels in all the leads are at energy E and you apply an infinitesimal voltage to lead L. For example if we want to see the current profile if we add an infinitesimal voltage dV to lead 0: wfs = kwant.wave_function(syst, energy=E, params=...) J_0 = dV * sum(J(psi) for psi in wfs(0)) This is analogous to the transmission obtained by kwant.smatrix: smatrix = kwant.smatrix(syst, energy=E, params=...) I_10 = dV * smatrix.transmission(1, 0) I_10 is the current we would measure in lead 1 after applying dV to lead 0. In the above I have elided the e^2/h factor for brevity, but hopefully I have been clear enough to get the point across. Hope that helps, Joe

Good morning, Joe, Thank you, then it looks as I have done it right, but I was confused as I got slightly asymmetric current plot from symmetric geometry. Then, the problem might be in asymmetric choice of starting points for streamplot. I am trying to manually add the symmetric set of starting points. My code is: J_0 = kwant.operator.Current(sys) seed_points = numpy.array([ [x, y] for y in numpy.nditer(numpy.linspace(-Wsample/2, Wsample/2, 40)) for x in numpy.nditer(numpy.linspace(5 , Wcontact+xmiddle-5, 3))]) for en in [0.001, 0.01, 0.02]: wf = kwant.solvers.default.wave_function(sys, energy=en, args=[phi,chempot,0]) psi=wf(1) currents = [J_0(p, args=[phi,chempot,0]) for p in psi] current=sum(currents) kwant.plotter.current(sys, current, relwidth=0.05, start_points=seed_points) pyplot.show(block=False) I have two small questions here: 1) This code gives a strange error: The debugged program raised the exception unhandled TypeError "streamplot() got an unexpected keyword argument 'start_points'" File: /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py, Line: 2164 which is strange since start_points is in the streamplot documentation 2) How to make several plots be generated without manual closure of the previous one? My command pyplot.show(block=False) does not seem to work in this case. Thanks, Sergey On 19/10/18 10:01, Joseph Weston wrote:
Good morning,
Hi Joe, Thank you, now it works! Nice!
But I am a bit confused about the physical meaning of the current, created by modes in lead n. How to plot the real current between the two leads? Imagine, as the simplest case, that my geometry is inversion-symmetric, so that lead 0 goes into lead 1 under inversion. Then I expect the current to be inversion-symmetric as well. Summing the current contributions for *all* the scattering states originating from lead L at an energy E gives you the current you would measure if the fermi levels in all the leads are at energy E and you apply an infinitesimal voltage to lead L.
For example if we want to see the current profile if we add an infinitesimal voltage dV to lead 0:
wfs = kwant.wave_function(syst, energy=E, params=...) J_0 = dV * sum(J(psi) for psi in wfs(0))
This is analogous to the transmission obtained by kwant.smatrix:
smatrix = kwant.smatrix(syst, energy=E, params=...) I_10 = dV * smatrix.transmission(1, 0)
I_10 is the current we would measure in lead 1 after applying dV to lead 0.
In the above I have elided the e^2/h factor for brevity, but hopefully I have been clear enough to get the point across.
Hope that helps,
Joe

Hi Sergey,
1) This code gives a strange error:
The debugged program raised the exception unhandled TypeError "streamplot() got an unexpected keyword argument 'start_points'" File: /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py, Line: 2164
which is strange since start_points is in the streamplot documentation
Ah, in the documentation [1] it does indeed mention "streamplot", but we are actually referring to 'kwant.plotter.streamplot', not matplotlib's one. I will modify the documentation so that the distinction is clearer. Our version of streamplot includes things like including the background color etc. We don't currently provide a way to customize all the options of the underlying calls to matplotlib, because this would be excessively complicated. Luckily it is pretty simple to write your own wrapper that you can customize: def custom_current(syst, current): field, box = kwant.plotter.interpolate_current(syst, current, ...) # your custom args here # make grid for streamplot X = np.linspace(*box[0], num=field.shape[0]) Y = np.linspace(*box[1], num=field.shape[1]) pyplot.streamplot(X, Y, field[:, :, 0], field[:, :, 1], ...) # your custom args here Make sure you post back to the mailing list if you find some heuristic that makes decent plots!
2) How to make several plots be generated without manual closure of the previous one? My command pyplot.show(block=False) does not seem to work in this case.
You can pass a matplotlib axis to 'current' via the 'ax' parameter. This will make the plotter draw into the axes that you provide. You'll need to search on stackoverflow or look in the matplotlib docs to find out how to do exactly what you want, because even though you can totally define several plots, I'm not sure matplotlib can display them simultaneously. Happy Kwanting, Joe [1]: https://kwant-project.org/doc/1/reference/generated/kwant.plotter.current

Hi Joe, Thank you for help! I found simpler answers to my questions. kwant.plotter.current(sys, current, relwidth=0.05, density=1, show=False) pyplot.show(block=False) Also, I found that current asymmetry was indeed there and it was caused by numerical errors: the precision of the current calculation is higher near the lead for which it is calculated, while the error may grow significant near other lead(s). In my case, at some energies it is symmetric, at some - not. Best wishes, Sergey On 19/10/18 12:53, Joseph Weston wrote:
Hi Sergey,
1) This code gives a strange error:
The debugged program raised the exception unhandled TypeError "streamplot() got an unexpected keyword argument 'start_points'" File: /home/sergey/.local/lib/python3.6/site-packages/kwant/plotter.py, Line: 2164
which is strange since start_points is in the streamplot documentation
Ah, in the documentation [1] it does indeed mention "streamplot", but we are actually referring to 'kwant.plotter.streamplot', not matplotlib's one. I will modify the documentation so that the distinction is clearer. Our version of streamplot includes things like including the background color etc.
We don't currently provide a way to customize all the options of the underlying calls to matplotlib, because this would be excessively complicated. Luckily it is pretty simple to write your own wrapper that you can customize:
def custom_current(syst, current): field, box = kwant.plotter.interpolate_current(syst, current, ...) # your custom args here
# make grid for streamplot X = np.linspace(*box[0], num=field.shape[0]) Y = np.linspace(*box[1], num=field.shape[1])
pyplot.streamplot(X, Y, field[:, :, 0], field[:, :, 1], ...) # your custom args here
Make sure you post back to the mailing list if you find some heuristic that makes decent plots!
2) How to make several plots be generated without manual closure of the previous one? My command pyplot.show(block=False) does not seem to work in this case.
You can pass a matplotlib axis to 'current' via the 'ax' parameter. This will make the plotter draw into the axes that you provide.
You'll need to search on stackoverflow or look in the matplotlib docs to find out how to do exactly what you want, because even though you can totally define several plots, I'm not sure matplotlib can display them simultaneously.
Happy Kwanting,
Joe
[1]: https://kwant-project.org/doc/1/reference/generated/kwant.plotter.current

Hi Sergey,
Also, I found that current asymmetry was indeed there and it was caused by numerical errors: the precision of the current calculation is higher near the lead for which it is calculated, while the error may grow significant near other lead(s). In my case, at some energies it is symmetric, at some - not.
This is very surprising; do you think that this could be a bug in Kwant? Can you share a simple script that reproduces this issue (the simpler the better; that way it's easy to debug)? Thanks, Joe

Hi Joe, Sorry, I have to take back my words about unusual asymmetry of the current. It was caused by a real asymmetry of my geometry. I have checked that summing modes of lead 0 leads to the same (but opposite) current, as summing modes of lead 1. Thank you so much for your help! Best wishes, Sergey On 19/10/18 14:51, Joseph Weston wrote:
Hi Sergey,
Also, I found that current asymmetry was indeed there and it was caused by numerical errors: the precision of the current calculation is higher near the lead for which it is calculated, while the error may grow significant near other lead(s). In my case, at some energies it is symmetric, at some - not. This is very surprising; do you think that this could be a bug in Kwant? Can you share a simple script that reproduces this issue (the simpler the better; that way it's easy to debug)?
Thanks,
Joe
participants (4)
-
Anton Akhmerov
-
Christoph Groth
-
Joseph Weston
-
Sergey Slizovskiy