Skip to content
Snippets Groups Projects
Forked from kwant / kwant
839 commits behind the upstream repository.
1.3.rst 6.20 KiB

What's new in Kwant 1.3

This article explains the user-visible changes in Kwant 1.3. Please consult the full list of changes in Kwant for all the changes up to the most recent bugfix release.

Onsite/hopping functions can depend on different parameters

In Kwant < 1.3 whenever Hamiltonian values were provided as functions, they all had to take the same extra parameters (after the site(s)) regardless of whether or not they actually used them at all. For example, if we had some onsite potential and a magnetic field that we model using the Peierls substitution, we would have to define our value functions like so:

# formally depends on 'B', but 'B' is never used
def onsite(site, V, B):
    return V

# formally depends on 'V', but 'V' is never used
def hopping(site_a, site_b, V, B):
    return (site_b.pos[1] - site_a.pos[1]) * B

This was because previously extra arguments were provided to the system by passing them as a sequence via the args parameter to various Kwant functions (e.g. kwant.smatrix or hamiltonian_submatrix).

In Kwant 1.3 it is now possible for value functions to depend on different parameters, e.g.:

def onsite(site, V):
    return V

def hopping(site_a, site_b, B):
    return (site_b.pos[1] - site_a.pos[1]) * B

If you make use of this feature then you must in addition pass your arguments via the params parameter. The value provided to params must be a dict that maps parameter names to values, e.g.:

kwant.smatrix(syst, params=dict(B=0.1, V=2))

as opposed to the old way:

kwant.smatrix(syst, args=(2, 0.1))

Passing a dictionary of parameters via params is now the recommended way to provide parameters to the system.

Calculating charges and currents using the operator module

Often one may wish to calculate quantities that are defined over sites of the system (such as charge density, spin density along some axis etc), or over hoppings of the system (such as current or spin current). With the introduction of the operator module it has now become much easier to calculate such quantities. To calculate the regular density and current everywhere in a system due to a wavefunction psi, one only needs to do the following:

syst = make_system().finalized()
psi = kwant.wave_function(syst)(0)[0]

# create the operators
Q = kwant.physics.LocalOperator(syst)
J = kwant.physics.Current(syst)

# evaluate the expectation value with the wavefunction
q = Q(psi)
j = J(psi)

See the Kwant tutorial for more details.

Sites in finalized builders have consistent ordering

In Python 3 the internal ordering of dictionaries is not deterministic. This meant that running a Kwant script twice would produce systems with different ordering of sites, which leads to non-reproducible calculations. Now, sites in finalized builders are always ordered first by their site family, then by their tag.

Coincidentally, this means that you can plot a wavefunction in a simple 1D system by just saying:

lattice_1D = chain()
syst = make_system(lattice_1D)
h = syst.hamiltonian_submatrix()
pyplot.plot(np.eigs(h)[1][0])

Improved build configuration

The name of the build configuration file, build.conf by default, is now configurable with the --configfile=PATH option to setup.py. (This makes build configuration usable with the pip tool.) The build configuration as specified in this file is now more general, allowing to modify any build parameter for any of the compiled extensions contained in Kwant. See the :ref:`Installation instructions <build-configuration>` for details.

Scattering states with discrete symmetries and conservation laws

Given a lead Hamiltonian that has a conservation law, it is now possible to construct lead modes that have definite values of the conservation law. This is done by declaring projectors that block diagonalize the Hamiltonian before the modes are computed. For a Hamiltonian that has one or more of the three fundamental discrete symmetries (time-reversal symmetry, particle-hole symmetry and chiral symmetry), it is now possible to declare the symmetries in Kwant. The symmetries are then used to construct scattering states that are properly related by symmetry. The discrete symmetries may be combined with conservation laws, such that if different blocks of the Hamiltonian are related by a discrete symmetry, the lead modes are computed to reflect this.

Pickling support

It is now possible to pickle and unpickle Kwant Builder and System.

Using Builders as templates with Builder.fill()

Builders now have a fill() method that fills the Builder with copies of a template Builder (passed as a parameter). This can be used to "cut out" shapes from high-symmetry models, or to increase the symmetry period of a lead.

attach_lead() can now handle leads with greater than nearest-neighbor hoppings

When attaching a lead with greater than nearest-neighbor hoppings, the symmetry period of the finalized lead is suitably extended and the unit cell size is increased.

Reference implementation of the Kernel Polynomial Method

The kernel polynomial method is now implemented within Kwant to obtain the density of states or, more generally, the spectral density of a given operator acting on a system or Hamiltonian.

Tools for coninuum Hamiltonians

The ~kwant.continuum sub-package is a collection of tools for working with continuum models and for discretizing them into tight-binding models. It aims at providing a handy interface to convert symbolic Hamiltonian into a builder with N-D translational symmetry that can be use to calculate TB band structures or construct systems with different/lower symmetry.