Пример #1
0
    def __call__(self, src, dst):
        grid = src.grid
        # sum_n D^-1 vn vn^dag src = D^-1 vn (src^dag vn)^dag
        dst_sc, src_sc = gpt.vspincolor(grid), gpt.vspincolor(grid)

        for s in range(4):
            for c in range(3):

                gpt.qcd.prop_to_ferm(src_sc, src, s, c)

                self.sc_solver(src_sc, dst_sc)

                gpt.qcd.ferm_to_prop(dst, dst_sc, s, c)
Пример #2
0
    def __init__(self, matrix):

        self.F_grid = matrix.F_grid
        ftmp = gpt.vspincolor(self.F_grid)

        def _Mpc(dst, src):
            matrix.G5M.mat(ftmp, src)
            matrix.G5M.mat(dst, ftmp)

        def _L(dst, src):
            gpt.copy(dst, src)

        def _R(dst, src):
            dst @= matrix.G5M * gpt.gamma[5] * src

        def _S(dst, src):
            dst[:] = 0

        self.Mpc = gpt.matrix_operator(mat=_Mpc,
                                       otype=matrix.otype,
                                       grid=self.F_grid)
        self.L = gpt.matrix_operator(mat=_L,
                                     otype=matrix.otype,
                                     grid=self.F_grid)
        self.R = gpt.matrix_operator(mat=_R,
                                     otype=matrix.otype,
                                     grid=self.F_grid)
        self.S = gpt.matrix_operator(mat=_S,
                                     otype=matrix.otype,
                                     grid=self.F_grid)
Пример #3
0
Файл: g5m.py Проект: lehner/gpt
    def __init__(self, matrix):

        self.F_grid = matrix.F_grid
        ftmp = gpt.vspincolor(self.F_grid)

        def _Mpc(dst, src):
            matrix.G5M.mat(ftmp, src)
            matrix.G5M.mat(dst, ftmp)

        def _ident(dst, src):
            gpt.copy(dst, src)

        def _R(dst, src):
            dst @= matrix.G5M * gpt.gamma[5] * src

        def _S(dst, src):
            dst[:] = 0

        self.Mpc = gpt.matrix_operator(mat=_Mpc,
                                       vector_space=matrix.vector_space)
        self.L = gpt.matrix_operator(mat=_ident,
                                     inv_mat=_ident,
                                     vector_space=matrix.vector_space)
        self.R = gpt.matrix_operator(mat=_R, vector_space=matrix.vector_space)
        self.S = gpt.matrix_operator(mat=_S, vector_space=matrix.vector_space)
Пример #4
0
def mk_gpt_field(ctype, geo):
    if ctype == "ColorMatrix":
        return g.mcolor(mk_grid(geo))
    elif ctype == "WilsonMatrix":
        return g.mspincolor(mk_grid(geo))
    elif ctype == "WilsonVector":
        return g.vspincolor(mk_grid(geo))
    else:
        raise Exception("make_gpt_field")
Пример #5
0
def gpt_from_qlat_ff4d(ff):
    assert isinstance(ff, q.FermionField4d)
    geo = ff.geo()
    ctype = "WilsonVector"
    total_site = geo.total_site()
    multiplicity = 1
    tag = "gpt_from_qlat"
    plan = get_qlat_gpt_copy_plan(ctype, total_site, multiplicity, tag)
    grid = mk_grid(geo)
    gpt_ff = g.vspincolor(grid)
    plan(gpt_ff, ff.mview())
    return gpt_ff
Пример #6
0
    def perform(self, root):
        global current_config, current_light_quark
        if current_config is not None and current_config.conf_file != self.conf_file:
            current_config = None
        if current_config is None:
            current_config = config(self.conf_file)

        if (current_light_quark is not None
                and current_light_quark.evec_dir != self.evec_dir):
            current_light_quark = None
        if current_light_quark is None:
            current_light_quark = light_quark(current_config, self.evec_dir)

        prop_l = {
            "sloppy": current_light_quark.prop_l_sloppy,
            "exact": current_light_quark.prop_l_exact,
        }[self.solver]

        vcj = g.load(f"{root}/{self.conf}/pm_basis/basis")
        c = g.coordinates(vcj[0])
        c = c[c[:, 3] == self.t]

        g.message(
            f"t = {self.t}, ilist = {self.ilist}, basis size = {len(vcj)}, solver = {self.solver}"
        )

        root_job = f"{root}/{self.name}"
        output = g.gpt_io.writer(f"{root_job}/propagators")

        # create sources
        srcD = [
            g.vspincolor(current_config.l_exact.U_grid) for spin in range(4)
        ]

        for i in self.ilist:

            for spin in range(4):
                srcD[spin][:] = 0
                srcD[spin][c, spin, :] = vcj[i][c]

                g.message("Norm of source:", g.norm2(srcD[spin]))
                if i == 0:
                    g.message("Source at origin:", srcD[spin][0, 0, 0, 0])
                    g.message("Source at time-origin:", srcD[spin][0, 0, 0,
                                                                   self.t])

            prop = g.eval(prop_l * srcD)
            g.mem_report(details=False)

            for spin in range(4):
                output.write(
                    {f"t{self.t}s{spin}c{i}_{self.solver}": prop[spin]})
                output.flush()
Пример #7
0
def read_openqcd_fermion(fname, cb=None):
    """
    Read a spinor field written by openqcd into a vspincolor object.
    Extracts only the values on the sites corresponding to 'cb' if this parameter is set.
    """
    g.message(f"Reading spinor from file {fname} with checkerboard = {cb}")

    # read into numpy array
    lat, norm, fld = read_sfld(fname)

    # change the order in numpy and convert to gpt field
    # openqcd in memory, slow to fast: t x y z,
    # we in memory, slow to fast: t z y x,
    # -> need to swap x and z
    fld = np.swapaxes(fld, 1, 3)
    grid = g.grid(fdimensions_from_openqcd(lat), g.double)
    field = g.vspincolor(grid)
    field[:] = fld.flatten(order="C")
    norm2_file = norm[0]
    norm2_field = g.norm2(field)

    assert fields_agree_openqcd(norm2_file, norm2_field)
    assert fields_agree(norm2_file, norm2_field, g.double.eps)

    if not cb:
        return field

    assert cb in [g.even, g.odd]
    cbgrid = g.grid(
        grid.gdimensions,
        grid.precision,
        g.redblack,
        parent=grid.parent,
        mpi=grid.mpi,
    )
    cbfield = g.vspincolor(cbgrid)
    g.pick_checkerboard(cb, cbfield, field)
    return cbfield
Пример #8
0
    def __init__(self, matrix, inverter):
        self.matrix = matrix
        self.inverter = inverter

        self.F_grid_eo=matrix.F_grid_eo
        self.F_grid=matrix.F_grid

        self.ie=gpt.vspincolor(self.F_grid_eo)
        self.io=gpt.vspincolor(self.F_grid_eo)
        self.t1=gpt.vspincolor(self.F_grid_eo)
        self.t2=gpt.vspincolor(self.F_grid_eo)
        self.oe=gpt.vspincolor(self.F_grid_eo)
        self.oo=gpt.vspincolor(self.F_grid_eo)
        self.ftmp=gpt.vspincolor(self.F_grid)
Пример #9
0
    def __init__(self, setup, params):
        # save input
        self.setup = setup
        self.params = params

        # aliases
        s = self.setup
        par = self.params

        # parameters
        self.smooth_solver = g.util.to_list(par["smooth_solver"], s.nlevel - 1)
        self.wrapper_solver = g.util.to_list(par["wrapper_solver"],
                                             s.nlevel - 2)
        self.coarsest_solver = par["coarsest_solver"]

        # verbosity
        self.verbose = g.default.is_verbose("multi_grid_inverter")

        # print prefix
        self.print_prefix = ["mg: level %d:" % i for i in range(s.nlevel)]

        # assertions
        assert g.util.entries_have_length([self.smooth_solver], s.nlevel - 1)
        assert g.util.entries_have_length([self.wrapper_solver], s.nlevel - 2)
        assert g.util.is_callable(
            [self.smooth_solver, self.coarsest_solver, self.wrapper_solver])
        assert type(self.coarsest_solver) != list
        assert not g.util.all_have_attribute(self.wrapper_solver, "inverter")

        # timing
        self.t = [
            g.timer("mg_solve_lvl_%d" % (lvl)) for lvl in range(s.nlevel)
        ]

        # temporary vectors
        self.r, self.e = [None] * s.nlevel, [None] * s.nlevel
        for lvl in range(s.finest + 1, s.nlevel):
            nf_lvl = s.nf_lvl[lvl]
            self.r[lvl] = g.vcomplex(s.grid[lvl], s.nbasis[nf_lvl])
            self.e[lvl] = g.vcomplex(s.grid[lvl], s.nbasis[nf_lvl])
        self.r[s.finest] = g.vspincolor(s.grid[s.finest])

        # setup a history for all solvers
        self.history = [None] * s.nlevel
        for lvl in range(s.finest, s.coarsest):
            self.history[lvl] = {"smooth": [], "wrapper": []}
        self.history[s.coarsest] = {"coarsest": []}
Пример #10
0
gre.checkerboard(g.odd)

print(gre)

sys.exit(0)

# Calculate U^\dag U
u = U[0][0, 1, 2, 3]

v = g.vcolor([0, 1, 0])

g.message(g.adj(v))
g.message(g.adj(u) * u * v)

gr = g.grid([2, 2, 2, 2], g.single)
g.message(g.mspincolor(gr)[0, 0, 0, 0] * g.vspincolor(gr)[0, 0, 0, 0])

g.message(g.trace(g.mspincolor(gr)[0, 0, 0, 0]))

# Expression including numpy array
r = g.eval(u * U[0] + U[1] * u)
g.message(g.norm2(r))

# test inner and outer products
v = g.vspincolor([[0, 0, 0], [0, 0, 2], [0, 0, 0], [0, 0, 0]])
w = g.vspincolor([[0, 0, 0], [0, 0, 0], [0, 0, 0], [1, 0, 0]])
xx = v * g.adj(w)
g.message(xx[1][3][2][0])
g.message(xx)
g.message(g.adj(v) * v)
Пример #11
0
    def __init__(self, mat_f, params):
        # save parameters
        self.params = params

        # fine grid from fine matrix
        if issubclass(type(mat_f), g.matrix_operator):
            self.grid = [mat_f.grid[1]]
        else:
            self.grid = [mat_f.grid]

        # grid sizes - allow specifying in two ways
        if "grid" in params:
            self.grid.extend(params["grid"])
        elif "blocksize" in params:
            for i, bs in enumerate(params["blocksize"]):
                assert type(bs) == list
                self.grid.append(g.block.grid(self.grid[i], bs))
        else:
            assert 0

        # dependent sizes
        self.nlevel = len(self.grid)
        self.ncoarselevel = self.nlevel - 1
        self.finest = 0
        self.coarsest = self.nlevel - 1

        # other parameters
        self.nblockortho = g.util.to_list(params["nblockortho"],
                                          self.nlevel - 1)
        self.check_blockortho = g.util.to_list(params["check_blockortho"],
                                               self.nlevel - 1)
        self.nbasis = g.util.to_list(params["nbasis"], self.nlevel - 1)
        self.make_hermitian = g.util.to_list(params["make_hermitian"],
                                             self.nlevel - 1)
        self.save_links = g.util.to_list(params["save_links"], self.nlevel - 1)
        self.npreortho = g.util.to_list(params["npreortho"], self.nlevel - 1)
        self.npostortho = g.util.to_list(params["npostortho"], self.nlevel - 1)
        self.vector_type = g.util.to_list(params["vector_type"],
                                          self.nlevel - 1)
        self.distribution = g.util.to_list(params["distribution"],
                                           self.nlevel - 1)
        self.solver = g.util.to_list(params["solver"], self.nlevel - 1)

        # verbosity
        self.verbose = g.default.is_verbose("multi_grid_setup")

        # print prefix
        self.print_prefix = [
            "mg_setup: level %d:" % i for i in range(self.nlevel)
        ]

        # easy access to current level and neighbors
        self.lvl = [i for i in range(self.nlevel)]
        self.nf_lvl = [i - 1 for i in range(self.nlevel)]
        self.nc_lvl = [i + 1 for i in range(self.nlevel)]
        self.nf_lvl[self.finest] = None
        self.nc_lvl[self.coarsest] = None

        # halved nbasis
        self.nb = []
        for lvl, b in enumerate(self.nbasis):
            assert b % 2 == 0
            self.nb.append(b // 2)

        # assertions
        assert self.nlevel >= 2
        assert g.util.entries_have_length(
            [
                self.nblockortho,
                self.nbasis,
                self.make_hermitian,
                self.save_links,
                self.npreortho,
                self.npostortho,
                self.vector_type,
                self.distribution,
                self.solver,
                self.nb,
            ],
            self.nlevel - 1,
        )

        # timing
        self.t = [
            g.timer("mg_setup_lvl_%d" % (lvl)) for lvl in range(self.nlevel)
        ]

        # matrices (coarse ones initialized later)
        self.mat = [mat_f] + [None] * (self.nlevel - 1)

        # setup random basis vectors on all levels but coarsest
        self.basis = [None] * self.nlevel
        for lvl, grid in enumerate(self.grid):
            if lvl == self.coarsest:
                continue
            elif lvl == self.finest:
                self.basis[lvl] = [
                    g.vspincolor(grid) for __ in range(self.nbasis[lvl])
                ]
            else:
                self.basis[lvl] = [
                    g.vcomplex(grid, self.nbasis[self.nf_lvl[lvl]])
                    for __ in range(self.nbasis[lvl])
                ]
            self.distribution[lvl](self.basis[lvl][0:self.nb[lvl]])

        # setup a block map on all levels but coarsest
        self.blockmap = [None] * self.nlevel
        for lvl in self.lvl:
            if lvl == self.coarsest:
                continue
            else:
                self.blockmap[lvl] = g.block.map(self.grid[self.nc_lvl[lvl]],
                                                 self.basis[lvl])

        # setup coarse link fields on all levels but finest
        self.A = [None] * self.nlevel
        for lvl in range(self.finest + 1, self.nlevel):
            self.A[lvl] = [
                g.mcomplex(self.grid[lvl], self.nbasis[self.nf_lvl[lvl]])
                for __ in range(9)
            ]

        # setup a solver history
        self.history = [[None]] * (self.nlevel - 1)

        # rest of setup
        self.__call__()
Пример #12
0
    (0.45, 1.0, None, two_flavor_ratio, mk_chron(cg_e), mk_chron(cg_s), light),
    (0.18, 0.45, None, two_flavor_ratio, mk_chron(cg_e), mk_chron(cg_s),
     light),
    (0.07, 0.18, None, two_flavor_ratio, mk_chron(cg_e), mk_chron(cg_s),
     light),
    (0.017, 0.07, None, two_flavor_ratio, mk_chron(cg_e), mk_chron(cg_s),
     light),
    (0.0026, 0.017, None, two_flavor_ratio, mk_chron(cg_e), mk_chron(cg_s),
     light),  # activated after ckpoint_lat.128
    (
        0.0176, 1.0, rat_fnc, eofa_ratio, mk_slv_e(), mk_slv_s(), light
    ),  # around 227 changed to 0.0176 from (0.0129, 1.0, rat_fnc, eofa_ratio, mk_slv_e(), mk_slv_s(), light),
]

fields = [
    (U + [g.vspincolor(F_grid_eo)]),
    (U + [g.vspincolor(F_grid_eo)]),
    (U + [g.vspincolor(F_grid_eo)]),
    (U + [g.vspincolor(F_grid_eo)]),
    (U + [g.vspincolor(F_grid_eo)]),
    (U + [g.vspincolor(U[0].grid)]),
]
# test test
#rat = g.algorithms.rational.zolotarev_inverse_square_root(1.0**0.5, 4**0.5, 2)
#rat_fnc = g.algorithms.rational.rational_function(rat.zeros, rat.poles, rat.norm)
#hasenbusch_ratios = [ # Nf=2+1
#(0.6, 1.0, rat_fnc),
#(0.6, 1.0, rat_fnc),
#(0.6, 1.0, rat_fnc),
#(0.3, 0.6, rat_fnc),
#(0.3, 0.6, rat_fnc)
Пример #13
0
def msc():
    return g.vspincolor(fine_grid)
Пример #14
0
    work_dir = os.environ["WORK_DIR"]
else:
    work_dir = "."

# grids
fgrid = g.grid([4, 8, 8, 8, 16], g.single, g.redblack)
cgrid = g.grid([1, 4, 4, 4, 4], g.single)
# fgrid = g.grid([12, 96, 48, 24, 24], g.single, g.redblack)
# cgrid = g.grid([1, 96//4, 48//4, 24//4, 24//4], g.single)

# vectors
nbasis = 40
nsingle = 10
nevec = 48
rng = g.random("test")
basis = [g.vspincolor(fgrid) for i in range(nbasis)]
cevec = [g.vcomplex(cgrid, nbasis) for i in range(nevec)]
feval = [rng.normal(mu=2.0, sigma=0.5).real for i in range(nevec)]
for b in basis:
    b.checkerboard(g.odd)
rng.cnormal([basis, cevec])
b = g.block.map(cgrid, basis)
for i in range(2):
    b.orthonormalize()

for mpi_layout in [[1, 1, 1, 1, 1], [1, 2, 2, 2, 2]]:

    # save in fixed layout
    g.save(
        f"{work_dir}/cevec",
        [basis, cevec, feval],
Пример #15
0
    def __init__(self, U, params):

        shift_eo.__init__(self, U, boundary_phases=params["boundary_phases"])

        Nc = U[0].otype.Nc
        otype = g.ot_vector_spin_color(4, Nc)
        grid = U[0].grid
        grid_eo = grid.checkerboarded(g.redblack)
        self.F_grid = grid
        self.U_grid = grid
        self.F_grid_eo = grid_eo
        self.U_grid_eo = grid_eo

        self.vector_space_F = g.vector_space.explicit_grid_otype(self.F_grid, otype)
        self.vector_space_U = g.vector_space.explicit_grid_otype(self.U_grid, otype)
        self.vector_space_F_eo = g.vector_space.explicit_grid_otype(
            self.F_grid_eo, otype
        )

        self.src_e = g.vspincolor(grid_eo)
        self.src_o = g.vspincolor(grid_eo)
        self.dst_e = g.vspincolor(grid_eo)
        self.dst_o = g.vspincolor(grid_eo)
        self.dst_e.checkerboard(g.even)
        self.dst_o.checkerboard(g.odd)

        if params["kappa"] is not None:
            assert params["mass"] is None
            self.m0 = 1.0 / params["kappa"] / 2.0 - 4.0
        else:
            self.m0 = params["mass"]

        self.xi_0 = params["xi_0"]
        self.csw_r = params["csw_r"] / self.xi_0
        self.csw_t = params["csw_t"]
        self.nu = params["nu"]

        self.kappa = 1.0 / (2.0 * (self.m0 + 1.0 + 3.0 * self.nu / self.xi_0))

        self.open_bc = params["boundary_phases"][self.nd - 1] == 0.0
        if self.open_bc:
            assert all(
                [
                    self.xi_0 == 1.0,
                    self.nu == 1.0,
                    self.csw_r == self.csw_t,
                    "cF" in params,
                ]
            )  # open bc only for isotropic case, require cF passed
            self.cF = params["cF"]
            T = self.L[self.nd - 1]

        # compute field strength tensor
        if self.csw_r != 0.0 or self.csw_t != 0.0:
            self.clover = g.mspincolor(grid)
            self.clover[:] = 0
            I = g.identity(self.clover)
            for mu in range(self.nd):
                for nu in range(mu + 1, self.nd):
                    if mu == (self.nd - 1) or nu == (self.nd - 1):
                        cp = self.csw_t
                    else:
                        cp = self.csw_r
                    self.clover += (
                        -0.5
                        * cp
                        * g.gamma[mu, nu]
                        * I
                        * g.qcd.gauge.field_strength(U, mu, nu)
                    )

            if self.open_bc:
                # set field strength tensor to unity at the temporal boundaries
                value = -0.5 * self.csw_t
                self.clover[:, :, :, 0, :, :, :, :] = 0.0
                self.clover[:, :, :, T - 1, :, :, :, :] = 0.0
                for alpha in range(4):
                    for a in range(Nc):
                        self.clover[:, :, :, 0, alpha, alpha, a, a] = value
                        self.clover[:, :, :, T - 1, alpha, alpha, a, a] = value

                if self.cF != 1.0:
                    # add improvement coefficients next to temporal boundaries
                    value = self.cF - 1.0
                    for alpha in range(4):
                        for a in range(Nc):
                            self.clover[:, :, :, 1, alpha, alpha, a, a] += value
                            self.clover[:, :, :, T - 2, alpha, alpha, a, a] += value

            # integrate kappa into clover matrix for inversion
            self.clover += 1.0 / 2.0 * 1.0 / self.kappa * I

            self.clover_inv = g.matrix.inv(self.clover)

            self.clover_eo = {
                g.even: g.lattice(grid_eo, self.clover.otype),
                g.odd: g.lattice(grid_eo, self.clover.otype),
            }
            self.clover_inv_eo = {
                g.even: g.lattice(grid_eo, self.clover.otype),
                g.odd: g.lattice(grid_eo, self.clover.otype),
            }
            for cb in self.clover_eo:
                g.pick_checkerboard(cb, self.clover_eo[cb], self.clover)
                g.pick_checkerboard(cb, self.clover_inv_eo[cb], self.clover_inv)
        else:
            self.clover = None
            self.clover_inv = None

        self.Meooe = g.matrix_operator(
            mat=lambda dst, src: self._Meooe(dst, src),
            vector_space=self.vector_space_F_eo,
        )
        self.Mooee = g.matrix_operator(
            mat=lambda dst, src: self._Mooee(dst, src),
            inv_mat=lambda dst, src: self._MooeeInv(dst, src),
            vector_space=self.vector_space_F_eo,
        )
        self.Dhop = g.matrix_operator(
            mat=lambda dst, src: self._Dhop(dst, src), vector_space=self.vector_space_F
        )
        matrix_operator.__init__(
            self, lambda dst, src: self._M(dst, src), vector_space=self.vector_space_F
        )
        self.G5M = g.matrix_operator(
            lambda dst, src: self._G5M(dst, src), vector_space=self.vector_space_F
        )
        self.Mdiag = g.matrix_operator(
            lambda dst, src: self._Mdiag(dst, src), vector_space=self.vector_space_F
        )
        self.ImportPhysicalFermionSource = g.matrix_operator(
            lambda dst, src: g.copy(dst, src), vector_space=self.vector_space_F
        )
        self.ExportPhysicalFermionSolution = g.matrix_operator(
            lambda dst, src: g.copy(dst, src), vector_space=self.vector_space_F
        )
        self.ExportPhysicalFermionSource = g.matrix_operator(
            lambda dst, src: g.copy(dst, src), vector_space=self.vector_space_F
        )
        self.Dminus = g.matrix_operator(
            lambda dst, src: g.copy(dst, src), vector_space=self.vector_space_F
        )
Пример #16
0
        "csw_t": 0,
        "xi_0": 1,
        "nu": 1,
        "isAnisotropic": False,
        "boundary_phases": [1.0, 1.0, 1.0, 1.0],
    },
)

# number of basis vectors
nbasis_f = 30

# number of block orthogonalization steps
nblockortho = 1

# setup fine basis
basis_f = [g.vspincolor(grid_f) for __ in range(nbasis_f // 2)]
rng.cnormal(basis_f)

# split fine basis into chiral halfs
g.qcd.fermion.coarse.split_chiral(basis_f)

# setup fine block map
bm_f = g.block.map(grid_c, basis_f)

# orthonormalize fine basis
for i in range(nblockortho):
    g.message("Block ortho step %d" % i)
    bm_f.orthonormalize()

# create coarse link fields
A_c = [g.mcomplex(grid_c, nbasis_f) for __ in range(9)]
Пример #17
0
c = g.algorithms.polynomial.chebyshev({"low": 0.5, "high": 2.0, "order": 10})

# implicitly restarted lanczos
irl = g.algorithms.eigen.irl({
    "Nk": 60,
    "Nstop": 60,
    "Nm": 80,
    "resid": 1e-8,
    "betastp": 0.0,
    "maxiter": 20,
    "Nminres": 7,
    #    "maxapply" : 100
})

# start vector
start = g.vspincolor(w.Mpc.vector_space[0].grid)
start[:] = g.vspincolor([[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]])
start.checkerboard(parity)

# generate eigenvectors
evec, ev = irl(c(w.Mpc), start)  # , g.checkpointer("checkpoint")

# memory info
g.mem_report()

# print eigenvalues of NDagN as well
evals, eps2 = g.algorithms.eigen.evals(w.Mpc, evec, real=True)
assert all([e2 < 1e-11 for e2 in eps2])

# test low-mode approximation of inverse
inv = g.algorithms.inverter
Пример #18
0
def vec_f_full():
    return g.vspincolor(mat_f.F_grid)
Пример #19
0
    "boundary_phases":
    [cmath.exp(1j), cmath.exp(2j),
     cmath.exp(3j), cmath.exp(4j)],
}

# pf=g.params("~/gpt/tests/wilson.txt")
# print(pf)

# take slow reference implementation of wilson (kappa = 1/2/(m0 + 4) ) ;
w_ref = g.qcd.fermion.reference.wilson_clover(U, p)

# and fast Grid version
w = g.qcd.fermion.wilson_clover(U, p, kappa=0.137)

# create point source
src = rng.cnormal(g.vspincolor(grid))

dst_ref, dst = g.lattice(src), g.lattice(src)

# correctness
dst_ref @= w_ref * src
dst @= w * src

eps = g.norm2(dst - dst_ref) / g.norm2(dst)
g.message("Test wilson versus reference:", eps)
assert eps < 1e-13

# now timing
t0 = g.time()
for i in range(100):
    w_ref(dst_ref, src)
Пример #20
0
    def perform(self, root):
        global basis_size, sloppy_per_job, T, current_config
        if current_config is not None and current_config.conf_file != self.conf_file:
            current_config = None
        if current_config is None:
            current_config = config(self.conf_file)

        output_correlator = g.corr_io.writer(f"{root}/{self.name}/head.dat")

        # <np,sp| D^{-1} Gamma D^{-1} |n,s> = < (D^{-1})^\dagger |np,sp> | Gamma | D^{-1} |n,s > >
        # = < Gamma5 D^{-1} Gamma5 |np,sp> | Gamma | D^{-1} |n,s > >
        # = < D^{-1} |np,sp> | Gamma5 Gamma | D^{-1} |n,s > > gamma5_sign[sp]
        indices = [0, 1, 2, 5]
        prec = {"sloppy": 0, "exact": 1}[self.solver]

        half_peramb = g.load(
            f"{root}/{self.conf}/pm_compressed_half_peramb_{self.solver}_t{self.t}/propagators"
        )

        sdomain = half_peramb["sparse_domain"]
        scale = (sdomain.grid.gsites / sdomain.grid.Nprocessors /
                 len(sdomain.local_coordinates))
        g.message("scale =", scale)
        gamma5_sign = [1.0 * scale, 1.0 * scale, -1.0 * scale, -1.0 * scale]

        for i0 in range(0, basis_size, sloppy_per_job):
            half_peramb_i = {}
            for i in range(i0, i0 + sloppy_per_job):
                for spin in range(4):
                    f = g.vspincolor(sdomain.grid)
                    f[:] = 0
                    sdomain.promote(
                        f, half_peramb[f"t{self.t}s{spin}c{i}_{self.solver}"])
                    half_peramb_i[f"t{self.t}s{spin}c{i}_{self.solver}"] = f

            for j0 in range(0, basis_size, sloppy_per_job):
                if j0 == i0:
                    half_peramb_j = half_peramb_i
                else:
                    half_peramb_j = {}
                    for j in range(j0, j0 + sloppy_per_job):
                        for spin in range(4):
                            f = g.vspincolor(sdomain.grid)
                            f[:] = 0
                            sdomain.promote(
                                f, half_peramb[
                                    f"t{self.t}s{spin}c{j}_{self.solver}"])
                            half_peramb_j[
                                f"t{self.t}s{spin}c{j}_{self.solver}"] = f

                for i in range(i0, i0 + sloppy_per_job):
                    for spin in range(4):
                        g.message(i, spin)
                        hp_i = g(sdomain.weight() * half_peramb_i[
                            f"t{self.t}s{spin}c{i}_{self.solver}"])
                        for mu in indices:
                            hp_i_gamma = g(g.gamma[5] * g.gamma[mu] * hp_i)
                            for spin_prime in range(4):
                                slc_j = [
                                    g(gamma5_sign[spin_prime] *
                                      g.adj(half_peramb_j[
                                          f"t{self.t}s{spin_prime}c{j}_{self.solver}"]
                                            ) * hp_i_gamma)
                                    for j in range(j0, j0 + sloppy_per_job)
                                ]
                                slc = g.slice(slc_j, 3)

                                for j in range(j0, j0 + sloppy_per_job):
                                    output_correlator.write(
                                        f"output/G{mu}_prec{prec}/n_{j}_{i}_s_{spin_prime}_{spin}_t_{self.t}",
                                        slc[j - j0],
                                    )

        output_correlator.close()
Пример #21
0
def vec_f_half():
    return g.vspincolor(mat_f.F_grid_eo)
Пример #22
0
    ev3 = [0.0] * len(cevec)
    for i, v in enumerate(cevec):
        v_fine @= b.promote * v
        for j in range(nsmoother):
            v_fine_smooth @= smoother * v_fine
            v_fine @= v_fine_smooth / g.norm2(v_fine_smooth)**0.5
        ev_smooth = g.algorithms.eigen.evals(q.NDagN, [v_fine],
                                             check_eps2=1e-2,
                                             real=True)
        ev3[i] = ev_smooth[0]
        g.message("Eigenvalue %d = %.15g" % (i, ev3[i]))
    g.save("ev3", ev3)

# tests
start = g.lattice(basis[0])
start[:] = g.vspincolor([[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]])
start *= 1.0 / g.norm2(start)**0.5


def save_history(fn, history):
    f = open(fn, "wt")
    for i, v in enumerate(history):
        f.write("%d %.15E\n" % (i, v))
    f.close()


test_solver = params["test_solver"]
solver = g.algorithms.inverter.sequence(
    g.algorithms.inverter.coarse_deflate(cevec, basis, ev3),
    test_solver)(q.Mpc)
v_fine[:] = 0
Пример #23
0
#
# Production code to generate fine-grid basis vectorscoarse-grid eigenvectors using existing
#
import gpt as g

# parameters
fn = g.default.get("--params", "params.txt")
params = g.params(fn, verbose=True)

# load configuration
U = params["config"]

# matrix to use
fmatrix = params["fmatrix"](U)
op = params["op"](fmatrix)
grid = op.grid[0]

# implicitly restarted lanczos
irl = params["method_evec"]

# run
start = g.vspincolor(grid)
start[:] = g.vspincolor([[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]])
start.checkerboard(g.odd)  # traditionally, calculate odd-site vectors

try:
    basis, ev = g.load("checkpoint", grids=grid)
except g.LoadError:
    basis, ev = irl(op, start, params["checkpointer"])
    g.save("checkpoint", (basis, ev))
Пример #24
0
            g.message(f"Algebra<>Matrix {mu}: {eps2}")
            assert eps2 < 1e-14

# reconstruct and test the gamma matrix elements
for mu in g.gamma:
    gamma = g.gamma[mu]
    g.message("Test numpy matrix representation of", mu)
    gamma_mu_mat = np.identity(4, dtype=np.complex128)
    for j in range(4):
        c = g.vspin([1 if i == j else 0 for i in range(4)])
        gamma_mu_mat[:, j] = (gamma * c).array
    eps = np.linalg.norm(gamma_mu_mat - gamma.tensor().array)
    assert eps < 1e-14

# test multiplication of spin-color vector
sc = g.vspincolor([[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0.12, 0]])
for mu in g.gamma:
    gamma = g.gamma[mu]
    g.message("Test numpy matrix application to vspincolor for", mu)
    vec = (gamma * sc).array
    for i in range(4):
        for j in range(3):
            eps = abs(vec[i, j] - sum(gamma.tensor().array[i, :] * sc[:, j]))
            assert eps < 1e-14

# test multiplication of spin vector
sc = g.vspin([1, 3.3, 4.7, 0.2391])
for mu in g.gamma:
    gamma = g.gamma[mu]
    g.message("Test numpy matrix application to vspin for", mu)
    vec = (gamma * sc).array
Пример #25
0
    for j in range(3):
        eps = abs(A[i, j] - B[1, 2, i, j])
        assert eps < 1e-13

# peek color
ms[:] = msc[:, :, :, :, :, :, 1, 2]

A = ms[0, 1, 0, 1]
B = msc[0, 1, 0, 1]
for i in range(4):
    for j in range(4):
        eps = abs(A[i, j] - B[i, j, 1, 2])
        assert eps < 1e-13

# gamma matrices applied to spin
vsc = g.vspincolor(grid)
vsc[:] = 0
vsc[0, 0, 0, 0] = g.vspincolor([[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0]])
vscA = g.eval(g.gamma[0] * g.gamma[1] * vsc)
vscB = g.eval(g.gamma[0] * g.eval(g.gamma[1] * vsc))
assert g.norm2(vscA - vscB) < 1e-13

# set entire block to tensor
src = g.vspincolor(grid)
zero = g.vspincolor([[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]])
val = g.vspincolor([[1, 1, 1], [1, 1, 1], [0, 0, 0], [0, 0, 0]])
src[:] = 0
src[:, :, :, 0] = val

for x in range(grid.fdimensions[0]):
    for t in range(grid.fdimensions[3]):
Пример #26
0
    "Nk": 60,
    "Nstop": 60,
    "Nm": 80,
    "resid": 1e-8,
    "betastp": 0.0,
    "maxiter": 100,
    "Nminres": 0,
    #    "maxapply" : 100
})

# start vector
path_to_evec = "/hpcgpfs01/scratch/clehner/openQCD/evec"
try:
    evec, ev = g.load(path_to_evec, {"grids": w.F_grid_eo})
except g.LoadError:
    start = g.vspincolor(w.F_grid_eo)
    start[:] = g.vspincolor([[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]])

    # generate eigenvectors
    evec, ev_cheby = irl(
        c(eo(w).NDagN),
        start,
        g.checkpointer("/hpcgpfs01/scratch/clehner/openQCD/checkpoint"),
    )
    ev = g.algorithms.eigen.evals(eo(w).Mpc, evec, check_eps2=1e-8, real=True)

    # save eigenvectors
    g.save(path_to_evec, [evec, ev])

# build solver
inv = g.algorithms.inverter
Пример #27
0
    {
        "kappa": 0.137,
        "csw_r": 0,
        "csw_t": 0,
        "xi_0": 1,
        "nu": 1,
        "isAnisotropic": False,
        "boundary_phases": [1.0, 1.0, 1.0, 1.0],
    },
)

# default grid
grid = U[0].grid

# create source
src = g.vspincolor(grid)
src[:] = g.vspincolor([[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]])

# abbreviations
i = g.algorithms.inverter
mg = i.multi_grid
p = g.qcd.fermion.preconditioner

# NOTE: mg params structure
# - list -> configure each level by itself explicitly (correct lengths asserted inside)
# - scalar value (= not a list) -> broadcast parameter to every level

# mg setups
# mg_setup_2lvl = mg.setup(
#     w,
#     {
Пример #28
0
# norms
for i in range(nbasis):
    g.message("Norm2 of basis[%d] = %g" % (i, g.norm2(fg_basis[i])))

for i in range(nbasis):
    g.message("Norm2 of cevec[%d] = %g" % (i, g.norm2(fg_cevec[i])))

g.mem_report()

# prepare and test basis
basis = []
assert nbasis > 0
b = g.block.map(fg_cevec[0].grid, fg_basis)
for i in range(nbasis):
    basis.append(g.vspincolor(q.F_grid_eo)
                 )  # don't advise yet, let it be first touched on accelerator
    g.message(i)
    if i < params["nbasis_on_host"]:
        g.message("marked as infrequent use")
        # basis[i].advise( g.infrequent_use )

    basis[i] @= b.promote * fg_cevec[i]
    g.algorithms.eigen.evals(q.Mpc, [basis[i]], check_eps2=1e-4, real=True)
    g.message("Compare to: %g" % fg_feval[i])

    g.mem_report(details=False)

# now discard original basis
del fg_basis
del fg_cevec
Пример #29
0
w = g.qcd.fermion.wilson_clover(
    U,
    {
        "mass": qm.params["M5"],
        "csw_r": 0,
        "csw_t": 0,
        "xi_0": 1,
        "nu": 1,
        "isAnisotropic": False,
        "boundary_phases": [1.0, 1.0, 1.0, 1.0],
    },
)

# test operator update
start = g.vspincolor(qm.F_grid)
rng.cnormal(start)
qm_new = g.qcd.fermion.mobius(U, mobius_params)
qm.update(U)
eps2 = g.norm2(qm * start - qm_new * start) / g.norm2(start)
g.message(f"Operator update test: {eps2}")
assert eps2 < 1e-10

# solver
pc = g.qcd.fermion.preconditioner
inv = g.algorithms.inverter
cg = inv.cg({"eps": 1e-4, "maxiter": 1000})


def H5_denom(dst, src):
    dst @= g.gamma[5] * (2 * src + (qm.params["b"] - qm.params["c"]) * w * src)
Пример #30
0
q = params["fmatrix"](U)

# load basis vectors
nbasis = params["nbasis"]
# fg_basis,fg_cevec,fg_feval = g.load(params["basis"],{
#    "grids" : q.F_grid_eo, "nmax" : nbasis,
#    "advise_basis" : g.infrequent_use,
#    "advise_cevec" : g.infrequent_use
# })
rng = g.random("test")

try:
    fg_basis = g.load("basis", {"grids": q.F_grid_eo})[0]
except g.LoadError:
    fg_basis = g.advise(
        [g.vspincolor(q.F_grid_eo) for i in range(nbasis)], g.infrequent_use
    )
    rng.zn(fg_basis)
    g.save("basis", [fg_basis])

# g.mem_report()
# g.prefetch( fg_basis, g.to_accelerator)
# g.mem_report()

# w=fg_basis[-1]
# g.orthogonalize(w,fg_basis[0:1])
# g.orthogonalize(w,fg_basis[0:15])

fg_basis = g.advise(fg_basis, g.infrequent_use)
tg = g.block.grid(q.F_grid_eo, [12, 2, 2, 2, 2])
fg_cevec = g.advise([g.vcomplex(tg, 150) for i in range(nbasis)], g.infrequent_use)