Example #1
0
File: wick.py Project: spieseba/gpt
        def __init__(self, index, propagators, is_bar):
            self.index = index
            self.is_bar = is_bar

            self.propagators = {}
            for p in propagators:

                if type(propagators[p]) == dict:
                    self.propagators[p] = propagators[p]
                else:
                    p_sc = {}

                    if isinstance(propagators[p], g.lattice):
                        p_s = g.separate_spin(propagators[p])
                        for a, b in p_s:
                            p_sc[(a, b)] = g.separate_color(p_s[a, b])
                    else:
                        Ns = propagators[p].otype.shape[0]
                        Nc = propagators[p].otype.shape[2]
                        p_sc = {(s1, s2):
                                {(c1, c2): propagators[p].array[s1, s2, c1, c2]
                                 for c1 in range(Nc) for c2 in range(Nc)}
                                for s1 in range(Ns) for s2 in range(Ns)}

                    self.propagators[p] = p_sc
Example #2
0
def spin_transpose(l):
    xs = gpt.separate_spin(l)
    Ns = l[:].shape[-3]
    y = {}
    for i in range(Ns):
        for j in range(Ns):
            y[i, j] = xs[j, i]
    dst = gpt.mspincolor(l.grid)
    gpt.merge_spin(dst, y)
    return dst
Example #3
0
File: split.py Project: wettig/gpt
import sys

rng = g.random("test")
vol = [16, 16, 16, 32]
grid_rb = g.grid(vol, g.single, g.redblack)
grid = g.grid(vol, g.single)
field = g.vcolor
Nlat = 12

################################################################################
# Spin/Color separation
################################################################################
msc = g.mspincolor(grid_rb)
rng.cnormal(msc)

xs = g.separate_spin(msc)
xc = g.separate_color(msc)

for s1 in range(4):
    for s2 in range(4):
        eps = np.linalg.norm(
            msc[0, 0, 0, 0].array[s1, s2, :, :] - xs[s1, s2][0, 0, 0, 0].array
        )
        assert eps < 1e-13

for c1 in range(3):
    for c2 in range(3):
        eps = np.linalg.norm(
            msc[0, 0, 0, 0].array[:, :, c1, c2] - xc[c1, c2][0, 0, 0, 0].array
        )
        assert eps < 1e-13
Example #4
0
# 2 * N for read/write
GB = 2 * N * msc.otype.nfloats * grid.precision.nbytes * grid.fsites / 1e9

xc = g.separate_color(msc)
g.merge_color(msc, xc)
t0 = g.time()
for n in range(N):
    xc = g.separate_color(msc)
t1 = g.time()
for n in range(N):
    g.merge_color(msc, xc)
t2 = g.time()
g.message("%-50s %g GB/s %g s" % ("separate_color:", GB / (t1 - t0),
                                  (t1 - t0) / N))
g.message("%-50s %g GB/s %g s" % ("merge_color:", GB / (t2 - t1),
                                  (t2 - t1) / N))

xs = g.separate_spin(msc)
g.merge_spin(msc, xs)
t0 = g.time()
for n in range(N):
    xs = g.separate_spin(msc)
t1 = g.time()
for n in range(N):
    g.merge_spin(msc, xs)
t2 = g.time()
g.message("%-50s %g GB/s %g s" % ("separate_spin:", GB / (t1 - t0),
                                  (t1 - t0) / N))
g.message("%-50s %g GB/s %g s" % ("merge_spin:", GB / (t2 - t1),
                                  (t2 - t1) / N))
Example #5
0
def quark_contract_xx(mspincolor1, mspincolor2, components):
    """
    This routine is written for Nc = 3

    y^{k2, k1} = \\sum_{i1, i2, j1, j2} \\epsilon^{i1, j1, k1} \\epsilon^{i2, j2, k2} xc1^{i1, i2} xc2^{j1, j2}
    Permutations: +(0, 1, 2), +(1, 2, 0), +(2, 0, 1),
                     -(1, 0, 2), -(0, 2, 1), -(2, 1, 0)
    i.e.
    - y^{0, 0} = \\epsilon^{i1, j1, 0} \\epsilon^{i2, j2, 0} xc1^{i1, i2} xc2^{j1, j2}
        Permutations: +(1, 2, 0), -(2, 1, 0);         +(1, 2, 0), -(2, 1, 0)
    - y^{0, 1} = \\epsilon^{i1, j1, 1} \\epsilon^{i2, j2, 0} xc1^{i1, i2} xc2^{j1, j2}
        Permutations: +(2, 0, 1), -(0, 2, 1);         +(1, 2, 0), -(2, 1, 0)
    - y^{0, 2} = \\epsilon^{i1, j1, 2} \\epsilon^{i2, j2, 0} xc1^{i1, i2} xc2^{j1, j2}
        Permutations: +(0, 1, 2), -(1, 0, 2)          +(1, 2, 0), -(2, 1, 0)
    - y^{1, 0} = \\epsilon^{i1, j1, 0} \\epsilon^{i2, j2, 1} xc1^{i1, i2} xc2^{j1, j2}
        Permutations: +(1, 2, 0), -(2, 1, 0)          +(2, 0, 1), -(0, 2, 1)
    - y^{1, 1} = \\epsilon^{i1, j1, 1} \\epsilon^{i2, j2, 1} xc1^{i1, i2} xc2^{j1, j2}
        Permutations: +(2, 0, 1), -(0, 2, 1)          +(2, 0, 1), -(0, 2, 1)
    - y^{1, 2} = \\epsilon^{i1, j1, 2} \\epsilon^{i2, j2, 1} xc1^{i1, i2} xc2^{j1, j2}
        Permutations: +(0, 1, 2), -(1, 0, 2)          +(2, 0, 1), -(0, 2, 1)
    - y^{2, 0} = \\epsilon^{i1, j1, 0} \\epsilon^{i2, j2, 2} xc1^{i1, i2} xc2^{j1, j2}
        Permutations: +(1, 2, 0), -(2, 1, 0)          +(0, 1, 2), -(1, 0, 2)
    - y^{2, 1} = \\epsilon^{i1, j1, 1} \\epsilon^{i2, j2, 2} xc1^{i1, i2} xc2^{j1, j2}
        Permutations: +(2, 0, 1), -(0, 2, 1)          +(0, 1, 2), -(1, 0, 2)
    - y^{2, 2} = \\epsilon^{i1, j1, 2} \\epsilon^{i2, j2, 2} xc1^{i1, i2} xc2^{j1, j2}
        Permutations: +(0, 1, 2), -(1, 0, 2)          +(0, 1, 2), -(1, 0, 2)
    """

    t_separatespin, t_separatecolor, t_create, t_bilinear, t_merge = 0.0, 0.0, 0.0, 0.0, 0.0
    t_start = gpt.time()

    comps1, comps2 = dict(), dict()
    for mspincolor, comps in [[mspincolor1, comps1], [mspincolor2, comps2]]:
        if isinstance(mspincolor, gpt.lattice):
            t_separatespin -= gpt.time()
            spin_separated = gpt.separate_spin(mspincolor)
            t_separatespin += gpt.time()

            for spinkey in spin_separated:
                t_separatecolor -= gpt.time()
                comps[spinkey] = gpt.separate_color(spin_separated[spinkey])
                t_separatecolor += gpt.time()

        elif isinstance(mspincolor, dict):
            for spinkey in mspincolor:
                n_keys = len(mspincolor[spinkey])
                n_colors = np.sqrt(n_keys)
                assert n_colors == int(n_colors)
                assert (int(n_colors) - 1,
                        int(n_colors) - 1) in mspincolor[spinkey]
                comps[spinkey] = mspincolor[spinkey]
    grid = comps1[0, 0][0, 0].grid

    t_create -= gpt.time()
    dst = gpt.mspincolor(grid)
    spinsep_dst = {(ii // 4, ii % 4): gpt.mcolor(grid) for ii in range(16)}
    bilinear_result = [gpt.complex(grid) for _ in range(9)]
    t_create += gpt.time()

    leftbase = np.array(
        [[4, 5, 7, 8], [7, 8, 1, 2], [1, 2, 4, 5], [5, 3, 8, 6], [8, 6, 2, 0],
         [2, 0, 5, 3], [3, 4, 6, 7], [6, 7, 0, 1], [0, 1, 3, 4]],
        dtype=np.int32)
    rightbase = np.array(
        [[8, 7, 5, 4], [2, 1, 8, 7], [5, 4, 2, 1], [6, 8, 3, 5], [0, 2, 6, 8],
         [3, 5, 0, 2], [7, 6, 4, 3], [1, 0, 7, 6], [4, 3, 1, 0]],
        dtype=np.int32)

    for spin_key in components.keys():

        lefts, rights = [], []
        bilin_coeffs, bilin_leftbasis, bilin_rightbasis = [], [], []
        for nn, comps in enumerate(components[spin_key]):
            c0_0, c0_1, c1_0, c1_1 = comps

            for ii in range(9):
                lefts.append(comps1[c0_0, c0_1][ii // 3, ii % 3])
                rights.append(comps2[c1_0, c1_1][ii // 3, ii % 3])

            bilin_coeffs = np.append(bilin_coeffs, [1.0, -1.0, -1.0, +1.0])
            bilin_leftbasis.append(leftbase + nn * 9)
            bilin_rightbasis.append(rightbase + nn * 9)

        bilin_coeffs = np.array([bilin_coeffs for _ in range(9)],
                                dtype=np.int32)
        bilin_leftbasis = np.concatenate(bilin_leftbasis, axis=1)
        bilin_rightbasis = np.concatenate(bilin_rightbasis, axis=1)

        t_bilinear -= gpt.time()
        gpt.bilinear_combination(bilinear_result, lefts, rights, bilin_coeffs,
                                 bilin_leftbasis, bilin_rightbasis)
        t_bilinear += gpt.time()

        cmat_dict = dict()
        for ii in range(9):
            cmat_dict[ii // 3, ii % 3] = bilinear_result[ii]

        t_merge -= gpt.time()
        gpt.merge_color(spinsep_dst[spin_key], cmat_dict)
        t_merge += gpt.time()

    t_merge -= gpt.time()
    gpt.merge_spin(dst, spinsep_dst)
    t_merge += gpt.time()

    t_total = gpt.time() - t_start
    t_profiled = t_separatespin + t_separatecolor + t_create + t_bilinear + t_merge

    if gpt.default.is_verbose("quark_contract_xx"):
        gpt.message("quark_contract_xx: total", t_total, "s")
        gpt.message("quark_contract_xx: t_separatespin", t_separatespin, "s",
                    round(100 * t_separatespin / t_total, 1), "%")
        gpt.message("quark_contract_xx: t_separatecolor", t_separatecolor, "s",
                    round(100 * t_separatecolor / t_total, 1), "%")
        gpt.message("quark_contract_xx: t_create", t_create, "s",
                    round(100 * t_create / t_total, 1), "%")
        gpt.message("quark_contract_xx: t_bilinear", t_bilinear, "s",
                    round(100 * t_bilinear / t_total, 1), "%")
        gpt.message("quark_contract_xx: t_merge", t_merge, "s",
                    round(100 * t_merge / t_total, 1), "%")
        gpt.message("quark_contract_xx: unprofiled", t_total - t_profiled, "s",
                    round(100 * (t_total - t_profiled) / t_total, 1), "%")
    return dst