CHROMA
inline_propagator_ferm_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of propagator returning only a single lattice fermion
3  *
4  * Propagator calculations
5  */
6 
7 #include "fermact.h"
10 #include "meas/glue/mesplq.h"
11 #include "util/ft/sftmom.h"
12 #include "util/info/proginfo.h"
13 #include "util/info/unique_id.h"
17 
19 
20 namespace Chroma
21 {
22  namespace InlinePropagatorFermEnv
23  {
24  namespace
25  {
26  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
27  const std::string& path)
28  {
29  return new InlinePropagatorFerm(InlinePropagatorFermParams(xml_in, path));
30  }
31 
32  //! Local registration flag
33  bool registered = false;
34  }
35 
36  const std::string name = "PROPAGATOR_FERM";
37 
38  //! Register all the factories
39  bool registerAll()
40  {
41  bool success = true;
42  if (! registered)
43  {
45  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
46  registered = true;
47  }
48  return success;
49  }
50  }
51 
52 
53  //! Propagator input
54  void read(XMLReader& xml, const std::string& path, InlinePropagatorFermParams::NamedObject_t& input)
55  {
56  XMLReader inputtop(xml, path);
57 
58  read(inputtop, "gauge_id", input.gauge_id);
59  read(inputtop, "source_id", input.source_id);
60  read(inputtop, "prop_id", input.prop_id);
61  }
62 
63  //! Propagator output
64  void write(XMLWriter& xml, const std::string& path, const InlinePropagatorFermParams::NamedObject_t& input)
65  {
66  push(xml, path);
67 
68  write(xml, "gauge_id", input.gauge_id);
69  write(xml, "source_id", input.source_id);
70  write(xml, "prop_id", input.prop_id);
71 
72  pop(xml);
73  }
74 
75 
76  // Param stuff
78 
80  {
81  try
82  {
83  XMLReader paramtop(xml_in, path);
84 
85  if (paramtop.count("Frequency") == 1)
86  read(paramtop, "Frequency", frequency);
87  else
88  frequency = 1;
89 
90  // Parameters for source construction
91  read(paramtop, "Param", param);
92 
93  // Read in the output propagator/source configuration info
94  read(paramtop, "NamedObject", named_obj);
95 
96  // Possible alternate XML file pattern
97  if (paramtop.count("xml_file") != 0)
98  {
99  read(paramtop, "xml_file", xml_file);
100  }
101  }
102  catch(const std::string& e)
103  {
104  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
105  QDP_abort(1);
106  }
107  }
108 
109 
110  //! Propagator input
111  void read(XMLReader& xml, const std::string& path, InlinePropagatorFermParams& input)
112  {
113  InlinePropagatorFermParams tmp(xml, path);
114  input = tmp;
115  }
116 
117  //! Propagator output
118  void write(XMLWriter& xml, const std::string& path, const InlinePropagatorFermParams& input)
119  {
120  push(xml, path);
121 
122  Chroma::write(xml, "Param", input.param);
123  Chroma::write(xml, "NamedObject", input.named_obj);
124 
125  pop(xml);
126  }
127 
128 
129 
130  // Function call
131  void
132  InlinePropagatorFerm::operator()(unsigned long update_no,
133  XMLWriter& xml_out)
134  {
135  // If xml file not empty, then use alternate
136  if (params.xml_file != "")
137  {
138  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
139 
140  push(xml_out, "propagator");
141  write(xml_out, "update_no", update_no);
142  write(xml_out, "xml_file", xml_file);
143  pop(xml_out);
144 
145  XMLFileWriter xml(xml_file);
146  func(update_no, xml);
147  }
148  else
149  {
150  func(update_no, xml_out);
151  }
152  }
153 
154 
155  // Real work done here
156  void
157  InlinePropagatorFerm::func(unsigned long update_no,
158  XMLWriter& xml_out)
159  {
160  START_CODE();
161 
162  StopWatch snoop;
163  snoop.reset();
164  snoop.start();
165 
166  // Test and grab a reference to the gauge field
167  XMLBufferWriter gauge_xml;
168  try
169  {
170  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
171  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
172  }
173  catch( std::bad_cast )
174  {
175  QDPIO::cerr << InlinePropagatorFermEnv::name << ": caught dynamic cast error"
176  << std::endl;
177  QDP_abort(1);
178  }
179  catch (const std::string& e)
180  {
181  QDPIO::cerr << InlinePropagatorFermEnv::name << ": std::map call failed: " << e
182  << std::endl;
183  QDP_abort(1);
184  }
185  const multi1d<LatticeColorMatrix>& u =
186  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
187 
188  push(xml_out, "propagator");
189  write(xml_out, "update_no", update_no);
190 
191  QDPIO::cout << InlinePropagatorFermEnv::name << ": propagator calculation" << std::endl;
192 
193  proginfo(xml_out); // Print out basic program info
194 
195  // Write out the input
196  write(xml_out, "Input", params);
197 
198  // Write out the config header
199  write(xml_out, "Config_info", gauge_xml);
200 
201  push(xml_out, "Output_version");
202  write(xml_out, "out_version", 1);
203  pop(xml_out);
204 
205  // Calculate some gauge invariant observables just for info.
206  MesPlq(xml_out, "Observables", u);
207 
208  //
209  // Read in the source along with relevant information.
210  //
211  XMLReader source_file_xml, source_record_xml;
212  LatticeFermion quark_source;
213 
214  bool make_sourceP = false;
215  bool seqsourceP = false;
216  QDPIO::cout << "Snarf the source from a named buffer" << std::endl;
217  try
218  {
219  quark_source =
220  TheNamedObjMap::Instance().getData<LatticeFermion>(params.named_obj.source_id);
221 
222  // Snarf the source info. This is will throw if the source_id is not there
223  TheNamedObjMap::Instance().get(params.named_obj.source_id).getFileXML(source_file_xml);
224  TheNamedObjMap::Instance().get(params.named_obj.source_id).getRecordXML(source_record_xml);
225 
226  // First identify what kind of source might be here
227  if (source_record_xml.count("/MakeSource") != 0)
228  {
229  make_sourceP = true;
230  }
231  else if (source_record_xml.count("/SequentialSource") != 0)
232  {
233  seqsourceP = true;
234  }
235  else
236  {
237  throw std::string("No appropriate header found");
238  }
239 
240  // Write out the source header
241  write(xml_out, "Source_file_info", source_file_xml);
242  write(xml_out, "Source_record_info", source_record_xml);
243  }
244  catch (std::bad_cast)
245  {
246  QDPIO::cerr << InlinePropagatorFermEnv::name << ": caught dynamic cast error"
247  << std::endl;
248  QDP_abort(1);
249  }
250  catch (const std::string& e)
251  {
252  QDPIO::cerr << InlinePropagatorFermEnv::name << ": error extracting source_header: " << e << std::endl;
253  QDP_abort(1);
254  }
255 
256  QDPIO::cout << "Source successfully read and parsed" << std::endl;
257 
258  // Sanity check - write out the norm2 of the source in the Nd-1 direction
259  // Use this for any possible verification
260  {
261  // Initialize the slow Fourier transform phases
262  SftMom phases(0, true, Nd-1);
263 
264  multi1d<Double> source_corr = sumMulti(localNorm2(quark_source),
265  phases.getSet());
266 
267  push(xml_out, "Source_correlator");
268  write(xml_out, "source_corr", source_corr);
269  pop(xml_out);
270  }
271 
272  //
273  // Loop over the source color and spin, creating the source
274  // and calling the relevant propagator routines. The QDP
275  // terminology is that a propagator is a matrix in color
276  // and spin space
277  //
278  LatticeFermion quark_soln = zero;
279  int ncg_had = 0;
280 
281  //
282  // Initialize fermion action
283  //
284  std::istringstream xml_s(params.param.fermact.xml);
285  XMLReader fermacttop(xml_s);
286  QDPIO::cout << "FermAct = " << params.param.fermact.id << std::endl;
287 
288 
289  //
290  // Try the factories
291  //
292  try
293  {
294  StopWatch swatch;
295  swatch.reset();
296  QDPIO::cout << "Try the various factories" << std::endl;
297 
298  // Typedefs to save typing
299  typedef LatticeFermion T;
300  typedef multi1d<LatticeColorMatrix> P;
301  typedef multi1d<LatticeColorMatrix> Q;
302 
303  // Generic Wilson-Type stuff
306  fermacttop,
308 
309  Handle< FermState<T,P,Q> > state(S_f->createState(u));
310 
313 
314  QDPIO::cout << "Suitable factory found: compute the quark prop" << std::endl;
315  swatch.start();
316 
317  SystemSolverResults_t res = (*PP)(quark_soln, quark_source);
318  ncg_had = res.n_count;
319 
320  swatch.stop();
321  QDPIO::cout << "Propagator computed: time= "
322  << swatch.getTimeInSeconds()
323  << " secs" << std::endl;
324  }
325  catch (const std::string& e)
326  {
327  QDPIO::cout << InlinePropagatorFermEnv::name
328  << ": caught exception around qprop: " << e << std::endl;
329  QDP_abort(1);
330  }
331 
332 
333  push(xml_out,"Relaxation_Iterations");
334  write(xml_out, "ncg_had", ncg_had);
335  pop(xml_out);
336 
337  // Sanity check - write out the propagator (pion) correlator in the Nd-1 direction
338  {
339  // Initialize the slow Fourier transform phases
340  SftMom phases(0, true, Nd-1);
341 
342  multi1d<Double> prop_corr = sumMulti(localNorm2(quark_soln),
343  phases.getSet());
344 
345  push(xml_out, "Prop_correlator");
346  write(xml_out, "prop_corr", prop_corr);
347  pop(xml_out);
348  }
349 
350 
351  // Save the propagator info
352  try
353  {
354  QDPIO::cout << "Start writing propagator info" << std::endl;
355 
356  XMLBufferWriter file_xml;
357  push(file_xml, "propagator");
358  write(file_xml, "id", uniqueId()); // NOTE: new ID form
359  pop(file_xml);
360 
361  XMLBufferWriter record_xml;
362  if (make_sourceP)
363  {
364  XMLReader xml_tmp(source_record_xml, "/MakeSource");
365 
366  push(record_xml, "Propagator");
367  write(record_xml, "ForwardProp", params.param);
368  record_xml << xml_tmp; // write out all the stuff under MakeSource
369  pop(record_xml);
370  }
371  else if (seqsourceP)
372  {
373  XMLReader xml_tmp(source_record_xml, "/SequentialSource");
374 
375  push(record_xml, "SequentialProp");
376  write(record_xml, "SeqProp", params.param);
377  record_xml << xml_tmp; // write out all the stuff under SequentialSource
378  pop(record_xml);
379  }
380 
381  // Write the propagator and info
382  TheNamedObjMap::Instance().create<LatticeFermion>(params.named_obj.prop_id);
383  TheNamedObjMap::Instance().getData<LatticeFermion>(params.named_obj.prop_id) = quark_soln;
384  TheNamedObjMap::Instance().get(params.named_obj.prop_id).setFileXML(file_xml);
385  TheNamedObjMap::Instance().get(params.named_obj.prop_id).setRecordXML(record_xml);
386 
387  QDPIO::cout << "Propagator successfully updated" << std::endl;
388  }
389  catch (std::bad_cast)
390  {
391  QDPIO::cerr << InlinePropagatorFermEnv::name << ": caught dynamic cast error"
392  << std::endl;
393  QDP_abort(1);
394  }
395  catch (const std::string& e)
396  {
397  QDPIO::cerr << InlinePropagatorFermEnv::name << ": error extracting prop_header: " << e << std::endl;
398  QDP_abort(1);
399  }
400 
401  pop(xml_out); // propagator
402 
403  snoop.stop();
404  QDPIO::cout << InlinePropagatorFermEnv::name << ": total time = "
405  << snoop.getTimeInSeconds()
406  << " secs" << std::endl;
407 
408  QDPIO::cout << InlinePropagatorFermEnv::name << ": ran successfully" << std::endl;
409 
410  END_CODE();
411  }
412 
413 }
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
Inline task for generating propagators.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
InlinePropagatorFermParams params
void func(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 read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
std::string uniqueId()
Return a unique id.
Definition: unique_id.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.
Inline construction of propagator returning only a single lattice fermion.
Make xml file writer.
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
multi1d< LatticeColorMatrix > P
bool registerAll()
Register all the factories.
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
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
struct Chroma::InlinePropagatorFermParams::NamedObject_t named_obj
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Generate a unique id.