def read_header(self): # make sure this is a file if not os.path.isfile(self.path): return False with open(self.path, "rb") as f: line = self.getline(f) if line != "BEGIN_FIELD_HEADER": return False # need to be mute before this line since this is used to autodetect the file format if self.verbose: gpt.message(f"Qlattice file format; reading {self.path}") gpt.message(f" {line}") for i in range(8): line = self.getline(f) if self.verbose: gpt.message(f"\t{line}") [field, val] = line.split(" = ") if field == "field_version": self.version = val assert val == "1.0" elif field[:10] == "total_site": self.fdimensions.append(int(val)) elif field == "multiplicity": if int(val) == 288: self.otype = gpt.ot_matrix_spin_color(4, 3) self.size *= int(val) elif field == "sizeof(M)": if int(val) == 4: self.precision = gpt.single elif int(val) == 8: self.precision = gpt.double self.size *= int(val) elif field == "field_crc32": self.crc_exp = val line = self.getline(f) if self.verbose: gpt.message(f" {line}") assert line == "END_HEADER" self.bytes_header = f.tell() self.cv_desc = "[" + ",".join(["1"] * len(self.fdimensions)) + "]" self.ldimensions = [fd for fd in self.fdimensions] return True
def p2p_ubaru(src, Pol_i, Spin_M, t_sink): I = g.ot_matrix_spin_color(4, 3).identity() tmp_seq_src = g.lattice(src) q1_tmp = g.eval(src * Spin_M) # e.g. D * Cg5 q2_tmp = g.eval(Spin_M * src) # e.g. Cg5 * D di_quark = qC.quarkContract24(q1_tmp, q2_tmp) tmp_seq_src = g.eval(Pol_i * di_quark) tmp_seq_src += g.eval(g.spin_trace(di_quark) * I * Pol_i) q1_tmp = g.eval(q2_tmp * Spin_M) # e.g. Cg5 * D * Cg5 q2_tmp = g.eval(src * Pol_i) # e.g. D * Pol_i tmp_seq_src -= qC.quarkContract13(q1_tmp, q2_tmp) tmp_seq_src -= g.spin_transpose(qC.quarkContract12(q2_tmp, q1_tmp)) tmp_seq_src @= g.eval(g.gamma[5] * g.adj(tmp_seq_src) * g.gamma[5]) seq_src = g.lattice(src) seq_src[:] = 0 seq_src[:, :, :, t_sink] = tmp_seq_src[:, :, :, t_sink] return seq_src
def p2n_dbaru(src, Pol_i, Spin_M, t_sink): I = g.ot_matrix_spin_color(4, 3).identity() tmp_seq_src = g.lattice(src) q1_tmp = g.eval(src * Spin_M) # e.g. D * Cg5 q2_tmp = g.eval(Spin_M * src) # e.g. Cg5 * D di_quark = qC.quarkContract24(q1_tmp, q2_tmp) tmp_seq_src = qC.quarkContract14(g.eval(Pol_i * q1_tmp), q2_tmp) tmp_seq_src += g.eval(Pol_i * di_quark) tmp_seq_src += g.eval(g.spin_trace(di_quark) * I * Pol_i) q1_tmp = q2_tmp * Spin_M # e.g. (Cg5 * D) * Cg5 q2_tmp = src * Pol_i # e.g. D * Pol_i tmp_seq_src -= qC.quarkContract13(q1_tmp, q2_tmp) seq_src = g.lattice(src) seq_src[:] = 0 seq_src[:, :, :, t_sink] = tmp_seq_src[:, :, :, t_sink] return seq_src
# at this point only make sure that it # produces a string without failing g.message( f"Test string conversion of expression:\n{g.trace(0.5 * msc * msc - msc)}") # left and right multiplication of different data types with scalar mc = g.mcomplex(grid, ntest) for dti in [cv, cm, vsc, msc, vc, mc]: rng.cnormal(dti) eps = g.norm2(mask * dti - dti * mask) g.message(f"Done with {dti.otype.__name__}") assert eps == 0.0 # test numpy versus lattice tensor multiplication for a_type in [ g.ot_matrix_spin_color(4, 3), g.ot_vector_spin_color(4, 3), g.ot_matrix_spin(4), g.ot_vector_spin(4), g.ot_matrix_color(3), g.ot_vector_color(3), ]: # mtab for e in a_type.mtab: if a_type.mtab[e][1] is not None: b_type = g.str_to_otype(e) a = rng.cnormal(g.lattice(grid, a_type)) b = rng.cnormal(g.lattice(grid, b_type)) mul_lat = g(a * b)[0, 0, 0, 0] mul_np = a[0, 0, 0, 0] * b[0, 0, 0, 0] eps2 = g.norm2(mul_lat - mul_np) / g.norm2(mul_lat)
] for m, di_quark in enumerate(contraction_routines): correlator = g.slice(g.trace(di_quark * g.adj(di_quark)), 3) for t, c in enumerate(correlator): correlators[n, m, l, t] = c.real # test gauge covariance for k in range(len(contraction_routines)): for t in range(Nt): assert (correlators[0, k, l, t] - correlators[1, k, l, t] < 1e-12) # test spin structure for n in range(4): I = g.ot_matrix_spin_color(4, 3).identity() if (n == 0): di_quark1 = qC.quark_contract_12(dst, dst) di_quark2 = qC.quark_contract_12(dst, g.eval(I * g.spin_trace(dst))) correlator1 = g.slice(g.trace(di_quark1), 3) correlator2 = g.slice(g.color_trace(di_quark2), 3) for t in range(Nt): assert (correlator1[t] - correlator2[t][0, 0]) < 1e-13 if (n == 1): di_quark1 = qC.quark_contract_34(dst, dst) di_quark2 = qC.quark_contract_34(g.eval(I * g.spin_trace(dst)), dst) correlator1 = g.slice(g.trace(di_quark1), 3)