def get_test_impurity_model(norb=2, ntau=1000, beta=10.0):
    """ Function that generates a random impurity model for testing """

    from triqs.operators import c, c_dag, Operator, dagger

    from pyed.OperatorUtils import fundamental_operators_from_gf_struct
    from pyed.OperatorUtils import symmetrize_quartic_tensor
    from pyed.OperatorUtils import get_quadratic_operator
    from pyed.OperatorUtils import operator_from_quartic_tensor

    orb_idxs = list(np.arange(norb))
    #print "orb_idxs ", orb_idxs
    spin_idxs = ['up', 'do']
    gf_struct = [[spin_idx, orb_idxs] for spin_idx in spin_idxs]
    #print "gf_struct", gf_struct

    # -- Random Hamiltonian

    fundamental_operators = fundamental_operators_from_gf_struct(gf_struct)
    #print "fundamental_operators ", fundamental_operators

    N = len(fundamental_operators)
    t_OO = np.random.random((N, N)) + 1.j * np.random.random((N, N))
    t_OO = 0.5 * (t_OO + np.conj(t_OO.T))

    #print "N", N
    #print "t_OO", t_OO.shape

    #print 't_OO.real =\n', t_OO.real
    #print 't_OO.imag =\n', t_OO.imag

    U_OOOO = np.random.random((N, N, N, N)) + 1.j * np.random.random(
        (N, N, N, N))
    U_OOOO = symmetrize_quartic_tensor(U_OOOO, conjugation=True)

    #print 'gf_struct =', gf_struct
    #print 'fundamental_operators = ', fundamental_operators


    H_loc = get_quadratic_operator(t_OO, fundamental_operators) + \
        operator_from_quartic_tensor(U_OOOO, fundamental_operators)

    #print 'H_loc =', H_loc
    #print "H_loc.type", H_loc.type()

    from triqs.gf import MeshImTime, BlockGf

    mesh = MeshImTime(beta, 'Fermion', ntau)
    Delta_tau = BlockGf(mesh=mesh, gf_struct=gf_struct)

    #print "mesh", mesh
    #print "Delta_tau", Delta_tau

    for block_name, delta_tau in Delta_tau:
        delta_tau.data[:] = -0.5

    return gf_struct, Delta_tau, H_loc
Beispiel #2
0
def test_quadratic():

    n = 10

    h_loc = np.random.random((n, n))
    h_loc = 0.5 * (h_loc + h_loc.T)

    fund_op = [c(0, idx) for idx in range(n)]
    H_loc = get_quadratic_operator(h_loc, fund_op)
    h_loc_ref = quadratic_matrix_from_operator(H_loc, fund_op)

    np.testing.assert_array_almost_equal(h_loc, h_loc_ref)
Beispiel #3
0
def test_single_particle_transform(verbose=False):

    if verbose:
        print('--> test_single_particle_transform')

    h_loc = np.array([
        [1.0, 0.0],
        [0.0, -1.0],
    ])

    op_imp = [c(0, 0), c(0, 1)]

    H_loc = get_quadratic_operator(h_loc, op_imp)
    H_loc_ref = c_dag(0, 0) * c(0, 0) - c_dag(0, 1) * c(0, 1)

    assert ((H_loc - H_loc_ref).is_zero())

    h_loc_ref = quadratic_matrix_from_operator(H_loc, op_imp)
    np.testing.assert_array_almost_equal(h_loc, h_loc_ref)

    if verbose:
        print('h_loc =\n', h_loc)
        print('h_loc_ref =\n', h_loc_ref)
        print('H_loc =', H_loc)

    T_ab = np.array([
        [1., 1.],
        [1., -1.],
    ]) / np.sqrt(2.)

    Ht_loc = operator_single_particle_transform(H_loc, T_ab, op_imp)
    ht_loc = quadratic_matrix_from_operator(Ht_loc, op_imp)

    ht_loc_ref = np.array([
        [0., 1.],
        [1., 0.],
    ])

    Ht_loc_ref = c_dag(0, 0) * c(0, 1) + c_dag(0, 1) * c(0, 0)

    if verbose:
        print('ht_loc =\n', ht_loc)
        print('ht_loc_ref =\n', ht_loc_ref)
        print('Ht_loc =', Ht_loc)
        print('Ht_loc_ref =', Ht_loc_ref)

    assert ((Ht_loc - Ht_loc_ref).is_zero())
    T_imp = block_diag(T_imp, T_imp)
    T_bath = block_diag(T_bath, T_bath)

    print 'V =\n', V
    print 'T_imp =\n', T_imp
    print 'T_bath =\n', T_bath

    T = np.block([[T_imp, V], [V.T, T_bath]])

    print 'T =\n', T

    H_int = h_int_kanamori(spin_names, imp_idxs,
                           np.array([[0, U - 3 * J], [U - 3 * J, 0]]),
                           np.array([[U, U - 2 * J], [U - 2 * J, U]]), J, True)

    H = H_int + get_quadratic_operator(T, fop)

    up, do = spin_names
    index_converter = {
        (up, 0): ('loc', 0, 'up'),
        (do, 0): ('loc', 0, 'down'),
        (up, 1): ('loc', 1, 'up'),
        (do, 1): ('loc', 1, 'down'),
        (up, 2): ('loc', 2, 'up'),
        (do, 2): ('loc', 2, 'down'),
        (up, 3): ('loc', 3, 'up'),
        (do, 3): ('loc', 3, 'down'),
        (up, 4): ('loc', 4, 'up'),
        (do, 4): ('loc', 4, 'down'),
        (up, 5): ('loc', 5, 'up'),
        (do, 5): ('loc', 5, 'down'),
Beispiel #5
0
    }

    # ------------------------------------------------------------------
    # -- Setup Hamiltonian

    # -- Local crystal field

    h_loc = np.array([
        [1.0, 0.0],
        [0.0, -1.0],
    ])

    I = np.eye(p.num_spins)
    h_loc = np.kron(h_loc, I)

    p.H_loc = p.crystal_field * get_quadratic_operator(h_loc, p.op_imp)

    # -- Bath sites and hybridizations

    V2 = 1.0
    V3 = 3.0
    E2 = -1.0
    E3 = -4.0

    h_bath = np.array([
        [0, 0, V2, 0],
        [0, 0, 0, V3],
        [V2, 0, E2, 0],
        [0, V3, 0, E3],
    ])