Exemple #1
0
    def merge_normal_distributions(self, fill=0):
        """Merge all normal distributed rvs together into one joint normal

           Set new covariances (and previous 0 covs) to 'fill'
        """
        non_altered = []
        means = []
        blocks = []
        names = []
        for rvs, dist in self.distributions():
            names.extend([rv.name for rv in rvs])
            if isinstance(dist, stats.crv_types.NormalDistribution):
                means.append(dist.mean)
                blocks.append(sympy.Matrix([dist.std**2]))
            elif isinstance(dist, stats.joint_rv_types.MultivariateNormalDistribution):
                means.extend(dist.mu)
                blocks.append(dist.sigma)
            else:
                non_altered.extend(rvs)
        if names:
            if len(blocks) > 1:
                # Need special case for len(blocks) == 1 because of sympy 1.5.1 bug #18618
                M = sympy.BlockDiagMatrix(*blocks)
                M = sympy.Matrix(M)
            else:
                M = sympy.Matrix(blocks[0])
            if fill != 0:
                for row, col in itertools.product(range(M.rows), range(M.cols)):
                    if M[row, col] == 0:
                        M[row, col] = fill
            new_rvs = JointNormalSeparate(names, means, M)
            self.__init__(new_rvs + non_altered)
Exemple #2
0
def make_syst(a, width):
    kx, ky, kz = kwant.continuum.momentum_operators

    ham_rashba = kwant.continuum.sympify(
        '''                                                                                                                                         
        B*g*mu_B/2*sigma_z+(hbar**2/(2*m_0)*(k_x/m*k_x+k_y/m*k_y+k_z/m*k_z)-V(x, y))*eye(2)+                                                                 
        alpha_z*(k_x*sigma_y-k_y*sigma_x)+alpha_y*(k_z*sigma_x-k_x*sigma_z)+alpha_x*(k_y*sigma_z-k_z*sigma_y)                                                      
    ''')
    modified = ['V(x, y)']
    ham_rashba = ham_rashba.subs(
        {kx: kwant.continuum.sympify('k_x-pi/phi_0*B*y')})
    ham1 = ham_rashba
    ham2 = -ham_rashba.conjugate().subs({s: -s for s in [kx, ky, kz]})
    hamiltonian = sympy.Matrix(sympy.BlockDiagMatrix(ham1, ham2))
    hamiltonian[0, 3] = hamiltonian[3,
                                    0] = +kwant.continuum.sympify('Delta_SC')
    hamiltonian[1, 2] = hamiltonian[2,
                                    1] = -kwant.continuum.sympify('Delta_SC')
    subs = {s.conjugate(): s for s in hamiltonian.atoms(sympy.Symbol)}
    subs.update({
        kwant.continuum.sympify(m).conjugate(): kwant.continuum.sympify(m)
        for m in modified
    })
    hamiltonian = hamiltonian.subs(subs)

    template = discretize(hamiltonian, ('x', 'y'), grid_spacing=a)
    wire = kwant.Builder()
    shape = get_hexagon(width)
    wire.fill(template, lambda s: shape([s.pos[0], s.pos[1]]), (0, 0))
    return wire.finalized()
Exemple #3
0
    def block(self, ls, als, bs):
        matrices = []
        for i in range(len(als)):
            matrixi = sp.Matrix([[als[i], -bs[i]], [bs[i], als[i]]])

            matrices.append(matrixi)
        B = sp.BlockDiagMatrix(sp.Matrix([ls]), *matrices)
        return B
Exemple #4
0
def get_foreman():
    # Basis transformation
    v_n = lambda i, N: sympy.Matrix(  # noqa: E731
        [1 if i == n else 0 for n in range(N)])
    S, X, Y, Z = [v_n(i, 4) for i in range(4)]
    up, dw = [v_n(i, 2) for i in range(2)]

    X = sympy.I * X
    Y = sympy.I * Y
    Z = sympy.I * Z

    molenkamp_basis = [
        kr(up, S),
        kr(dw, S),
        +(1 / sympy.sqrt(2)) * kr(up, X + sympy.I * Y),
        +(1 / sympy.sqrt(6)) * (kr(dw, X + sympy.I * Y) - kr(up, 2 * Z)),
        -(1 / sympy.sqrt(6)) * (kr(up, X - sympy.I * Y) + kr(dw, 2 * Z)),
        -(1 / sympy.sqrt(2)) * kr(dw, X - sympy.I * Y),
        +(1 / sympy.sqrt(3)) * (kr(dw, X + sympy.I * Y) + kr(up, Z)),
        +(1 / sympy.sqrt(3)) * (kr(up, X - sympy.I * Y) - kr(dw, Z)),
    ]

    subs_notation = {
        Ec: Ev + E0,
        L: -(g1 + 4 * g2) * (hbar**2 / 2 / m0),
        M: -(g1 - 2 * g2) * (hbar**2 / 2 / m0),
        Np: -(3 * g3 + (3 * kappa + 1)) * (hbar**2 / 2 / m0),
        Nm: -(3 * g3 - (3 * kappa + 1)) * (hbar**2 / 2 / m0),
        Ac: (g0 * hbar**2 / 2 / m0),
    }

    Hs = spin_orbit()

    Hcc = sympy.Matrix([Ec + kx * Ac * kx + ky * Ac * ky + kz * Ac * kz])
    Hcv = +sympy.I * sympy.Matrix([[P * kx, P * ky, P * kz]])
    Hvc = -sympy.I * sympy.Matrix([kx * P, ky * P, kz * P])

    data = [[valence_term(i, j) for j in range(3)] for i in range(3)]
    Hvv = sympy.Matrix(data)

    H4 = sympy.BlockMatrix([[Hcc, Hcv], [Hvc, Hvv]])
    H8 = sympy.Matrix(sympy.BlockDiagMatrix(H4, H4)) + Hs

    dag = lambda x: x.conjugate().transpose()  # noqa: E731
    U_dag = sympy.Matrix(sympy.BlockMatrix([molenkamp_basis]))
    U = dag(U_dag)

    hamiltonian = U * H8 * dag(U)
    hamiltonian = hamiltonian.subs(subs_notation)
    hamiltonian = hamiltonian + (Ev - Delta / 3) * sympy.diag(
        0, 0, 1, 1, 1, 1, 1, 1)
    return sympy.ImmutableMatrix(hamiltonian.expand())
Exemple #5
0
 def _calc_covariance_matrix(self):
     non_altered = []
     means = []
     blocks = []
     names = []
     for rvs, dist in self.distributions():
         names.extend([rv.name for rv in rvs])
         if isinstance(dist, stats.crv_types.NormalDistribution):
             means.append(dist.mean)
             blocks.append(sympy.Matrix([dist.std**2]))
         elif isinstance(
                 dist, stats.joint_rv_types.MultivariateNormalDistribution):
             means.extend(dist.mu)
             blocks.append(dist.sigma)
         else:
             non_altered.extend(rvs)
     if names:
         M = sympy.BlockDiagMatrix(*blocks)
         M = sympy.Matrix(M)
     return means, M, names, non_altered
Exemple #6
0
 def _calc_covariance_matrix(self, ruv=False):
     non_altered = []
     means = []
     blocks = []
     names = []
     if ruv:
         dists = self.distributions(level=VariabilityLevel.RUV)
     else:
         dists = self.distributions(exclude_level=VariabilityLevel.RUV)
     for rvs, dist in dists:
         names.extend([rv.name for rv in rvs])
         if isinstance(dist, stats.crv_types.NormalDistribution):
             means.append(dist.mean)
             blocks.append(sympy.Matrix([dist.std ** 2]))
         elif isinstance(dist, stats.joint_rv_types.MultivariateNormalDistribution):
             means.extend(dist.mu)
             blocks.append(dist.sigma)
         else:
             non_altered.extend(rvs)
     if names:
         M = sympy.BlockDiagMatrix(*blocks)
         M = sympy.Matrix(M)
     return means, M, names, non_altered