# test creating spinor projections as expession templates P = g.gamma[0] * g.gamma[1] - g.gamma[2] * g.gamma[3] dst @= P * l ref @= g.gamma[0] * g.gamma[1] * l - g.gamma[2] * g.gamma[3] * l eps = g.norm2(dst - ref) / g.norm2(l) g.message("Test Regular Expression: ", eps) assert eps == 0.0 # 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, 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
lambda a, b: g.trace(a * b), lambda a, b: g.trace(b * a), ]: dst_alg = g(op(g.gamma[mu], l)) dst_mat = g(op(g.gamma[mu].tensor(), l)) eps2 = g.norm2(dst_alg - dst_mat) / g.norm2(dst_mat) 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
for i in range(4): while x[i] < -L[i] / 2: x[i] += L[i] ref = np.exp(1j * np.dot(p_arbitrary, x)) * l_dp[xc] val = g.eval(exp_ixp_rel * l_dp)[xc] eps = g.norm2(ref - val) g.message("Reference value test (arbitrary momentum with origin): ", eps) assert eps < 1e-25 ################################################################################ # Test slice sums ################################################################################ for lattice_object in [ g.complex(grid_dp), g.vcomplex(grid_dp, 10), g.vspin(grid_dp), g.vcolor(grid_dp), g.vspincolor(grid_dp), g.mspin(grid_dp), g.mcolor(grid_dp), g.mspincolor(grid_dp), ]: g.message(f"Testing slice with random {lattice_object.describe()}") obj_list = [g.copy(lattice_object) for _ in range(3)] rng.cnormal(obj_list) for dimension in range(4): tmp = g.slice(obj_list, dimension) full_sliced = np.array([[g.util.tensor_to_value(v) for v in obj] for obj in tmp])