CHROMA
propagator_comp.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Main code for propagator generation
3  */
4 
5 #include <iostream>
6 #include <cstdio>
7 #include <iomanip>
8 #include "chroma.h"
9 
10 using namespace Chroma;
11 
12 
13 // define MRES_CALCULATION in order to run the code computing the residual mass
14 // and the pseudoscalar to conserved axial current correlator
15 #define MRES_CALCULATION
16 
17 /*
18  * Input
19  */
20 struct Prop_t
21 {
22  std::string source_file;
23  std::string prop_file;
24  QDP_volfmt_t prop_volfmt;
25 };
26 
27 
28 struct Component_t {
29  int color;
30  int spin;
31 };
32 
34 {
35  ChromaProp_t param;
36  Cfg_t cfg;
37  Prop_t prop;
38  multi1d<Component_t> components;
39 };
40 
41 
42 void read(XMLReader& xml, const std::string& path, Component_t &comp)
43 {
44  XMLReader top(xml,path);
45  try {
46  read(top, "color", comp.color);
47  read(top, "spin", comp.spin);
48  }
49  catch( const std::string& e ) {
50  QDPIO::cerr << "Caught Exception : " << e << std::endl;
51  QDP_abort(1);
52  }
53  if( comp.color < 0 || comp.color >= Nc ) {
54  QDPIO::cerr << "Component color >= Nc. color = " << comp.color << std::endl;
55  QDP_abort(1);
56  }
57 
58  if( comp.spin < 0 || comp.spin >= Ns ) {
59  QDPIO::cerr << "Component spin >= Ns. spin = " << comp.spin << std::endl;
60  QDP_abort(1);
61  }
62 }
63 
64 void write(XMLWriter& xml, const std::string& path, const Component_t &comp)
65 {
66 
67  push( xml, path );
68 
69  write(xml, "color", comp.color);
70  write(xml, "spin", comp.spin);
71 
72  pop( xml );
73 }
74 
75 
76 // Propagator parameters
77 void read(XMLReader& xml, const std::string& path, Prop_t& input)
78 {
79  XMLReader inputtop(xml, path);
80 
81  read(inputtop, "source_file", input.source_file);
82  read(inputtop, "prop_file", input.prop_file);
83  read(inputtop, "prop_volfmt", input.prop_volfmt); // singlefile or multifile
84 }
85 
86 
87 // Reader for input parameters
88 void read(XMLReader& xml, const std::string& path, PropagatorComponent_input_t& input)
89 {
90  XMLReader inputtop(xml, path);
91 
92  // Read the input
93  try
94  {
95  // The parameters holds the version number
96  read(inputtop, "Param", input.param);
97 
98  // Read in the gauge configuration info
99  read(inputtop, "Cfg", input.cfg);
100 
101  // Read in the source/propagator info
102  read(inputtop, "Prop", input.prop);
103 
104  read(inputtop, "Components", input.components);
105  }
106  catch (const std::string& e)
107  {
108  QDPIO::cerr << "Error reading data: " << e << std::endl;
109  throw;
110  }
111 }
112 
113 // Forward declaration
114 void saveComponent(const ChromaProp_t& param,
115  const Prop_t& prop,
116  XMLReader& source_record_xml,
117  const Component_t& component,
118  XMLReader& gauge_xml,
119  XMLWriter& xml_out,
120  const LatticeFermion& psi,
121  bool make_sourceP,
122  bool seqsourceP);
123 
124 //! Propagator generation
125 /*! \defgroup propagator_comp Propagator generation
126  * \ingroup main
127  *
128  * Main program for propagator generation.
129  */
130 
131 int main(int argc, char **argv)
132 {
133  // Put the machine into a known state
134  Chroma::initialize(&argc, &argv);
135 
136  START_CODE();
137 
138  // Input parameter structure
140 
141  // Instantiate xml reader for DATA
142  XMLReader xml_in(Chroma::getXMLInputFileName());
143 
144  // Read data
145  try {
146  read(xml_in, "/propagatorComp", input);
147  }
148  catch( const std::string& e) {
149  QDPIO::cerr << "Caught Exception : " << e << std::endl;
150  QDP_abort(1);
151  }
152 
153  // Specify lattice size, shape, etc.
154  Layout::setLattSize(input.param.nrow);
155  Layout::create();
156 
157  QDPIO::cout << "propagatorComp" << std::endl;
158 
159  // Read in the configuration along with relevant information.
160  multi1d<LatticeColorMatrix> u(Nd);
161  XMLReader gauge_file_xml, gauge_xml;
162 
163  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
164 
165  // Read in the source along with relevant information.
166  LatticePropagator quark_prop_source;
167  XMLReader source_file_xml, source_record_xml;
168 
169  // ONLY SciDAC mode is supported for propagators!!
170  readQprop(source_file_xml,
171  source_record_xml, quark_prop_source,
172  input.prop.source_file, QDPIO_SERIAL);
173 
174  // Try to invert this record XML into a source struct
175  // Also pull out the id of this source
176  int t0;
177  int j_decay;
178  multi1d<int> boundary;
179  bool make_sourceP = false;;
180  bool seqsourceP = false;
181  {
182  // ONLY SciDAC mode is supported for propagators!!
183  QDPIO::cout << "Attempt to read source" << std::endl;
184  readQprop(source_file_xml,
185  source_record_xml, quark_prop_source,
186  input.prop.source_file, QDPIO_SERIAL);
187  QDPIO::cout << "Forward propagator successfully read" << std::endl;
188 
189  // Try to invert this record XML into a source struct
190  try
191  {
192  // First identify what kind of source might be here
193  if (source_record_xml.count("/MakeSource") != 0)
194  {
195  PropSourceConst_t source_header;
196 
197  read(source_record_xml, "/MakeSource/PropSource", source_header);
198  j_decay = source_header.j_decay;
199  t0 = source_header.t_source[j_decay];
200  boundary = input.param.boundary;
201  make_sourceP = true;
202  }
203  else if (source_record_xml.count("/SequentialSource") != 0)
204  {
206  PropSourceConst_t source_header;
207  SeqSource_t seqsource_header;
208 
209  read(source_record_xml, "/SequentialSource/SeqSource", seqsource_header);
210  // Any source header will do for j_decay
211  read(source_record_xml, "/SequentialSource/ForwardProps/elem[1]/ForwardProp",
212  prop_header);
213  read(source_record_xml, "/SequentialSource/ForwardProps/elem[1]/PropSource",
214  source_header);
215  j_decay = source_header.j_decay;
216  t0 = seqsource_header.t_sink;
217  boundary = prop_header.boundary;
218  seqsourceP = true;
219  }
220  else
221  throw std::string("No appropriate header found");
222  }
223  catch (const std::string& e)
224  {
225  QDPIO::cerr << "Error extracting source_header: " << e << std::endl;
226  QDP_abort(1);
227  }
228  }
229 
230  // Sanity check
231  if (seqsourceP)
232  {
233  for(int i=0; i < boundary.size(); ++i)
234  if (boundary[i] != input.param.boundary[i])
235  {
236  QDPIO::cerr << "Incompatible boundary between input and seqsource" << std::endl;
237  QDP_abort(1);
238  }
239  }
240 
241 
242  // Instantiate XML writer for XMLDAT
243  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
244  push(xml_out, "propagatorComp");
245 
246  proginfo(xml_out); // Print out basic program info
247 
248  // Write out the input
249  write(xml_out, "Input", xml_in);
250 
251  // Write out the config header
252  write(xml_out, "Config_info", gauge_xml);
253 
254  // Write out the source header
255  write(xml_out, "Source_file_info", source_file_xml);
256  write(xml_out, "Source_record_info", source_record_xml);
257 
258  push(xml_out, "Output_version");
259  write(xml_out, "out_version", 1);
260  pop(xml_out);
261 
262  xml_out.flush();
263 
264 
265  // Check if the gauge field configuration is unitarized
266  unitarityCheck(u);
267 
268  // Calculate some gauge invariant observables just for info.
269  MesPlq(xml_out, "Observables", u);
270  xml_out.flush();
271 
272  // Sanity check - write out the norm2 of the source in the Nd-1 direction
273  // Use this for any possible verification
274  {
275  // Initialize the slow Fourier transform phases
276  SftMom phases(0, true, Nd-1);
277 
278  multi1d<Double> source_corr = sumMulti(localNorm2(quark_prop_source),
279  phases.getSet());
280 
281  push(xml_out, "Source_correlator");
282  write(xml_out, "source_corr", source_corr);
283  pop(xml_out);
284  }
285 
286  xml_out.flush();
287 
288  /*
289  * Construct fermionic BC. Need one for LatticeFermion and multi1d<LatticeFermion>
290  * Note, the handle is on an ABSTRACT type
291  */
293  Handle< FermBC<multi1d<LatticeFermion> > > fbc_a(new SimpleFermBC<multi1d<LatticeFermion> >(input.param.boundary));
294  //
295  // Initialize fermion action
296  //
297  FermionAction<LatticeFermion>* S_f_ptr = 0;
299 
300  switch (input.param.FermActHandle->getFermActType() ) {
301  case FERM_ACT_WILSON:
302  {
303  const WilsonFermActParams& wils = dynamic_cast<const WilsonFermActParams&>(*(input.param.FermActHandle));
304 
305  QDPIO::cout << "FERM_ACT_WILSON" << std::endl;
306  S_f_ptr = new EvenOddPrecWilsonFermAct(fbc, wils.Mass,
307  wils.anisoParam);
308  }
309  break;
310 
311  case FERM_ACT_UNPRECONDITIONED_WILSON:
312  {
313  const WilsonFermActParams& wils = dynamic_cast<const WilsonFermActParams&>(*(input.param.FermActHandle));
314 
315  QDPIO::cout << "FERM_ACT_UNPRECONDITIONED_WILSON" << std::endl;
316  S_f_ptr = new UnprecWilsonFermAct(fbc, wils.Mass);
317  }
318  break;
319 
320  case FERM_ACT_OVLAP_PARTFRAC_4D:
321  {
322  QDPIO::cout << "FERM_ACT_ZOLOTAREV_4D" << std::endl;
323  const OvlapPartFrac4DFermActParams& zolo4d = dynamic_cast<const Zolotarev4DFermActParams& > (*(input.param.FermActHandle));
324 
325  // Construct Fermact -- now uses constructor from the zolo4d params
326  // struct
327  S_f_ptr = new OvlapPartFrac4DFermAct(fbc, zolo4d, xml_out);
328  }
329  break;
330 
331  case FERM_ACT_ZOLOTAREV_5D:
332  {
333  QDPIO::cout << "FERM_ACT_ZOLOTAREV_5D" << std::endl;
334  const Zolotarev5DFermActParams& zolo5d = dynamic_cast<const Zolotarev5DFermActParams& > (*(input.param.FermActHandle));
335 
336  // Construct Fermact -- now uses constructor from the zolo4d params
337  // struct
338  S_f_a_ptr = new Zolotarev5DFermActArray(fbc_a, fbc, zolo5d, xml_out);
339  }
340  break;
341 
342  case FERM_ACT_DWF:
343  {
344  const DWFFermActParams& dwf = dynamic_cast<const DWFFermActParams&>(*(input.param.FermActHandle));
345 
346  QDPIO::cout << "FERM_ACT_DWF" << std::endl;
347  S_f_a_ptr = new EvenOddPrecDWFermActArray(fbc_a,
348  dwf.chiralParam.OverMass,
349  dwf.Mass,
350  dwf.chiralParam.N5);
351  }
352  break;
353 
354  case FERM_ACT_UNPRECONDITIONED_DWF:
355  {
356  const DWFFermActParams& dwf = dynamic_cast<const DWFFermActParams&>(*(input.param.FermActHandle));
357 
358  QDPIO::cout << "FERM_ACT_UNPRECONDITONED_DWF" << std::endl;
359  S_f_a_ptr = new UnprecDWFermActArray(fbc_a,
360  dwf.chiralParam.OverMass,
361  dwf.Mass,
362  dwf.chiralParam.N5);
363  }
364  break;
365  default:
366  QDPIO::cerr << "Unsupported fermion action" << std::endl;
367  QDP_abort(1);
368  }
369 
370  // Create a useable handle on the action
371  // The handle now owns the pointer
374 
375  // FIrst we have to set up the state -- this is fermact dependent
376  const ConnectState *state_ptr;
377 
378 
379  switch(input.param.FermActHandle->getFermActType()) {
380  case FERM_ACT_WILSON:
381  state_ptr = S_f->createState(u);
382  break;
383  case FERM_ACT_UNPRECONDITIONED_WILSON:
384  state_ptr = S_f->createState(u);
385  break;
386  case FERM_ACT_DWF:
387  state_ptr = S_f_a->createState(u);
388  break;
389  case FERM_ACT_UNPRECONDITIONED_DWF:
390  state_ptr = S_f_a->createState(u);
391  break;
392 
393  case FERM_ACT_ZOLOTAREV_4D:
394  {
395  const Zolotarev4DFermActParams& zolo4d = dynamic_cast<const Zolotarev4DFermActParams& > (*(input.param.FermActHandle));
396  const Zolotarev4DFermAct& S_zolo4 = dynamic_cast<const Zolotarev4DFermAct&>(*S_f);
397 
398  state_ptr = S_zolo4.createState(u, zolo4d.StateInfo, xml_out,zolo4d.AuxFermActHandle->getMass());
399 
400  }
401  break;
402  case FERM_ACT_ZOLOTAREV_5D:
403  {
404  const Zolotarev5DFermActParams& zolo5d = dynamic_cast<const Zolotarev5DFermActParams& > (*(input.param.FermActHandle));
405  const Zolotarev5DFermActArray& S_zolo5 = dynamic_cast<const Zolotarev5DFermActArray&>(*S_f_a);
406 
407 
408  state_ptr = S_zolo5.createState(u, zolo5d.StateInfo, xml_out, zolo5d.AuxFermActHandle->getMass());
409  }
410  break;
411 
412  default:
413  QDPIO::cerr << "Unsupported fermion action (state creation)" << std::endl;
414  QDP_abort(1);
415  }
416 
417  // Now do the quarkprop here again depending on which of the
418  // action pointers is not null
419 
420  Handle<const ConnectState> state(state_ptr); // inserts any BC
421 
422 
423  //
424  // Loop over the source color and spin, creating the source
425  // and calling the relevant propagator routines. The QDP
426  // terminology is that a propagator is a matrix in color
427  // and spin space
428  //
429 
430 
431  LatticeFermion psi;
432  int ncg_had = 0;
433  for(int comp = 0; comp < input.components.size(); comp++) {
434  LatticeFermion chi;
435 
436  PropToFerm(quark_prop_source, chi, input.components[comp].color,
437  input.components[comp].spin);
438 
439 
440  // Zero out initial guess
441  psi = zero;
442 
443 
444  // Normalise source
445  Real fact = Real(1) / sqrt(norm2(chi));
446  chi *= fact;
447 
448  int n_count = 0;
449 
450  if( S_f_ptr != 0x0 ) {
451 
452  if( input.param.FermActHandle->getFermActType()==FERM_ACT_ZOLOTAREV_4D ) {
453 
454  switch( input.param.invParam.invType ) {
455  case REL_GMRESR_SUMR_INVERTER:
456  case REL_GMRESR_CG_INVERTER:
457  {
458  const OverlapFermActBase& S_ov = dynamic_cast<const OverlapFermActBase&>(*S_f);
459 
460  S_ov.qprop(psi,
461  state,
462  chi,
463  input.param.invParam.invType,
464  input.param.invParam.RsdCG,
465  input.param.invParam.RsdCGPrec,
466  input.param.invParam.MaxCG,
467  input.param.invParam.MaxCGPrec,
468  n_count);
469  }
470  break;
471  default:
472  S_f->qprop(psi,
473  state,
474  chi,
475  input.param.invParam.invType,
476  input.param.invParam.RsdCG,
477  input.param.invParam.MaxCG,
478  n_count);
479  break;
480  } // End switch
481  } // End Zolotarev4D
482  else {
483  S_f->qprop(psi,
484  state,
485  chi,
486  input.param.invParam.invType,
487  input.param.invParam.RsdCG,
488  input.param.invParam.MaxCG,
489  n_count);
490  }
491  }
492  else if ( S_f_a_ptr != 0x0 ) {
493 
494  S_f_a->qprop(psi,
495  state,
496  chi,
497  input.param.invParam.invType,
498  input.param.invParam.RsdCG,
499  input.param.invParam.MaxCG,
500  n_count);
501  }
502  else {
503  QDPIO::cerr << "Both S_f_ptr and S_f_a_ptr == 0 " << std::endl;
504  QDP_abort(1);
505  }
506 
507  ncg_had += n_count;
508 
509  fact = Real(1) / fact;
510  psi *= fact;
511 
512  push(xml_out,"Relaxation_Iterations");
513  write(xml_out, "ncg_had", n_count);
514  pop(xml_out);
515 
516 
517  saveComponent( input.param,
518  input.prop,
519  source_record_xml,
520  input.components[comp],
521  gauge_xml,
522  xml_out,
523  psi,
524  make_sourceP,
525  seqsourceP);
526 
527  }
528 
529  pop(xml_out); // propagator
530 
531  xml_out.close();
532  xml_in.close();
533 
534  END_CODE();
535 
536  // Time to bolt
537  QDP_finalize();
538 
539  exit(0);
540 }
541 
542 void saveComponent(const ChromaProp_t& param,
543  const Prop_t& prop,
544  XMLReader& source_record_xml,
545  const Component_t& component,
546  XMLReader& gauge_xml,
547  XMLWriter& xml_out,
548  const LatticeFermion& psi,
549  bool make_sourceP,
550  bool seqsourceP)
551 {
552  START_CODE();
553 
554  SftMom phases(0, true, Nd-1);
555  multi1d<Double> prop_corr = sumMulti(localNorm2(psi),
556  phases.getSet());
557 
558  push(xml_out, "PropComp_correlator");
559  write(xml_out, "Mass", param.FermActHandle->getMass());
560  write(xml_out, "prop_corr", prop_corr);
561  pop(xml_out);
562 
563 
564 
565  XMLBufferWriter file_xml;
566  int id = 0;
567  push(file_xml, "propagatorComponent");
568  // NEED TO FIX THIS - SOMETHING NON-TRIVIAL NEEDED
569  write(file_xml, "id", id);
570  pop(file_xml);
571 
572  XMLBufferWriter record_xml;
573 
574  if( make_sourceP) {
575 
576 
577  XMLReader xml_tmp(source_record_xml, "/MakeSource");
578 
579  push(record_xml, "Propagator");
580  write(record_xml, "ForwardProp", param);
581  record_xml << xml_tmp;
582  write(record_xml, "Component", component);
583  pop(record_xml);
584  }
585  else {
586  XMLReader xml_tmp(source_record_xml, "/SequentialSource");
587 
588  push(record_xml, "SeqProp");
589  write(record_xml, "ForwardProp", param);
590  record_xml << xml_tmp;
591  write(record_xml, "Component", component);
592  pop(record_xml);
593  }
594  std::ostringstream outfile;
595 
596  // Zero suffix for compatibility with multi mass version
597  outfile << prop.prop_file << "_component_s" << component.spin
598  << "_c" << component.color ;
599 
600 
601  QDPIO::cout << "Attempting to write " << outfile.str() << std::endl;
602 
603  // Write the source
604  writeFermion(file_xml, record_xml, psi,
605  outfile.str(), prop.prop_volfmt, QDPIO_SERIAL);
606 
608  exit(0);
609 
610  END_CODE();
611 }
Primary include file for CHROMA in application codes.
Support class for fermion actions and linear operators.
Definition: state.h:28
4D style even-odd preconditioned domain-wall fermion action
Even-odd preconditioned Wilson fermion action.
Base class for quadratic matter actions (e.g., fermions)
Definition: fermact.h:53
Class for counted reference semantics.
Definition: handle.h:33
Base class for unpreconditioned overlap-like fermion actions.
SystemSolver< T > * qprop(Handle< FermState< T, P, Q > > state, const GroupXML_t &invParam) const
Redefine quark propagator routine for 4D fermions.
4D Zolotarev variant of Overlap-Dirac operator
Fourier transform phase factor support.
Definition: sftmom.h:35
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
Concrete class for all gauge actions with simple boundary conditions.
Definition: simple_fermbc.h:42
Unpreconditioned domain-wall fermion action.
Unpreconditioned Wilson fermion action.
void PropToFerm(const LatticePropagatorF &b, LatticeFermionF &a, int color_index, int spin_index)
Extract a LatticeFermion from a LatticePropagator.
Definition: transf.cc:226
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void unitarityCheck(const multi1d< LatticeColorMatrixF3 > &u)
Check the unitarity of color matrix in SU(N)
Definition: unit_check.cc:20
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
std::map< std::string, SinkPropContainer_t > prop
ForwardProp_t prop_header
int j_decay
Definition: meslate.cc:22
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
int n_count
Definition: invbicg.cc:78
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
void readQprop(XMLReader &file_xml, XMLReader &record_xml, LatticePropagator &quark_prop, const std::string &file, QDP_serialparallel_t serpar)
Read a Chroma propagator.
Definition: qprop_io.cc:1573
multi1d< LatticeFermion > chi(Ncb)
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
LatticeFermion psi
Definition: mespbg5p_w.cc:35
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
void writeFermion(XMLBufferWriter &file_xml, XMLBufferWriter &record_xml, const LatticeFermion &fermion, const std::string &file, QDP_volfmt_t volfmt, QDP_serialparallel_t serpar)
Definition: qprop_io.cc:1613
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Definition: pbg5p_w.cc:27
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
int main(int argc, char **argv)
void saveComponent(const ChromaProp_t &param, const Prop_t &prop, XMLReader &source_record_xml, const Component_t &component, XMLReader &gauge_xml, XMLWriter &xml_out, const LatticeFermion &psi, bool make_sourceP, bool seqsourceP)
Gauge configuration structure.
Definition: cfgtype_io.h:16
Propagator parameters.
Definition: qprop_io.h:75
Propagator source construction parameters.
Definition: qprop_io.h:27
Sequential source parameters.
Definition: qprop_io.h:90
Params for wilson ferm acts.
Propagators.
std::string source_file
QDP_volfmt_t prop_volfmt
std::string prop_file
multi1d< Component_t > components