CHROMA
inline_create_colorvecs.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Construct colorvectors via power iteration of the laplacian
3  */
4 
5 #include "fermact.h"
11 #include "meas/smear/gaus_smear.h"
12 #include "meas/glue/mesplq.h"
15 #include "util/ft/sftmom.h"
16 #include "util/info/proginfo.h"
18 
20 
21 namespace Chroma
22 {
23  namespace InlineCreateColorVecsEnv
24  {
25  //! Propagator input
26  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
27  {
28  XMLReader inputtop(xml, path);
29 
30  read(inputtop, "gauge_id", input.gauge_id);
31  read(inputtop, "colorvec_id", input.colorvec_id);
32 
33  // User Specified MapObject tags
34  input.colorvec_obj = readXMLGroup(inputtop, "ColorVecMapObject", "MapObjType");
35  }
36 
37  //! Propagator output
38  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
39  {
40  push(xml, path);
41 
42  write(xml, "gauge_id", input.gauge_id);
43  write(xml, "colorvec_id", input.colorvec_id);
44  xml << input.colorvec_obj.xml;
45 
46  pop(xml);
47  }
48 
49  //! Propagator input
50  void read(XMLReader& xml, const std::string& path, Params::Param_t& input)
51  {
52  XMLReader inputtop(xml, path);
53 
54  read(inputtop, "num_vecs", input.num_vecs);
55  read(inputtop, "decay_dir", input.decay_dir);
56  read(inputtop, "num_iter", input.num_iter);
57  read(inputtop, "num_orthog", input.num_orthog);
58  read(inputtop, "width", input.width);
59  input.link_smear = readXMLGroup(inputtop, "LinkSmearing", "LinkSmearingType");
60  }
61 
62  //! Propagator output
63  void write(XMLWriter& xml, const std::string& path, const Params::Param_t& out)
64  {
65  push(xml, path);
66 
67  write(xml, "num_vecs", out.num_vecs);
68  write(xml, "decay_dir", out.decay_dir);
69  write(xml, "num_iter", out.num_iter);
70  write(xml, "num_orthog", out.num_orthog);
71  write(xml, "width", out.width);
72  xml << out.link_smear.xml;
73 
74  pop(xml);
75  }
76 
77 
78  //! Propagator input
79  void read(XMLReader& xml, const std::string& path, Params& input)
80  {
81  Params tmp(xml, path);
82  input = tmp;
83  }
84 
85  //! Propagator output
86  void write(XMLWriter& xml, const std::string& path, const Params& input)
87  {
88  push(xml, path);
89 
90  write(xml, "Param", input.param);
91  write(xml, "NamedObject", input.named_obj);
92 
93  pop(xml);
94  }
95  } // namespace InlineCreateColorVecsEnv
96 
97 
98  namespace InlineCreateColorVecsEnv
99  {
100  namespace
101  {
102  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
103  const std::string& path)
104  {
105  return new InlineMeas(Params(xml_in, path));
106  }
107 
108  //! Local registration flag
109  bool registered = false;
110  }
111 
112  const std::string name = "CREATE_COLORVECS";
113 
114  //! Register all the factories
115  bool registerAll()
116  {
117  bool success = true;
118  if (! registered)
119  {
120  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
122  registered = true;
123  }
124  return success;
125  }
126 
127 
128  //-------------------------------------------------------------------------
129  // Param stuff
131 
132  Params::Params(XMLReader& xml_in, const std::string& path)
133  {
134  try
135  {
136  XMLReader paramtop(xml_in, path);
137 
138  if (paramtop.count("Frequency") == 1)
139  read(paramtop, "Frequency", frequency);
140  else
141  frequency = 1;
142 
143  // Parameters for source construction
144  read(paramtop, "Param", param);
145 
146  // Read in the output propagator/source configuration info
147  read(paramtop, "NamedObject", named_obj);
148 
149  // Possible alternate XML file pattern
150  if (paramtop.count("xml_file") != 0)
151  {
152  read(paramtop, "xml_file", xml_file);
153  }
154  }
155  catch(const std::string& e)
156  {
157  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
158  QDP_abort(1);
159  }
160  }
161 
162 
163 
164  // Function call
165  void
166  InlineMeas::operator()(unsigned long update_no,
167  XMLWriter& xml_out)
168  {
169  // If xml file not empty, then use alternate
170  if (params.xml_file != "")
171  {
172  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
173 
174  push(xml_out, "CreateColorVecs");
175  write(xml_out, "update_no", update_no);
176  write(xml_out, "xml_file", xml_file);
177  pop(xml_out);
178 
179  XMLFileWriter xml(xml_file);
180  func(update_no, xml);
181  }
182  else
183  {
184  func(update_no, xml_out);
185  }
186  }
187 
188 
189  // Real work done here
190  void
191  InlineMeas::func(unsigned long update_no,
192  XMLWriter& xml_out)
193  {
194  START_CODE();
195 
196  StopWatch snoop;
197  snoop.reset();
198  snoop.start();
199 
200  // Test and grab a reference to the gauge field
201  multi1d<LatticeColorMatrix> u;
202  XMLBufferWriter gauge_xml;
203  try
204  {
205  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
206  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
207  }
208  catch( std::bad_cast )
209  {
210  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
211  QDP_abort(1);
212  }
213  catch (const std::string& e)
214  {
215  QDPIO::cerr << name << ": std::map call failed: " << e << std::endl;
216  QDP_abort(1);
217  }
218 
219  push(xml_out, "CreateColorVecs");
220  write(xml_out, "update_no", update_no);
221 
222  QDPIO::cout << name << ": Create color vectors" << std::endl;
223 
224  proginfo(xml_out); // Print out basic program info
225 
226  // Write out the input
227  write(xml_out, "Input", params);
228 
229  // Write out the config header
230  write(xml_out, "Config_info", gauge_xml);
231 
232  push(xml_out, "Output_version");
233  write(xml_out, "out_version", 1);
234  pop(xml_out);
235 
236  // Calculate some gauge invariant observables just for info.
237  MesPlq(xml_out, "Observables", u);
238 
239  //
240  // Smear the gauge field if needed
241  //
242  multi1d<LatticeColorMatrix> u_smr = u;
243 
244  try
245  {
246  std::istringstream xml_l(params.param.link_smear.xml);
247  XMLReader linktop(xml_l);
248  QDPIO::cout << "Link smearing type = "
250  << std::endl;
251 
253  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.param.link_smear.id,
254  linktop,params.param.link_smear.path));
255  (*linkSmearing)(u_smr);
256  }
257  catch(const std::string& e){
258  QDPIO::cerr << name << ": Caught Exception link smearing: "<<e<< std::endl;
259  QDP_abort(1);
260  }
261 
262  // Record the smeared observables
263  MesPlq(xml_out, "Smeared_Observables", u_smr);
264 
265 
266  //
267  // Create the output files
268  //
269  try
270  {
271  // Generate a metadata
272  std::string file_str;
273  if (1)
274  {
275  XMLBufferWriter file_xml;
276 
277  push(file_xml, "MODMetaData");
278  write(file_xml, "id", std::string("eigenColorVec"));
279  write(file_xml, "lattSize", QDP::Layout::lattSize());
280  write(file_xml, "num_vecs", params.param.num_vecs);
281  write(file_xml, "Config_info", gauge_xml);
282  pop(file_xml);
283 
284  file_str = file_xml.str();
285  }
286 
287  std::istringstream xml_s(params.named_obj.colorvec_obj.xml);
288  XMLReader MapObjReader(xml_s);
289 
290  // Create the entry
294  MapObjReader,
296  file_str);
297  }
298  catch (std::bad_cast)
299  {
300  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
301  QDP_abort(1);
302  }
303  catch (const std::string& e)
304  {
305  QDPIO::cerr << name << ": error creating prop: " << e << std::endl;
306  QDP_abort(1);
307  }
308 
309  // Cast should be valid now
310  MapObject<int,EVPair<LatticeColorVector> >& color_vecs =
312 
313  // The code goes here
314  StopWatch swatch;
315  swatch.reset();
316  swatch.start();
317 
318  /**
319  *Loop for num_iter
320  * apply smearing
321  * if orthonormalize is true to a GramSchmit on them
322  * Compute the v'Smearing v matrix elements for all color vectors
323  * call them evals and monitor convergence on one time slice
324  *EndLoop
325 
326  **/
327 
328  // Initialize the slow Fourier transform phases
329  SftMom phases(0, true, params.param.decay_dir);
330 
331  const int num_vecs = params.param.num_vecs;
332 
333 
334  // color_vecs.resizeEvectors(num_vecs);
335  multi1d<SubsetVectorWeight_t> evals(num_vecs);
336  // Temporary
337  multi1d<LatticeColorVector> evecs(num_vecs);
338 
339 
340  QDPIO::cout << "Got here" << std::endl;
341  for(int i(0);i<num_vecs;i++){
342  evals[i].weights.resize(phases.numSubsets());
343  }
344 
345  //
346  // Initialize the color vectors with gaussian numbers
347  // Gaussian smear in an orthogonalization loop
348  //
349  for(int hit=0; hit <= params.param.num_orthog; ++hit)
350  {
351  for(int i=0; i < num_vecs; ++i)
352  {
353  QDPIO::cout << name << ": Doing colorvec: "<<i << " hit no: "<<hit<<std::endl;
354  if (hit == 0) {
355  gaussian(evecs[i]);
356  }
357  else {
358  gausSmear(u_smr,
359  evecs[i],
361  }
362 
363  for(int k=0; k < i; ++k) {
364  multi1d<DComplex> cc =
365  sumMulti(localInnerProduct(evecs[k],
366  evecs[i]),
367  phases.getSet());
368 
369  for(int t(0);t<phases.numSubsets();t++) {
370  evecs[i][phases.getSet()[t]] -= cc[t]*evecs[k];
371  }
372 
373  }
374 
375  multi1d<Double> norm2 = sumMulti(localNorm2(evecs[i]),phases.getSet());
376 
377  for(int t=0; t < phases.numSubsets(); ++t) {
378  evecs[i][phases.getSet()[t]] /= sqrt(norm2[t]);
379  }
380 
381  }
382  }
383 
384 
385  //
386  // Compute the version of eigenvalues (which they are not)
387  //
388  {
389  multi1d< multi1d<Double> > source_corrs(evecs.size());
390  for(int m=0; m < source_corrs.size(); ++m)
391  source_corrs[m] = sumMulti(localNorm2(evecs[m]), phases.getSet());
392  push(xml_out, "Source_correlators");
393  write(xml_out, "source_corrs", source_corrs);
394  pop(xml_out);
395  //compute the "eigenvalues"
396  push(xml_out,"SmearingEvals");
397 
398 
399  for(int i=0; i < num_vecs; ++i) {
400  LatticeColorVector Svec;
401  klein_gord(u_smr, evecs[i], Svec, Real(0), params.param.decay_dir);
402 
403  multi1d<DComplex> cc =
404  sumMulti(localInnerProduct(evecs[i],
405  Svec),
406  phases.getSet());
407 
408  for(int t=0; t < phases.numSubsets(); ++t) {
409  evals[i].weights[t] = real(cc[t]);
410  }
411 
412  push(xml_out,"Vector");
413  write(xml_out, "VecNo",i);
414  write(xml_out, "Evals", evals[i].weights);
415  pop(xml_out);
416  }
417  pop(xml_out);
418  }
419 
420 
421  for(int i=0; i < num_vecs; i++) {
423  pair.eigenValue=evals[i];
424  pair.eigenVector=evecs[i];
425  color_vecs.insert(i, pair);
426  }
427 
428  swatch.stop();
429  QDPIO::cout << name << ": time for colorvec construction = "
430  << swatch.getTimeInSeconds()
431  << " secs" << std::endl;
432 
433  pop(xml_out); // CreateColorVecs
434 
435  /**/
436  // Write the meta-data for this operator
437  {
438  XMLBufferWriter file_xml;
439 
440  push(file_xml, "LaplaceEigInfo");
441  write(file_xml, "num_vecs", num_vecs);
442  write(file_xml, "Params", params.param);
443  write(file_xml, "Config_info", gauge_xml);
444  pop(file_xml);
445 
446  XMLBufferWriter record_xml;
447  push(record_xml, "SubsetVectors");
448  for(int i(0);i<num_vecs;i++){
449  push(record_xml, "EigenPair");
450  write(record_xml, "EigenPairNumber", i);
451  write(record_xml, "EigenValues", evals[i].weights);
452  pop(record_xml);
453  }
454  pop(record_xml);
455 
456  // Write the propagator xml info
457  TheNamedObjMap::Instance().get(params.named_obj.colorvec_id).setFileXML(file_xml);
458  TheNamedObjMap::Instance().get(params.named_obj.colorvec_id).setRecordXML(record_xml);
459  }
460  /**/
461 
462  snoop.stop();
463  QDPIO::cout << name << ": total time = "
464  << snoop.getTimeInSeconds()
465  << " secs" << std::endl;
466 
467  QDPIO::cout << name << ": ran successfully" << std::endl;
468 
469  END_CODE();
470  }
471 
472  }
473 
474 } // namespace Chroma
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
Fourier transform phase factor support.
Definition: sftmom.h:35
int numSubsets() const
Number of subsets - length in decay direction.
Definition: sftmom.h:63
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
static T & Instance()
Definition: singleton.h:432
Class structure for fermion actions.
Gaussian smearing of color std::vector.
void klein_gord(const multi1d< LatticeColorMatrix > &u, const T &psi, T &chi, const Real &mass_sq, int j_decay)
Compute the covariant Klein-Gordon operator.
Definition: klein_gord.cc:31
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
std::string makeXMLFileName(std::string xml_file, unsigned long update_no)
Return a xml file name for inline measurements.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
void gausSmear(const multi1d< LatticeColorMatrix > &u, T &chi, const Real &width, int ItrGaus, int j_decay)
Do a covariant Gaussian smearing of a lattice field.
Definition: gaus_smear.cc:24
Construct colorvectors via power iteration of the laplacian.
Klein-Gordon operator.
static int m[4]
Definition: make_seeds.cc:16
Make xml file writer.
int t
Definition: meslate.cc:37
Named object function std::map.
static bool registered
Local registration flag.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Propagator output.
bool registerAll()
Register all the factories.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Propagator input.
QDPSubTypeTrait< typename BinaryReturn< C1, C2, FnLocalInnerProduct >::Type_t >::Type_t localInnerProduct(const QDPSubType< T1, C1 > &l, const QDPType< T2, C2 > &r)
bool registerAll()
aggregate everything
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
static QDP_ColorVector * out
Constructor.
START_CODE()
int k
Definition: invbicg.cc:119
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.
Fourier transform phase factor support.
A Pair type.
SubsetVectorWeight_t eigenValue