def perform(self, root): global basis_size, 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) c = None vcj = [ g.vcolor(current_config.l_exact.U_grid) for jr in range(basis_size) ] for vcjj in vcj: vcjj[:] = 0 for tprime in range(T): basis_evec, basis_evals = g.load(self.basis_fmt % (self.conf, tprime)) plan = g.copy_plan(vcj[0], basis_evec[0], embed_in_communicator=vcj[0].grid) c = g.coordinates(basis_evec[0]) plan.destination += vcj[0].view[np.hstack( (c, np.ones((len(c), 1), dtype=np.int32) * tprime))] plan.source += basis_evec[0].view[c] plan = plan() for l in range(basis_size): plan(vcj[l], basis_evec[l]) for l in range(basis_size): g.message("Check norm:", l, g.norm2(vcj[l])) g.save(f"{root}/{self.name}/basis", vcj)
#!/usr/bin/env python3 # # Authors: Christoph Lehner 2020 # # Desc.: Illustrate core concepts and features # import gpt as g import numpy as np grid = g.grid([8, 8, 8, 8], g.single) g.default.push_verbose("random", False) rng = g.random("test") g.default.pop_verbose() # outer product and inner product of tensors lhs = g.vcolor([rng.cnormal() for i in range(3)]) rhs = g.vcolor([rng.cnormal() for i in range(3)]) outer = lhs * g.adj(rhs) inner = g.adj(lhs) * rhs inner_comp = 0.0 for i in range(3): inner_comp += lhs.array.conjugate()[i] * rhs.array[i] for j in range(3): assert abs(outer.array[i, j] - lhs.array[i] * rhs.array.conjugate()[j]) < 1e-14 assert abs(inner_comp - inner) < 1e-14 assert abs(inner_comp - g.rank_inner_product(lhs, rhs)) < 1e-14 # TODO: the following is already implemented for vcomplex but should # be implemented for all vectors
src = g.mspincolor(grid) rng.cnormal(src) dst1 = g(V * smear * src) dst2 = g(smear_transformed * V * src) eps2 = g.norm2(dst1 - dst2) / g.norm2(dst1) g.message(f"Covariance test: {eps2}") assert eps2 < 1e-29 # Test smearing operator on point source over unit gauge field for dimensions in [[0, 1, 2], [0, 1, 2, 3]]: for sigma, steps in [(0.5, 3), (0.16, 2)]: smear_unit = g.create.smear.gauss(U_unit, sigma=sigma, steps=steps, dimensions=dimensions) src = g.vcolor(grid) src[:] = g.vcolor([1, 0, 0]) # anti-periodic boundary conditions in time mean space and time are # differently quantized p = 2.0 * np.pi * np.array([1, 2, 3, 4.5]) / L src_mom = g(g.exp_ixp(p) * src) laplace = sum([2.0 * (np.cos(p[i]) - 1.0) for i in dimensions]) factor = (1.0 + laplace * sigma**2.0 / steps / 4.0)**steps dst = g(smear_unit * src_mom) eps2 = g.norm2(dst - factor * src_mom) / g.norm2(dst) g.message(f"Gaussian test using eigen representation: {eps2}") assert eps2 < 1e-29
gre[2, 0, 0, 0] = 4 g.set_cb(gr, gre) g.meminfo() print(gre) 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]])
# Authors: Christoph Lehner 2020 # # Desc.: Test small core features that are not sufficiently complex # to require a separate test file. These tests need to be fast. # import gpt as g import numpy as np import sys, cgpt # grid L = [16, 16, 16, 32] grid_dp = g.grid(L, g.double) grid_sp = g.grid(L, g.single) # test fields l_dp = g.random("test").cnormal(g.vcolor(grid_dp)) l_sp = g.convert(l_dp, g.single) ################################################################################ # Test mview ################################################################################ c = g.coordinates(l_dp) x = l_dp[c] mv = g.mview(x) assert mv.itemsize == 1 and mv.shape[0] == len(mv) assert sys.getrefcount(x) == 3 del mv assert sys.getrefcount(x) == 2 ################################################################################ # Test assignments
# # Desc.: Test small core features that are not sufficiently complex # to require a separate test file. These tests need to be fast. # import gpt as g import numpy as np import sys, cgpt # grid L = [16, 12, 12, 24] grid_dp = g.grid(L, g.double) grid_sp = g.grid(L, g.single) # test fields rng = g.random("test") l_dp = rng.cnormal(g.vcolor(grid_dp)) l_sp = g.convert(l_dp, g.single) # and convert precision l_dp_prime = g.convert(l_sp, g.double) eps2 = g.norm2(l_dp - l_dp_prime) / g.norm2(l_dp) assert eps2 < 1e-14 eps2 = g.norm2(l_dp[0, 0, 0, 0] - l_sp[0, 0, 0, 0]) assert eps2 < 1e-14 ################################################################################ # Test mview ################################################################################ c = g.coordinates(l_dp) x = l_dp[c]
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") vcj = g.load(f"{root}/{self.conf}/pm_basis/basis") for i0 in range(0, basis_size, sloppy_per_job): half_peramb = {} for l in g.load( f"{root}/{self.conf}/pm_{self.solver}_t{self.t}_i{i0}/propagators" ): for x in l: half_peramb[x] = l[x] g.mem_report(details=False) vc = g.vcolor(vcj[0].grid) c = g.coordinates(vc) prec = {"sloppy": 0, "exact": 1}[self.solver] for spin_prime in range(4): plan = None for spin in range(4): for i in range(i0, i0 + sloppy_per_job): hp = half_peramb[f"t{self.t}s{spin}c{i}_{self.solver}"] if plan is None: plan = g.copy_plan(vc, hp) plan.destination += vc.view[c] plan.source += hp.view[c, spin_prime, :] plan = plan() plan(vc, hp) t0 = g.time() slc_j = [ g(g.adj(vcj[j]) * vc) for j in range(basis_size) ] t1 = g.time() slc = g.slice(slc_j, 3) t2 = g.time() for j in range(basis_size): output_correlator.write( f"output/peramb_prec{prec}/n_{j}_{i}_s_{spin_prime}_{spin}_t_{self.t}", slc[j], ) t3 = g.time() if i % 50 == 0: g.message(spin_prime, spin, i, "Timing", t1 - t0, t2 - t1, t3 - t2) output_correlator.close()
g.message(f"Laplace basis for time-slice {t}") U3_t = [u[t] for u in U3] grid = U3_t[0].grid lap = g.create.smear.laplace( g.covariant.shift(U3_t, boundary_phases=[1.0, 1.0, 1.0, -1.0]), dimensions=[0, 1, 2], ) def _slap(dst, src): dst @= -1.0 / 6.0 * lap * src slap = g.matrix_operator(_slap) start = g.vcolor(grid) start[:] = g.vcolor([1, 1, 1]) if t == 0: g.message( "Power iteration spectrum test", g.algorithms.eigen.power_iteration(eps=1e-7, maxiter=200)(slap, start), ) evec, ev = irl(c(slap), start) evals, eps2 = g.algorithms.eigen.evals(slap, evec) assert all([e2 < 0.1 for e2 in eps2]) g.save(f"{destination}/basis_t{t}", [evec, evals])
#!/usr/bin/env python3 # # Authors: Christoph Lehner 2020 # # Desc.: Illustrate core concepts and features # import gpt as g import numpy as np grid = g.grid([2, 2, 2, 2], g.single) cm = g.mcolor(grid) cv = g.vcolor(grid) cv[:] = 0 cv[0, 0, 0, 0, 0] = 1 cv[0, 0, 0, 0, 1] = 2 cm @= cv * g.adj(cv) g.message(cm) res = g.eval(cv * g.adj(cv) * cm * cv) g.message(res) sc = g.vspincolor(grid) sc[:] = 0 sc[0, 0, 0, 0] = g.vspincolor([[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0]]) scA = g.eval(g.gamma[0] * g.gamma[1] * sc) scB = g.eval(g.gamma[0] * g.eval(g.gamma[1] * sc))
#!/usr/bin/env python3 # # Authors: Christoph Lehner 2020 # # Desc.: Illustrate core concepts and features # import gpt as g import numpy as np import sys # grid grid = g.grid([2, 2, 2, 2], g.single) # test different lattice types vc = g.vcolor(grid) g.message(vc) vz30 = g.vcomplex(grid, 30) g.message(vz30) vz30c = g.lattice(grid, vz30.describe()) vz30c[:] = g.vcomplex([1] * 15 + [0.5] * 15, 30) g.message(vz30c) vz30b = g.lattice(vz30c) vz30b[:] = g.vcomplex([0.5] * 5 + [1.0] * 20 + [0.2] * 5, 30) g.message(g.eval(vz30c + 0.3 * vz30b)) # perform a barrier grid.barrier()
]: g.message( f"Iteration {it}, group_policy = {group_policy.__name__}") src_unsplit = [g.lattice(x) for x in src] t0 = g.time() src_split = g.split(src, split_grid, None if it == 0 else cache, group_policy) t1 = g.time() g.unsplit(src_unsplit, src_split, None if it == 0 else cache, group_policy) t2 = g.time() g.message(f"Timing: {t1-t0}s for split and {t2-t1}s for unsplit") for i in range(len(src)): eps2 = g.norm2(src_unsplit[i] - src[i]) / g.norm2(src[i]) g.message(f"Split test {i} / {len(src)}: {eps2}") assert eps2 == 0.0 ################################################################################ # Test scale per coordinate ################################################################################ grid_rb = g.grid([12, 8, 8, 8, 8], g.double, g.redblack) a = rng.cnormal(g.vcolor(grid_rb)) b = g.lattice(a) sc = np.array([rng.cnormal() for i in range(12)], np.complex128) g.scale_per_coordinate(b, a, sc, 0) a_s = g.separate(a, 0) b_s = g.separate(b, 0) for i in range(len(a_s)): eps2 = g.norm2(sc[i] * a_s[i] - b_s[i]) / g.norm2(b_s[i]) assert eps2 < 1e-28