CHROMA
inline_stag_to_wils.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of propagator
3  *
4  * Propagator calculations
5  */
6 
7 #include "fermact.h"
8 #include "util/ferm/transf.h"
12 #include "meas/glue/mesplq.h"
13 #include "util/ft/sftmom.h"
14 #include "util/info/proginfo.h"
15 #include "util/info/unique_id.h"
19 
21 
22 
23 namespace Chroma
24 {
25  namespace InlineStagToWilsEnv
26  {
27  namespace
28  {
29  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
30  const std::string& path)
31  {
32  return new InlineStagToWils(InlineStagToWilsParams(xml_in, path));
33  }
34 
35  //! Local registration flag
36  bool registered = false;
37  }
38 
39  const std::string name = "STAG_TO_WILS";
40 
41  //! Register all the factories
42  bool registerAll()
43  {
44  bool success = true;
45  if (! registered)
46  {
48  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
49  registered = true;
50  }
51  return success;
52  }
53  } // end namespace
54 
55 
56  //! StagToWils input
57  void read(XMLReader& xml, const std::string& path, InlineStagToWilsParams::NamedObject_t& input)
58  {
59  XMLReader inputtop(xml, path);
60 
61  read(inputtop, "wils_id", input.wils_id);
62  read(inputtop, "stag_id", input.stag_id);
63  }
64 
65  //! StagToWils output
66  void write(XMLWriter& xml, const std::string& path, const InlineStagToWilsParams::NamedObject_t& input)
67  {
68  push(xml, path);
69 
70  write(xml, "stag_id", input.stag_id);
71  write(xml, "wils_id", input.wils_id);
72 
73  pop(xml);
74  }
75 
76 
77  // Param stuff
79 
81  {
82  try
83  {
84  XMLReader paramtop(xml_in, path);
85 
86  if (paramtop.count("Frequency") == 1)
87  read(paramtop, "Frequency", frequency);
88  else
89  frequency = 1;
90 
91  // Read in the output propagator/source configuration info
92  read(paramtop, "NamedObject", named_obj);
93 
94  // Possible alternate XML file pattern
95  if (paramtop.count("xml_file") != 0)
96  {
97  read(paramtop, "xml_file", xml_file);
98  }
99  }
100  catch(const std::string& e)
101  {
102  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
103  QDP_abort(1);
104  }
105  }
106 
107 
108  void
109  InlineStagToWilsParams::writeXML(XMLWriter& xml_out, const std::string& path)
110  {
111  push(xml_out, path);
112 
113  write(xml_out, "NamedObject", named_obj);
114 
115  pop(xml_out);
116  }
117 
118 
119  // Function call
120  void
121  InlineStagToWils::operator()(unsigned long update_no,
122  XMLWriter& xml_out)
123  {
124  // If xml file not empty, then use alternate
125  if (params.xml_file != "")
126  {
127  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
128 
129  push(xml_out, "stag_to_wils");
130  write(xml_out, "update_no", update_no);
131  write(xml_out, "xml_file", xml_file);
132  pop(xml_out);
133 
134  XMLFileWriter xml(xml_file);
135  func(update_no, xml);
136  }
137  else
138  {
139  func(update_no, xml_out);
140  }
141  }
142 
143 
144  // Real work done here
145  void
146  InlineStagToWils::func(unsigned long update_no,
147  XMLWriter& xml_out)
148  {
149  START_CODE();
150 
151  StopWatch snoop;
152  snoop.reset();
153  snoop.start();
154 
155  push(xml_out, "stag_to_wils");
156  write(xml_out, "update_no", update_no);
157 
158  QDPIO::cout << InlineStagToWilsEnv::name << ": propagator conversion" << std::endl;
159 
160  proginfo(xml_out); // Print out basic program info
161 
162  // Write out the input
163  params.writeXML(xml_out, "Input");
164 
165  push(xml_out, "Output_version");
166  write(xml_out, "out_version", 1);
167  pop(xml_out);
168 
169  //
170  // Read in the source along with relevant information.
171  //
172  XMLReader stag_file_xml, stag_record_xml;
173 
174  multi1d<int> t_srce ;
175  int t0;
176  int j_decay;
177  bool make_sourceP = false;
178  bool SmearedSink = false;
179 
180  QDPIO::cout << "Snarf the staggered propagator from a named buffer" << std::endl;
181  try
182  {
183  // Try the cast to see if this is a valid propagator
184  LatticeStaggeredPropagator& stag_tmp =
185  TheNamedObjMap::Instance().getData<LatticeStaggeredPropagator>(params.named_obj.stag_id);
186 
187  // Snarf the propagator info.
188  // This is will throw if the stag_id is not there
189  TheNamedObjMap::Instance().get(params.named_obj.stag_id).getFileXML(stag_file_xml);
190  TheNamedObjMap::Instance().get(params.named_obj.stag_id).getRecordXML(stag_record_xml);
191 
192  // Try to invert this record XML into a source struct
193  // First identify what kind of source might be here
194  if (stag_record_xml.count("/Propagator") != 0)
195  {
196  PropSourceConst_t source_header;
197 
198  read(stag_record_xml, "/Propagator/PropSource", source_header);
199  j_decay = source_header.j_decay;
200  t0 = source_header.t_source;
201  t_srce = source_header.getTSrce() ;
202  //Need to figure out what you do for Wall noise, or Corner sources
203  //plane wall or noise source should not be supported.
204  // corner sources do not exist...
205  // All this should be fixed in the future
206  make_sourceP = true;
207  }
208  // When smeared sink propagators are found
209  // I need to do something different
210  else if (stag_record_xml.count("/SinkSmear") != 0)
211  {
212  SmearedSink=true ;
213  PropSourceConst_t source_header;
214 
215  read(stag_record_xml, "/SinkSmear/PropSource", source_header);
216  j_decay = source_header.j_decay;
217  t0 = source_header.t_source;
218  t_srce = source_header.getTSrce() ;
219  //Need to figure out what you do for Wall noise, or Corner sources
220  //plane wall or noise source should not be supported.
221  // corner sources do not exist...
222  // All this should be fixed in the future
223  make_sourceP = true;
224  }
225 
226  else
227  {
228  throw std::string("No appropriate header found");
229  }
230 
231  // Write out the source header
232  write(xml_out, "StaggeredProp_file_info", stag_file_xml);
233  write(xml_out, "StaggeredProp_record_info", stag_record_xml);
234  }
235  catch (std::bad_cast)
236  {
237  QDPIO::cerr << InlineStagToWilsEnv::name << ": caught dynamic cast error"
238  << std::endl;
239  QDP_abort(1);
240  }
241  catch (const std::string& e)
242  {
243  QDPIO::cerr << InlineStagToWilsEnv::name << ": error extracting source_header: " << e << std::endl;
244  QDP_abort(1);
245  }
246 
247  // Should be a valid cast now
248  const LatticeStaggeredPropagator& stag_prop =
249  TheNamedObjMap::Instance().getData<LatticeStaggeredPropagator>(params.named_obj.stag_id);
250 
251  QDPIO::cout << "Staggered propagator successfully read and parsed" << std::endl;
252 
253  // Sanity check - write out the norm2 of the source in the Nd-1 direction
254  // Use this for any possible verification
255  {
256  // Initialize the slow Fourier transform phases
257  SftMom phases(0, true, Nd-1);
258 
259  multi1d<Double> stag_corr = sumMulti(localNorm2(stag_prop),
260  phases.getSet());
261 
262  push(xml_out, "StaggeredProp_correlator");
263  write(xml_out, "stag_prop_corr", stag_corr);
264  pop(xml_out);
265  }
266 
267  //
268  // Get the Wilson propagator
269  //
270  try
271  {
272  TheNamedObjMap::Instance().create<LatticePropagator>(params.named_obj.wils_id);
273  }
274  catch (std::bad_cast)
275  {
276  QDPIO::cerr << InlineStagToWilsEnv::name << ": caught dynamic cast error"
277  << std::endl;
278  QDP_abort(1);
279  }
280  catch (const std::string& e)
281  {
282  QDPIO::cerr << InlineStagToWilsEnv::name << ": error creating wils_prop: " << e << std::endl;
283  QDP_abort(1);
284  }
285 
286  // Cast should be valid now
287  LatticePropagator& wils_prop =
288  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.wils_id);
289 
290  StopWatch swatch;
291 
292 
293  if (!make_sourceP){
294  QDPIO::cerr<<"Error: Only forward props supported" << std::endl;
295  QDP_abort(1);
296  }
297 
298  LatticeColorMatrix xx = peekSpin(stag_prop,0,0) ;
299  wils_prop = zero ;
300  for(int s(0);s<Ns;s++){
301  pokeSpin(wils_prop,xx,s,s);
302  }//diagonal in spin
303 
304  swatch.start() ;
305  //Multiply the source by Gamma(1)^x Gamma(2)^y Gamma(4)^z Gamma(8)^t
306  QDPIO::cout<<"SOURCE: " ;
307  for(int d(0);d<Nd;d++)
308  QDPIO::cout<<t_srce[d]<<" ";
309  QDPIO::cout<<std::endl;
310  SpinMatrix Omega = 1.0 ;
311  int g(0);
312  for(int mu(0);mu<Nd;mu++)
313  g = g | ((t_srce[mu]%2)<<mu) ;
314  QDPIO::cout<<"SOURCE gamma: "<<g<<std::endl ;
315  Omega = Gamma(g)*Omega ;
316 
317  //now the sink location
318  LatticeSpinMatrix lOmega=1.0 ;
319  LatticeInteger lg = zero;
320  for(int mu(0);mu<Nd;mu++){
321  lg = lg | ((Layout::latticeCoordinate(mu)%2)<<mu) ;
322  }
323  for(int g(0);g<(Ns*Ns-1);g++)//loop over all possible gamma matrices
324  lOmega = where((lg==g),Gamma(g)*lOmega,lOmega) ;
325 
326  wils_prop = lOmega*wils_prop*adj(Omega) ;
327 
328  swatch.stop();
329  QDPIO::cout << "Staggered Propagator coverted to Wilson: time= "
330  << swatch.getTimeInSeconds()
331  << " secs" << std::endl;
332 
333 
334  // Sanity check - write out the propagator (pion) correlator in the Nd-1 direction
335  {
336  // Initialize the slow Fourier transform phases
337  SftMom phases(0, true, Nd-1);
338 
339  multi1d<Double> prop_corr=sumMulti(localNorm2(wils_prop),phases.getSet());
340 
341  push(xml_out, "WilsonProp_correlator");
342  write(xml_out, "wils_corr", prop_corr);
343  pop(xml_out);
344  }
345 
346  // Save the propagator info
347  try
348  {
349  QDPIO::cout << "Start writing propagator info" << std::endl;
350 
351  XMLBufferWriter file_xml;
352  push(file_xml, "propagator");
353  write(file_xml, "id", uniqueId()); // NOTE: new ID form
354  pop(file_xml);
355 
356  XMLBufferWriter record_xml;
357  if (make_sourceP)
358  {
359  if(SmearedSink){
360  XMLReader xml_tmp(stag_record_xml, "/SinkSmear");
361 
362  push(record_xml, "SinkSmear");
363  //write(record_xml, "ForwardProp", params.param);
364  //record_xml << params.stateInfo; // write out the stateinfo - might be empty
365  record_xml << xml_tmp; // write out all the stuff under MakeSource
366  pop(record_xml);
367  }
368  else{
369  XMLReader xml_tmp(stag_record_xml, "/Propagator");
370 
371  push(record_xml, "Propagator");
372  //write(record_xml, "ForwardProp", params.param);
373  //record_xml << params.stateInfo; // write out the stateinfo - might be empty
374  record_xml << xml_tmp; // write out all the stuff under MakeSource
375  pop(record_xml);
376  }
377  }
378 
379  // Write the propagator xml info
380  TheNamedObjMap::Instance().get(params.named_obj.wils_id).setFileXML(file_xml);
381  TheNamedObjMap::Instance().get(params.named_obj.wils_id).setRecordXML(record_xml);
382 
383  QDPIO::cout << "Propagator successfully updated" << std::endl;
384  }
385  catch (std::bad_cast)
386  {
387  QDPIO::cerr << InlineStagToWilsEnv::name << ": caught dynamic cast error"
388  << std::endl;
389  QDP_abort(1);
390  }
391  catch (const std::string& e)
392  {
393  QDPIO::cerr << InlineStagToWilsEnv::name << ": error extracting prop_header: " << e << std::endl;
394  QDP_abort(1);
395  }
396 
397  pop(xml_out); // propagator
398 
399  snoop.stop();
400  QDPIO::cout << InlineStagToWilsEnv::name << ": total time = "
401  << snoop.getTimeInSeconds()
402  << " secs" << std::endl;
403 
404  QDPIO::cout << InlineStagToWilsEnv::name << ": ran successfully" << std::endl;
405 
406  END_CODE();
407  }
408 
409 }
Inline measurement factory.
Asqtad staggered fermion action.
Inline measurement of staggered-to-wilson conversion.
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.
InlineStagToWilsParams params
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
int mu
Definition: cool.cc:24
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.
multi1d< int > t_srce
Inline construction of propagator.
Make xml file writer.
int j_decay
Definition: meslate.cc:22
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
pop(xml_out)
DComplex d
Definition: invbicg.cc:99
START_CODE()
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.
Fourier transform phase factor support.
struct Chroma::InlineStagToWilsParams::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)
Propagator source construction parameters.
Definition: qprop_io.h:27
multi1d< int > getTSrce() const
Definition: qprop_io.cc:120
Generate a unique id.