In [1]:
import sys
import os

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

init_notebook()
from matplotlib.collections import LineCollection
from matplotlib.colors import ListedColormap, BoundaryNorm
import scipy.linalg as la

# Set the path to a folder containing data files, to work with filters as well.
data_folder = (
    "data/" if os.path.exists("data") and os.path.isdir("data") else "../../data/"
)


def make_kitaev_chain(L=10):
    lat = kwant.lattice.chain()
    syst = kwant.Builder()

    def onsite(site, p):
        if not p.disorder:
            return (p.m + 2 * p.t) * pauli.sz
        else:
            rand = p.disorder * kwant.digest.gauss(str(site.tag), p.salt)
            return (p.m + rand + 2 * p.t) * pauli.sz

    def hop(site1, site2, p):
        return -p.t * pauli.sz - 1j * p.delta * pauli.sy

    syst[(lat(i) for i in range(L))] = onsite
    syst[kwant.HoppingKind((1,), lat)] = hop

    sym = kwant.TranslationalSymmetry((1,))
    lead = kwant.Builder(sym)

    # The leads are precalculated.
    lead[lat(0)] = onsite
    lead[kwant.HoppingKind((1,), lat)] = hop

    syst.attach_lead(lead)
    syst.attach_lead(lead.reversed())
    syst = syst.finalized()
    syst = syst.precalculate(
        params=dict(p=SimpleNamespace(t=1.0, m=0.0, delta=1.0, disorder=0))
    )

    return syst


def phase_diagram(L, ms, p, num_average=100):
    syst = make_kitaev_chain(L)

    # Adjust the reflection phase such that it's 0 for trivial system.
    trivial = SimpleNamespace(m=10.0, t=1.0, delta=1.0, disorder=0, salt="")
    phase = kwant.smatrix(syst, params=dict(p=trivial)).data[0, 0]
    phase /= abs(phase)
    data = []
    for p.m in ms:
        qt = []
        for p.salt in map(str, range(num_average)):
            s = kwant.smatrix(syst, params=dict(p=p)).data
            qt.append(((s[0, 0] / phase).real, abs(s[0, 1]) ** 2))
        qt = np.mean(qt, axis=0)
        data.append(qt)

    return np.array(data).T
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 2020-06-07 at 08:22:13.734917.