2.10. Advanced onebody settings

We show some advanced settings for solving the onebody Schrödinger equation which is based on Solving one-body problems. In the following, syst is a finalized kwant system with leads and we import the onebody module from tkwant:

from tkwant import onebody

2.10.1. Boundary conditions

Special boundary conditions have to be provided in order to solve the dynamic equations for an open quantum systems (with leads). For onebody.WaveFunction they must be precalculated:

boundaries = tkwant.leads.automatic_boundary(syst.leads, tmax=10000, refl_max=1E-10)
scattering_states = kwant.wave_function(syst, energy=1, params={'time':0})
lead, mode = 0, 0
psi_st = scattering_states(lead)[mode]
psi = onebody.WaveFunction.from_kwant(syst, psi_st, boundaries=boundaries, energy=1.)

For the scattering state solver boundary conditions are calculated on the fly. One can provide different boundary conditions by the keyword boundary

boundaries = tkwant.leads.automatic_boundary(syst.leads, tmax=10000, refl_max=1E-10)
psi = onebody.ScatteringStates(syst, energy=1, lead=0, boundaries=boundaries)[mode]

For closed quantum systems (without leads), no boundary conditions are needed.

See also

A tutorial on boundary conditions is given in Boundary conditions. An example script which shows alternative boundary conditions is given in Alternative boundary conditions.

2.10.2. Time integration

The time integration can be changed by prebinding values with the module functool.partial to the onebody solver. In the current example, we change the relative tolerance rtol of the time-stepping algorithm:

import functools as ft
solver_type = ft.partial(tkwant.onebody.solvers.default, rtol=1E-5)
psi = onebody.WaveFunction.from_kwant(syst=syst, boundaries=boundaries,
                                      psi_init=psi_st, energy=1.,

2.10.3. Time-dependent perturbation

When the method onebody.WaveFunction.from_kwant() is used, the time-dependent perturbation \(W(t)\) is extracted from the Hamiltonian of a Kwant system. By defaut, Tkwant uses cubic spline interpolation to interpolate \(W(t)\) in time with with an adaptive stepsize. The interpolation is used for performance reasons, in order to minimize the number of calls to Kwant.

One can switch off interpolation and always evaluate the exact \(W(t)\) function with:

psi = onebody.WaveFunction.from_kwant(syst=syst, psi_init=psi_st, energy=1.,

For the onebody scattering state solver onebody.ScatteringStates, the \(W(t)\) interpolation is switched off with:

import functools as ft

wavefunction_type = ft.partial(tkwant.onebody.WaveFunction.from_kwant,

mode = 0
psi = onebody.ScatteringStates(syst, energy=1., lead=0, tmax=100,

2.10.4. Saving and restarting states

Sometimes we might like to save a state in order to resume a calculation on a later stage. An easy way is to to use the pickle package:

import pickle

psi = onebody.WaveFunction.from_kwant(syst=syst, psi_init=psi_st, energy=1.,

saved = pickle.dumps(psi)

Saving a state works currently only with the tkwant.onebody.kernels.Scipy kernel. The saved object saved can be stored. Recovering the state later on in order to continue the calculation is possible by using

new_psi = pickle.loads(saved)

See Restarting calculations from previously saved results for the complete code.

See also

An example script showing the restarting of states is given in Restarting calculations from previously saved results.