CHROMA
inline_prop_colorvec_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Compute the matrix element of M^-1 * multi1d<LatticeColorVector>
3  *
4  * Propagator calculation on a colorstd::vector
5  */
6 
7 #include "fermact.h"
10 #include "meas/glue/mesplq.h"
15 #include "util/ferm/transf.h"
16 #include "util/ft/sftmom.h"
17 #include "util/info/proginfo.h"
21 
23 
24 namespace Chroma
25 {
26  namespace InlinePropColorVecEnv
27  {
28  //! Propagator input
29  void read(XMLReader& xml, const std::string& path, InlinePropColorVecEnv::Params::NamedObject_t& input)
30  {
31  XMLReader inputtop(xml, path);
32 
33  read(inputtop, "gauge_id", input.gauge_id);
34  read(inputtop, "colorvec_id", input.colorvec_id);
35  read(inputtop, "prop_id", input.prop_id);
36 
37  // User Specified MapObject tags
38  input.prop_obj = readXMLGroup(inputtop, "PropMapObject", "MapObjType");
39  }
40 
41  //! Propagator output
42  void write(XMLWriter& xml, const std::string& path, const InlinePropColorVecEnv::Params::NamedObject_t& input)
43  {
44  push(xml, path);
45 
46  write(xml, "gauge_id", input.gauge_id);
47  write(xml, "colorvec_id", input.colorvec_id);
48  write(xml, "prop_id", input.prop_id);
49  xml << input.prop_obj.xml;
50 
51  pop(xml);
52  }
53 
54 
55  //! Propagator input
56  void read(XMLReader& xml, const std::string& path, InlinePropColorVecEnv::Params::Param_t::Contract_t& input)
57  {
58  XMLReader inputtop(xml, path);
59 
60  read(inputtop, "num_vecs", input.num_vecs);
61  read(inputtop, "t_sources", input.t_sources);
62  read(inputtop, "decay_dir", input.decay_dir);
63  }
64 
65  //! Propagator output
66  void write(XMLWriter& xml, const std::string& path, const InlinePropColorVecEnv::Params::Param_t::Contract_t& input)
67  {
68  push(xml, path);
69 
70  write(xml, "num_vecs", input.num_vecs);
71  write(xml, "t_sources", input.t_sources);
72  write(xml, "decay_dir", input.decay_dir);
73 
74  pop(xml);
75  }
76 
77 
78  //! Propagator input
79  void read(XMLReader& xml, const std::string& path, InlinePropColorVecEnv::Params::Param_t& input)
80  {
81  XMLReader inputtop(xml, path);
82 
83  read(inputtop, "Propagator", input.prop);
84  read(inputtop, "Contractions", input.contract);
85  }
86 
87  //! Propagator output
88  void write(XMLWriter& xml, const std::string& path, const InlinePropColorVecEnv::Params::Param_t& input)
89  {
90  push(xml, path);
91 
92  write(xml, "Propagator", input.prop);
93  write(xml, "Contractions", input.contract);
94 
95  pop(xml);
96  }
97 
98 
99  //! Propagator input
100  void read(XMLReader& xml, const std::string& path, InlinePropColorVecEnv::Params& input)
101  {
103  input = tmp;
104  }
105 
106  //! Propagator output
107  void write(XMLWriter& xml, const std::string& path, const InlinePropColorVecEnv::Params& input)
108  {
109  push(xml, path);
110 
111  write(xml, "Param", input.param);
112  write(xml, "NamedObject", input.named_obj);
113 
114  pop(xml);
115  }
116  } // namespace InlinePropColorVecEnv
117 
118 
119  namespace InlinePropColorVecEnv
120  {
121  namespace
122  {
123  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
124  const std::string& path)
125  {
126  return new InlineMeas(Params(xml_in, path));
127  }
128 
129  //! Local registration flag
130  bool registered = false;
131  }
132 
133  const std::string name = "PROP_COLORVEC";
134 
135  //! Register all the factories
136  bool registerAll()
137  {
138  bool success = true;
139  if (! registered)
140  {
142  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
144  registered = true;
145  }
146  return success;
147  }
148 
149 
150  //----------------------------------------------------------------------------
151  // Param stuff
153 
154  Params::Params(XMLReader& xml_in, const std::string& path)
155  {
156  try
157  {
158  XMLReader paramtop(xml_in, path);
159 
160  if (paramtop.count("Frequency") == 1)
161  read(paramtop, "Frequency", frequency);
162  else
163  frequency = 1;
164 
165  // Parameters for source construction
166  read(paramtop, "Param", param);
167 
168  // Read in the output propagator/source configuration info
169  read(paramtop, "NamedObject", named_obj);
170 
171  // Possible alternate XML file pattern
172  if (paramtop.count("xml_file") != 0)
173  {
174  read(paramtop, "xml_file", xml_file);
175  }
176  }
177  catch(const std::string& e)
178  {
179  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
180  QDP_abort(1);
181  }
182  }
183 
184 
185 
186  // Function call
187  void
188  InlineMeas::operator()(unsigned long update_no,
189  XMLWriter& xml_out)
190  {
191  // If xml file not empty, then use alternate
192  if (params.xml_file != "")
193  {
194  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
195 
196  push(xml_out, "PropColorVec");
197  write(xml_out, "update_no", update_no);
198  write(xml_out, "xml_file", xml_file);
199  pop(xml_out);
200 
201  XMLFileWriter xml(xml_file);
202  func(update_no, xml);
203  }
204  else
205  {
206  func(update_no, xml_out);
207  }
208  }
209 
210 
211  // Real work done here
212  void
213  InlineMeas::func(unsigned long update_no,
214  XMLWriter& xml_out)
215  {
216  START_CODE();
217 
218  StopWatch snoop;
219  snoop.reset();
220  snoop.start();
221 
222  // Test and grab a reference to the gauge field
223  multi1d<LatticeColorMatrix> u;
224  XMLBufferWriter gauge_xml;
225  try
226  {
227  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
228  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
229  }
230  catch( std::bad_cast )
231  {
232  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
233  QDP_abort(1);
234  }
235  catch (const std::string& e)
236  {
237  QDPIO::cerr << name << ": std::map call failed: " << e << std::endl;
238  QDP_abort(1);
239  }
240 
241  push(xml_out, "PropColorVec");
242  write(xml_out, "update_no", update_no);
243 
244  QDPIO::cout << name << ": propagator calculation" << std::endl;
245 
246  proginfo(xml_out); // Print out basic program info
247 
248  // Write out the input
249  write(xml_out, "Input", params);
250 
251  // Write out the config header
252  write(xml_out, "Config_info", gauge_xml);
253 
254  push(xml_out, "Output_version");
255  write(xml_out, "out_version", 1);
256  pop(xml_out);
257 
258  // Calculate some gauge invariant observables just for info.
259  MesPlq(xml_out, "Observables", u);
260 
261  //
262  // Read in the source along with relevant information.
263  //
264  XMLReader source_file_xml, source_record_xml;
265 
266  QDPIO::cout << "Snarf the source from a named buffer" << std::endl;
267  try
268  {
270 
271  // Snarf the source info. This is will throw if the colorvec_id is not there
272 
273  TheNamedObjMap::Instance().get(params.named_obj.colorvec_id).getFileXML(source_file_xml);
274  TheNamedObjMap::Instance().get(params.named_obj.colorvec_id).getRecordXML(source_record_xml);
275 
276  // Write out the source header
277  write(xml_out, "Source_file_info", source_file_xml);
278  write(xml_out, "Source_record_info", source_record_xml);
279  }
280  catch (std::bad_cast) {
281  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
282  QDP_abort(1);
283  }
284  catch (const std::string& e) {
285  QDPIO::cerr << name << ": error extracting source_header: " << e << std::endl;
286  QDP_abort(1);
287  }
288  catch( const char* e) {
289  QDPIO::cerr << name <<": Caught some char* exception:" << std::endl;
290  QDPIO::cerr << e << std::endl;
291  QDPIO::cerr << "Rethrowing" << std::endl;
292  throw;
293  }
294 
295  // Cast should be valid now
296  const QDP::MapObject<int,EVPair<LatticeColorVector> >& eigen_source =
298 
299  QDPIO::cout << "Source successfully read and parsed" << std::endl;
300 
301  //
302  // Create the output files
303  //
304  try
305  {
306  // Generate a metadata
307  std::string file_str;
308  if (1)
309  {
310  XMLBufferWriter file_xml;
311 
312  push(file_xml, "MODMetaData");
313  write(file_xml, "id", std::string("propColorVec"));
314  write(file_xml, "lattSize", QDP::Layout::lattSize());
315  write(file_xml, "decay_dir", params.param.contract.decay_dir);
316  write(file_xml, "num_vecs", params.param.contract.num_vecs);
317  // write(file_xml, "mass_label", params.param.contract.mass_label); // no simple kind of mass label available. That is unfortunate...
318  proginfo(file_xml); // Print out basic program info
319  write(file_xml, "Propagator", params.param.prop);
320  write(file_xml, "Contractions", params.param.contract);
321  write(file_xml, "Config_info", gauge_xml);
322  pop(file_xml);
323 
324  file_str = file_xml.str();
325  }
326 
327  // Create the map object
328  std::istringstream xml_s(params.named_obj.prop_obj.xml);
329  XMLReader MapObjReader(xml_s);
330 
331  // Create the entry
335  MapObjReader,
337  file_str);
338 
340  }
341  catch (std::bad_cast)
342  {
343  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
344  QDP_abort(1);
345  }
346  catch (const std::string& e)
347  {
348  QDPIO::cerr << name << ": error creating prop: " << e << std::endl;
349  QDP_abort(1);
350  }
351 
352  // Cast should be valid now
353  QDP::MapObject<KeyPropColorVec_t,LatticeFermion>& prop_obj =
355 
356  // Sanity check - write out the norm2 of the source in the Nd-1 direction
357  // Use this for any possible verification
358  {
359  // Initialize the slow Fourier transform phases
360  SftMom phases(0, true, Nd-1);
361 
362  EVPair<LatticeColorVector> tmpvec; eigen_source.get(0, tmpvec);
363  multi1d<Double> source_corrs = sumMulti(localNorm2(tmpvec.eigenVector), phases.getSet());
364 
365  push(xml_out, "Source_correlators");
366  write(xml_out, "source_corrs", source_corrs);
367  pop(xml_out);
368  }
369 
370  // Another sanity check
372  {
373  QDPIO::cerr << __func__ << ": num_vecs= " << params.param.contract.num_vecs
374  << " is greater than the number of available colorvectors= "
375  << eigen_source.size() << std::endl;
376  QDP_abort(1);
377  }
378 
379 
380  // Total number of iterations
381  int ncg_had = 0;
382 
383  //
384  // Try the factories
385  //
386  try
387  {
388  StopWatch swatch;
389  swatch.reset();
390  QDPIO::cout << "Try the various factories" << std::endl;
391 
392  // Typedefs to save typing
393  typedef LatticeFermion T;
394  typedef multi1d<LatticeColorMatrix> P;
395  typedef multi1d<LatticeColorMatrix> Q;
396 
397  //
398  // Initialize fermion action
399  //
400  std::istringstream xml_s(params.param.prop.fermact.xml);
401  XMLReader fermacttop(xml_s);
402  QDPIO::cout << "FermAct = " << params.param.prop.fermact.id << std::endl;
403 
404  // Generic Wilson-Type stuff
407  fermacttop,
409 
410  Handle< FermState<T,P,Q> > state(S_f->createState(u));
411 
414 
415  QDPIO::cout << "Suitable factory found: compute all the quark props" << std::endl;
416  swatch.start();
417 
418  //
419  // Loop over the source color and spin, creating the source
420  // and calling the relevant propagator routines.
421  //
422  const int num_vecs = params.param.contract.num_vecs;
423  const int decay_dir = params.param.contract.decay_dir;
424  const multi1d<int>& t_sources = params.param.contract.t_sources;
425 
426  // Initialize the slow Fourier transform phases
427  SftMom phases(0, true, decay_dir);
428 
429 
430  // Loop over each operator
431  for(int tt=0; tt < t_sources.size(); ++tt)
432  {
433  int t_source = t_sources[tt];
434  QDPIO::cout << "t_source = " << t_source << std::endl;
435 
436  // All the loops
437  for(int colorvec_source=0; colorvec_source < num_vecs; ++colorvec_source)
438  {
439  QDPIO::cout << "colorvec_source = " << colorvec_source << std::endl;
440 
441  // Pull out a time-slice of the color std::vector source
442  LatticeColorVector vec_srce = zero;
444  eigen_source.get(colorvec_source, tmpvec);
445  vec_srce[phases.getSet()[t_source]] = tmpvec.eigenVector;
446 
447  for(int spin_source=0; spin_source < Ns; ++spin_source)
448  {
449  QDPIO::cout << "spin_source = " << spin_source << std::endl;
450 
451  // Insert a ColorVector into spin index spin_source
452  // This only overwrites sections, so need to initialize first
453  LatticeFermion chi = zero;
454  CvToFerm(vec_srce, chi, spin_source);
455 
456  LatticeFermion quark_soln = zero;
457 
458  // Do the propagator inversion
459  SystemSolverResults_t res = (*PP)(quark_soln, chi);
460  ncg_had = res.n_count;
461 
462  KeyPropColorVec_t key;
463  key.t_source = t_source;
464  key.colorvec_src = colorvec_source;
465  key.spin_src = spin_source;
466 
467  prop_obj.insert(key, quark_soln);
468  } // for spin_source
469  } // for colorvec_source
470  } // for t_source
471 
472  swatch.stop();
473  QDPIO::cout << "Propagators computed: time= "
474  << swatch.getTimeInSeconds()
475  << " secs" << std::endl;
476  }
477  catch (const std::string& e)
478  {
479  QDPIO::cout << name << ": caught exception around qprop: " << e << std::endl;
480  QDP_abort(1);
481  }
482 
483  push(xml_out,"Relaxation_Iterations");
484  write(xml_out, "ncg_had", ncg_had);
485  pop(xml_out);
486 
487  pop(xml_out); // prop_colorvec
488 
489  // Flush the object-std::map
490  prop_obj.flush();
491 
492  // Write the meta-data for this operator
493  {
494  XMLBufferWriter file_xml;
495 
496  push(file_xml, "PropColorVectors");
497  write(file_xml, "num_records", prop_obj.size());
498  write(file_xml, "Params", params.param);
499  write(file_xml, "Config_info", gauge_xml);
500  pop(file_xml);
501 
502  XMLBufferWriter record_xml;
503  push(record_xml, "PropColorVector");
504  write(record_xml, "num_records", prop_obj.size());
505  pop(record_xml);
506 
507  // Write the propagator xml info
508  TheNamedObjMap::Instance().get(params.named_obj.prop_id).setFileXML(file_xml);
509  TheNamedObjMap::Instance().get(params.named_obj.prop_id).setRecordXML(record_xml);
510  }
511 
512  snoop.stop();
513  QDPIO::cout << name << ": total time = "
514  << snoop.getTimeInSeconds()
515  << " secs" << std::endl;
516 
517  QDPIO::cout << name << ": ran successfully" << std::endl;
518 
519  END_CODE();
520  }
521 
522  }
523 
524 } // 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
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.
Fermion action factories.
All Wilson-type fermion actions.
void CvToFerm(const LatticeColorVectorF &a, LatticeFermionF &b, int spin_index)
Convert (insert) a LatticeColorVector into a LatticeFermion.
Definition: transf.cc:18
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.
MODS_t & eigen_source
Eigenvectors.
Compute the propagator elements M^-1 * multi1d<LatticeColorVector>
Key for propagator colorstd::vector sources.
Make xml file writer.
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
multi1d< LatticeColorMatrix > P
void write(XMLWriter &xml, const std::string &path, const InlinePropColorVecEnv::Params::NamedObject_t &input)
Propagator output.
void read(XMLReader &xml, const std::string &path, InlinePropColorVecEnv::Params::NamedObject_t &input)
Propagator input.
bool registerAll()
Register all the factories.
bool registerAll()
aggregate everything
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
multi1d< LatticeFermion > chi(Ncb)
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Definition: pbg5p_w.cc:27
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.
Fourier transform phase factor support.
GroupXML_t invParam
Definition: qprop_io.h:84
GroupXML_t fermact
Definition: qprop_io.h:80
A Pair type.
struct Chroma::InlinePropColorVecEnv::Params::Param_t param
struct Chroma::InlinePropColorVecEnv::Params::NamedObject_t named_obj
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Holds of vectors and weights.