In [1]:
import sys

sys.path.append("../../code")
from init_mooc_nb import *

init_notebook()

from scipy import linalg as la
from functools import reduce

pi_ticks = [
    (-np.pi, r"$-\pi$"),
    (-np.pi / 2, r"$-\pi/2$"),
    (0, r"$0$"),
    (np.pi / 2, r"$\pi/2$"),
    (np.pi, r"$\pi$"),
]


def checkerboard(W=None):
    lat = kwant.lattice.general([[2, 0], [1, 1]], [(0, 0), (1, 0)])
    a, b = lat.sublattices
    if W:

        def lead_shape(pos):
            (x, y) = pos
            return 0 <= y < W and 0 <= x < W

        syst = kwant.Builder(kwant.TranslationalSymmetry((1, 1)))
        syst[a.shape(lead_shape, (0, 0))] = 0
        syst[b.shape(lead_shape, (1, 0))] = 0
    else:
        syst = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))
        syst[lat.shape(lambda pos: True, (0, 0))] = 0
    syst[kwant.HoppingKind((0, 0), b, a)] = lambda s1, s2, p: -p.t1
    syst[kwant.HoppingKind((-1, 1), b, a)] = lambda s1, s2, p: -p.t2
    syst[kwant.HoppingKind((1, 0), a, b)] = lambda s1, s2, p: -p.t3
    syst[kwant.HoppingKind((0, 1), a, b)] = lambda s1, s2, p: -p.t4
    return syst


def evolution_operator(hamiltonians, T):
    n = len(hamiltonians)
    exps = [la.expm(-1j * h * T / n) for h in hamiltonians]
    return reduce(np.dot, exps)


def get_h_k(lead, p):
    bands = kwant.physics.Bands(lead, params=dict(p=p))
    h, t = bands.ham, bands.hop
    return lambda k: h + t * np.exp(-1j * k) + t.T.conj() * np.exp(1j * k)
Populated the namespace with:
np, matplotlib, kwant, holoviews, init_notebook, SimpleNamespace, pprint_matrix, scientific_number, pretty_fmt_complex, plt, pf, display_html
from code/edx_components:
MoocVideo, MoocDiscussion, MoocCheckboxesAssessment, MoocMultipleChoiceAssessment, MoocSelfAssessment
from code/functions:
spectrum, hamiltonian_array, h_k, pauli
Using kwant 1.4.2 and holoviews 1.13.2
Executed on 2021-03-06 at 14:57:06.113916.