CHROMA
inline_seqprop_test_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Test sequential propagator
3  *
4  * Sequential source test
5  */
6 
7 #include "handle.h"
10 #include "meas/glue/mesplq.h"
15 #include "util/ft/sftmom.h"
16 #include "util/info/proginfo.h"
19 
20 namespace Chroma
21 {
22  //! Propagator input
23  void read(XMLReader& xml, const std::string& path, InlineSeqPropTestEnv::Params::NamedObject_t& input)
24  {
25  XMLReader inputtop(xml, path);
26 
27  read(inputtop, "gauge_id", input.gauge_id);
28  read(inputtop, "sink_ids", input.sink_ids);
29  read(inputtop, "seqprop_id", input.seqprop_id);
30  read(inputtop, "gamma_insertion", input.gamma_insertion);
31  }
32 
33  //! Propagator output
34  void write(XMLWriter& xml, const std::string& path, const InlineSeqPropTestEnv::Params::NamedObject_t& input)
35  {
36  push(xml, path);
37 
38  write(xml, "gauge_id", input.gauge_id);
39  write(xml, "sink_ids", input.sink_ids);
40  write(xml, "seqprop_id", input.seqprop_id);
41  write(xml, "gamma_insertion", input.gamma_insertion);
42 
43  pop(xml);
44  }
45 
46 
47  namespace InlineSeqPropTestEnv
48  {
49  namespace
50  {
51  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
52  const std::string& path)
53  {
54  return new InlineMeas(Params(xml_in, path));
55  }
56 
57  //! Local registration flag
58  bool registered = false;
59  }
60 
61  const std::string name = "SEQPROP_TEST";
62 
63  //! Register all the factories
64  bool registerAll()
65  {
66  bool success = true;
67  if (! registered)
68  {
71  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
72  registered = true;
73  }
74  return success;
75  }
76 
77 
78 
79  // Param stuff
81 
82  Params::Params(XMLReader& xml_in, const std::string& path)
83  {
84  try
85  {
86  XMLReader paramtop(xml_in, path);
87 
88  if (paramtop.count("Frequency") == 1)
89  read(paramtop, "Frequency", frequency);
90  else
91  frequency = 1;
92 
93  // The parameters for smearing the sink
94  read(paramtop, "PropSourceSmear", smear_header);
95 
96  // Read in the forward_prop/seqsource info
97  read(paramtop, "NamedObject", named_obj);
98 
99  // Possible alternate XML file pattern
100  if (paramtop.count("xml_file") != 0)
101  {
102  read(paramtop, "xml_file", xml_file);
103  }
104  }
105  catch(const std::string& e)
106  {
107  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
108  QDP_abort(1);
109  }
110  }
111 
112 
113  void
114  Params::writeXML(XMLWriter& xml_out, const std::string& path)
115  {
116  push(xml_out, path);
117 
118  write(xml_out, "PropSourceSmear", smear_header);
119  write(xml_out, "NamedObject", named_obj);
120 
121  pop(xml_out);
122  }
123 
124 
125  // Function call
126  void
127  InlineMeas::operator()(unsigned long update_no,
128  XMLWriter& xml_out)
129  {
130  // If xml file not empty, then use alternate
131  if (params.xml_file != "")
132  {
133  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
134 
135  push(xml_out, "SeqPropTest");
136  write(xml_out, "update_no", update_no);
137  write(xml_out, "xml_file", xml_file);
138  pop(xml_out);
139 
140  XMLFileWriter xml(xml_file);
141  func(update_no, xml);
142  }
143  else
144  {
145  func(update_no, xml_out);
146  }
147  }
148 
149 
150  // Function call
151  void
152  InlineMeas::func(unsigned long update_no,
153  XMLWriter& xml_out)
154  {
155  START_CODE();
156 
157  StopWatch snoop;
158  snoop.reset();
159  snoop.start();
160 
161  push(xml_out, "SeqPropTest");
162  write(xml_out, "update_no", update_no);
163 
164  QDPIO::cout << name << ": sequential propagator sequential test" << std::endl;
165 
166  proginfo(xml_out); // Print out basic program info
167 
168  // Write out the input
169  params.writeXML(xml_out, "Input");
170 
171  // Test and grab a reference to the gauge field
172  XMLBufferWriter gauge_xml;
173  multi1d<LatticeColorMatrix> u;
174  try
175  {
176  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
177  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
178  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
179  }
180  catch( std::bad_cast )
181  {
182  QDPIO::cerr << name << ": caught dynamic cast error"
183  << std::endl;
184  QDP_abort(1);
185  }
186  catch (const std::string& e)
187  {
188  QDPIO::cerr << name << ": error extracting gauge field: " << e
189  << std::endl;
190  QDP_abort(1);
191  }
192 
193  // Write out the config header
194  write(xml_out, "Config_info", gauge_xml);
195 
196  push(xml_out, "Output_version");
197  write(xml_out, "out_version", 1);
198  pop(xml_out);
199 
200  // Calculate some gauge invariant observables just for info.
201  MesPlq(xml_out, "Observables", u);
202 
203  // Sanity check
204  if (params.named_obj.sink_ids.size() == 0)
205  {
206  QDPIO::cerr << name << ": sanity error: " << std::endl;
207  QDP_abort(1);
208  }
209 
210 
211  //
212  // Read the forward propagator and extract headers
213  //
214  multi1d<LatticePropagator> forward_props(params.named_obj.sink_ids.size());
215  multi1d<ForwardProp_t> forward_headers(params.named_obj.sink_ids.size());
216 
217  push(xml_out, "Forward_prop_infos");
218  for(int loop=0; loop < params.named_obj.sink_ids.size(); ++loop)
219  {
220  push(xml_out, "elem");
221  try
222  {
223  // Snarf the data into a copy
224  forward_props[loop] =
225  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.sink_ids[loop]);
226 
227  // Snarf the source info. This is will throw if the source_id is not there
228  XMLReader prop_file_xml, prop_record_xml;
229  TheNamedObjMap::Instance().get(params.named_obj.sink_ids[loop]).getFileXML(prop_file_xml);
230  TheNamedObjMap::Instance().get(params.named_obj.sink_ids[loop]).getRecordXML(prop_record_xml);
231 
232  // Try to invert this record XML into a ChromaProp struct
233  // Also pull out the id of this source
234  read(prop_record_xml, "/SinkSmear", forward_headers[loop]);
235 
236  // Save prop input
237  write(xml_out, "Propagator_info", prop_record_xml);
238  }
239  catch( std::bad_cast )
240  {
241  QDPIO::cerr << name << ": caught dynamic cast error"
242  << std::endl;
243  QDP_abort(1);
244  }
245  catch (const std::string& e)
246  {
247  QDPIO::cerr << name << ": error extracting forward props: " << e
248  << std::endl;
249  QDP_abort(1);
250  }
251  pop(xml_out);
252  }
253  pop(xml_out);
254 
255  QDPIO::cout << "Forward propagators successfully read and parsed" << std::endl;
256 
257 
258  //
259  // Read the quark sequential propagator and extract headers
260  //
261  LatticePropagator seqprop;
262  SequentialProp_t seqprop_header;
263 
264  try
265  {
266  // Snarf the data into a copy
267  seqprop = TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.seqprop_id);
268 
269  // Snarf the source info. This is will throw if the source_id is not there
270  XMLReader prop_file_xml, prop_record_xml;
271  TheNamedObjMap::Instance().get(params.named_obj.seqprop_id).getFileXML(prop_file_xml);
272  TheNamedObjMap::Instance().get(params.named_obj.seqprop_id).getRecordXML(prop_record_xml);
273 
274  // Save prop input
275  write(xml_out, "Seqprop_info", prop_record_xml);
276 
277  // Try to invert this record XML into a SequentialSource_t struct
278  // Also pull out the id of this source
279  read(prop_record_xml, "/SequentialProp", seqprop_header);
280  }
281  catch( std::bad_cast )
282  {
283  QDPIO::cerr << name << ": caught dynamic cast error"
284  << std::endl;
285  QDP_abort(1);
286  }
287  catch (const std::string& e)
288  {
289  QDPIO::cerr << name << ": error extracting seqprop: " << e
290  << std::endl;
291  QDP_abort(1);
292  }
293 
294  QDPIO::cout << "Sequential propagator successfully read and parsed" << std::endl;
295 
296  // Derived from input prop
297  int j_decay = seqprop_header.seqsource_header.j_decay;
298 
299  // Initialize the slow Fourier transform phases
300  SftMom phases(0, true, j_decay);
301 
302  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
303  // Use this for any possible verification
304  push(xml_out, "Forward_prop_correlators");
305  for(int loop=0; loop < params.named_obj.sink_ids.size(); ++loop)
306  {
307  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(forward_props[loop]),
308  phases.getSet());
309 
310  push(xml_out, "elem");
311  write(xml_out, "forward_prop_corr", forward_prop_corr);
312  pop(xml_out);
313  }
314  pop(xml_out);
315 
316  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
317  // Use this for any possible verification
318  {
319  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(seqprop),
320  phases.getSet());
321 
322  push(xml_out, "Seqprop_correlator");
323  write(xml_out, "seqprop_corr", forward_prop_corr);
324  pop(xml_out);
325  }
326 
327  //------------------ Start main body of calculations -----------------------------
328 
329  try
330  {
331  // Source smear the forward propagators
332  std::istringstream xml_s(params.smear_header.source.xml);
333  XMLReader sourcetop(xml_s);
334  QDPIO::cout << "Source smearing = " << params.smear_header.source.id << std::endl;
335 
338  sourcetop,
340  u));
341 
342  // Source smear the sequential propagator
343  (*sourceSmearing)(seqprop);
344 
345 
346  //
347  // Construct the sequential source constructor
348  //
349  QDPIO::cout << "Sequential source = " << seqprop_header.seqsource_header.seqsrc.xml << std::endl;
350 
351  std::istringstream xml_seq(seqprop_header.seqsource_header.seqsrc.xml);
352  XMLReader seqsrctop(xml_seq);
353  QDPIO::cout << "SeqSource = " << seqprop_header.seqsource_header.seqsrc.id << std::endl;
354 
356  hadSeqSource(TheWilsonHadronSeqSourceFactory::Instance().createObject(seqprop_header.seqsource_header.seqsrc.id,
357  seqsrctop,
358  seqprop_header.seqsource_header.seqsrc.path));
359 
360  // Evaluate the seqprop back at the source - this is the 2-pt at the sink
361  int gamma_insertion = params.named_obj.gamma_insertion;
362 
363  Complex source_value = hadSeqSource->tieBack(u, seqprop_header, seqprop, gamma_insertion);
364 
365  // Compute the 2-pt
366  Complex twopt_sink = hadSeqSource->twoPtSink(u, forward_headers, forward_props, gamma_insertion);
367 
368  // Dump the results
369  push(xml_out, "LoopBackTest");
370  write(xml_out, "seq_src", seqprop_header.seqsource_header.seqsrc.id);
371  write(xml_out, "gamma_insertion", gamma_insertion);
372  write(xml_out, "j_decay", seqprop_header.forward_props[0].source_header.j_decay);
373  write(xml_out, "t_srce", seqprop_header.forward_props[0].source_header.getTSrce());
374  write(xml_out, "t_source", seqprop_header.forward_props[0].source_header.t_source);
375  write(xml_out, "t_sink", seqprop_header.seqsource_header.t_sink);
376  write(xml_out, "sink_mom", seqprop_header.seqsource_header.sink_mom);
377  write(xml_out, "source_value", source_value);
378  write(xml_out, "twopt_sink", twopt_sink);
379  write(xml_out, "diff", Complex(source_value - twopt_sink));
380  write(xml_out, "norm2_source_value", norm2(source_value));
381  write(xml_out, "norm2_twopt_sink", norm2(twopt_sink));
382  write(xml_out, "norm2_diff", norm2(source_value - twopt_sink));
383  pop(xml_out);
384 
385  }
386  catch(const std::string& e)
387  {
388  QDPIO::cerr << name << ": Caught Exception in sink: " << e << std::endl;
389  QDP_abort(1);
390  }
391 
392 
393  pop(xml_out); // seqprop_test
394 
395  snoop.stop();
396  QDPIO::cout << name << ": total time = "
397  << snoop.getTimeInSeconds()
398  << " secs" << std::endl;
399 
400  QDPIO::cout << name << ": ran successfully" << std::endl;
401 
402  END_CODE();
403  }
404 
405  }
406 
407 }
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
Inline test of sequential propagators.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
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
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 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.
Class for counted reference semantics.
Test sequential propagator.
Make xml file writer.
int j_decay
Definition: meslate.cc:22
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
multi1d< ForwardProp_t > & forward_headers
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
START_CODE()
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.
All sequential source constructors.
Factory for producing quark prop sinks.
Fourier transform phase factor support.
All source smearing.
Factory for producing quark smearing objects.
struct Chroma::InlineSeqPropTestEnv::Params::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)
multi1d< int > sink_mom
Definition: qprop_io.h:95
GroupXML_t seqsrc
Definition: qprop_io.h:93
Mega structure holding a full sequential prop.
Definition: qprop_io.h:140
multi1d< ForwardProp_t > forward_props
Definition: qprop_io.h:144
SeqSource_t seqsource_header
Definition: qprop_io.h:143