CHROMA
inline_mres_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of mres
3  *
4  * Mres calculations
5  */
6 
7 #include "fermact.h"
10 #include "meas/glue/mesplq.h"
11 #include "util/ft/sftmom.h"
12 #include "util/ferm/transf.h"
13 #include "util/info/proginfo.h"
14 #include "io/qprop_io.h"
20 
21 namespace Chroma
22 {
23  namespace InlineMresEnv
24  {
25  namespace
26  {
27  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
28  const std::string& path)
29  {
30  return new InlineMres(InlineMresParams(xml_in, path));
31  }
32 
33  //! Local registration flag
34  bool registered = false;
35  }
36 
37  const std::string name = "MRES";
38 
39  //! Register all the factories
40  bool registerAll()
41  {
42  bool success = true;
43  if (! registered)
44  {
46  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
47  registered = true;
48  }
49  return success;
50  }
51  }
52 
53 
54  // Reader
55  void read(XMLReader& xml, const std::string& path, InlineMresParams::Param_t& input)
56  {
57  XMLReader inputtop(xml, path);
58 
59  if (inputtop.count("FermionAction") != 0)
60  input.fermact = readXMLGroup(inputtop, "FermionAction", "FermAct");
61  }
62 
63 
64  // Writer
65  void write(XMLWriter& xml, const std::string& path, const InlineMresParams::Param_t& input)
66  {
67  push(xml, path);
68 
69  QDPIO::cout << "write mresparams: fermact=XX" << input.fermact.xml << "XX\n";
70 
71  if (input.fermact.xml != "")
72  xml << input.fermact.xml;
73 
74  pop(xml);
75  }
76 
77 
78  // Reader
79  void read(XMLReader& xml, const std::string& path, InlineMresParams::NamedObject_t& input)
80  {
81  XMLReader inputtop(xml, path);
82 
83  read(inputtop, "gauge_id", input.gauge_id);
84  read(inputtop, "prop_id", input.prop_id);
85  }
86 
87 
88  // Writer
89  void write(XMLWriter& xml, const std::string& path, const InlineMresParams::NamedObject_t& input)
90  {
91  push(xml, path);
92  write(xml, "gauge_id", input.gauge_id);
93  write(xml, "prop_id", input.prop_id);
94  pop(xml);
95  }
96 
97 
98  // Param stuff
100 
101  InlineMresParams::InlineMresParams(XMLReader& xml, const std::string& path)
102  {
103  XMLReader inputtop(xml, path);
104 
105  // Read the input
106  try
107  {
108  // The parameters holds the version number
109  read(inputtop, "Param", param);
110 
111  // Read any auxiliary state information
112  if( inputtop.count("StateInfo") == 1 ) {
113  XMLReader xml_state_info(inputtop, "StateInfo");
114  std::ostringstream os;
115  xml_state_info.print(os);
116  stateInfo = os.str();
117  }
118  else {
119  XMLBufferWriter s_i_xml;
120  push(s_i_xml, "StateInfo");
121  pop(s_i_xml);
122  stateInfo = s_i_xml.str();
123  }
124 
125  // Read in the source/propagator info
126  read(inputtop, "NamedObject", named_obj);
127 
128  // Possible alternate XML file pattern
129  if (inputtop.count("xml_file") != 0)
130  {
131  read(inputtop, "xml_file", xml_file);
132  }
133  }
134  catch (const std::string& e)
135  {
136  QDPIO::cerr << "Error reading data: " << e << std::endl;
137  throw;
138  }
139  }
140 
141  void
142  InlineMresParams::write(XMLWriter& xml, const std::string& path)
143  {
144  push(xml, path);
145 
146  Chroma::write(xml, "Param", param);
147  {
148  //QDP::write(xml, "StateInfo", stateInfo);
149  std::istringstream header_is(stateInfo);
150  XMLReader xml_header(header_is);
151  xml << xml_header;
152  }
153  Chroma::write(xml, "NamedObject", named_obj);
154  QDP::write(xml, "xml_file", xml_file);
155 
156  pop(xml);
157  }
158 
159 
160  // Function call
161  void
162  InlineMres::operator()(unsigned long update_no,
163  XMLWriter& xml_out)
164  {
165  // If xml file not empty, then use alternate
166  if (params.xml_file != "")
167  {
168  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
169 
170  push(xml_out, "mres");
171  write(xml_out, "update_no", update_no);
172  write(xml_out, "xml_file", xml_file);
173  pop(xml_out);
174 
175  XMLFileWriter xml(xml_file);
176  func(update_no, xml);
177  }
178  else
179  {
180  func(update_no, xml_out);
181  }
182  }
183 
184 
185  // Function call
186  void
187  InlineMres::func(unsigned long update_no,
188  XMLWriter& xml_out)
189  {
190  START_CODE();
191 
192  StopWatch snoop;
193  snoop.reset();
194  snoop.start();
195 
196  // Test and grab a reference to the gauge field
197  XMLBufferWriter gauge_xml;
198  try
199  {
200  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
201  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
202  }
203  catch( std::bad_cast )
204  {
205  QDPIO::cerr << InlineMresEnv::name << ": caught dynamic cast error"
206  << std::endl;
207  QDP_abort(1);
208  }
209  catch (const std::string& e)
210  {
211  QDPIO::cerr << InlineMresEnv::name << ": std::map call failed: " << e
212  << std::endl;
213  QDP_abort(1);
214  }
215  const multi1d<LatticeColorMatrix>& u =
216  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
217 
218  push(xml_out, "mres");
219  write(xml_out, "update_no", update_no);
220 
221  QDPIO::cout << " MRES" << std::endl;
222 
223  //
224  // Read the prop
225  //
226  LatticePropagator quark_propagator;
228  PropSourceConst_t source_header;
229  std::string stateInfo;
230  XMLReader prop_file_xml, prop_record_xml;
231 
232  try
233  {
234  // Snarf the data into a copy
235  quark_propagator =
236  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_id);
237 
238  // Snarf the source info. This is will throw if the source_id is not there
239  XMLReader prop_file_xml, prop_record_xml;
240  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getFileXML(prop_file_xml);
241  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getRecordXML(prop_record_xml);
242 
243  // Try to invert this record XML into a ChromaProp struct
244  // Also pull out the id of this source
245  {
246  read(prop_record_xml, "/Propagator/ForwardProp", prop_header);
247  read(prop_record_xml, "/Propagator/PropSource", source_header);
248 
249  // Read any auxiliary state information
250  if( prop_record_xml.count("/Propagator/StateInfo") == 1 )
251  {
252  XMLReader xml_state_info(prop_record_xml, "/Propagator/StateInfo");
253  std::ostringstream os;
254  xml_state_info.print(os);
255  stateInfo = os.str();
256  }
257  else
258  {
259  // The user better have supplied something
260  stateInfo = params.stateInfo;
261  }
262  }
263  }
264  catch( std::bad_cast )
265  {
266  QDPIO::cerr << InlineMresEnv::name << ": caught dynamic cast error"
267  << std::endl;
268  QDP_abort(1);
269  }
270  catch (const std::string& e)
271  {
272  QDPIO::cerr << InlineMresEnv::name << ": std::map call failed: " << e
273  << std::endl;
274  QDP_abort(1);
275  }
276 
277  proginfo(xml_out); // Print out basic program info
278 
279  // Write out the input
280  params.write(xml_out, "Input");
281 
282  // Write out the config header
283  write(xml_out, "Config_info", gauge_xml);
284 
285  // Write out the propagator header
286  write(xml_out, "Propagator_file_info", prop_file_xml);
287  write(xml_out, "Propagator_record_info", prop_record_xml);
288 
289  push(xml_out, "Output_version");
290  write(xml_out, "out_version", 1);
291  pop(xml_out);
292 
293  // Calculate some gauge invariant observables just for info.
294  MesPlq(xml_out, "Observables", u);
295 
296  // Basic parameters
297  int j_decay = source_header.j_decay;
298  int t0 = source_header.t_source;
299 
300  // Initialize the slow Fourier transform phases
301  SftMom phases(0, true, j_decay);
302  {
303  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(quark_propagator),
304  phases.getSet());
305 
306  push(xml_out, "Forward_prop_correlator");
307  write(xml_out, "forward_prop_corr", forward_prop_corr);
308  pop(xml_out);
309  }
310 
311 
312  //
313  // Initialize fermion action
314  //
315  std::string ferm_act_str;
316  if (params.param.fermact.xml == "")
317  ferm_act_str = prop_header.fermact.xml;
318  else
319  ferm_act_str = params.param.fermact.xml;
320 
321  std::istringstream xml_s(ferm_act_str);
322  XMLReader fermacttop(xml_s);
323  const std::string fermact_path = "/FermionAction";
324  std::string fermact;
325 
326  try
327  {
328  read(fermacttop, fermact_path + "/FermAct", fermact);
329  }
330  catch (const std::string& e)
331  {
332  QDPIO::cerr << "Error reading fermact: " << e << std::endl;
333  throw;
334  }
335 
336  QDPIO::cout << "FermAct = " << fermact << std::endl;
337 
338  // Make a reader for the stateInfo
339  std::istringstream state_info_is(stateInfo);
340  XMLReader state_info_xml(state_info_is);
341  std::string state_info_path="/StateInfo";
342 
343 
344  //
345  LatticePropagator delta_prop;
346  LatticePropagator deltaSq_prop;
347 
348 
349  try
350  {
351  QDPIO::cout << "Try generic WilsonTypeFermAct actions" << std::endl;
352 
353  // Typedefs to save typing
354  typedef LatticeFermion T;
355  typedef multi1d<LatticeColorMatrix> P;
356  typedef multi1d<LatticeColorMatrix> Q;
357 
358  // Generic Wilson-Type Array stuff
360  TheFermionActionFactory::Instance().createObject(fermact,
361  fermacttop,
362  fermact_path);
363 
364  Handle< FermState<T,P,Q> > state(S_f->createState(u,
365  state_info_xml,
366  state_info_path));
367 
368  LinearOperator<T>* DelLs;
369 
370  // Possible actions
372  OverlapFermActBase* S_ov = dynamic_cast< OverlapFermActBase*>(S_f);
373 
374  if (S_dwf != 0)
375  {
376  DelLs = S_dwf->DeltaLs(state,prop_header.invParam);
377  }
378  else if (S_ov != 0)
379  {
380  DelLs = S_ov->DeltaLs(state);
381  }
382  else
383  {
384  throw std::string("No suitable cast found");
385  }
386 
387  for(int col = 0; col < Nc; col++)
388  {
389  for(int spin = 0; spin < Ns; spin++)
390  {
391  LatticeFermion tmp1, tmp2;
392 
393  // Move component from prop to ferm
394  PropToFerm(quark_propagator, tmp1, col, spin);
395 
396  // Apply DeltaLs -> tmp2 = Delta_Ls tmp1
397  (*DelLs)(tmp2, tmp1, PLUS);
398 
399  FermToProp(tmp2, delta_prop, col, spin);
400  }
401  }
402 
403  delete DelLs;
404  delete S_f;
405  }
406  catch(const std::string& e) {
407  QDPIO::cerr << InlineMresEnv::name << ": Error:" << e << std::endl;
408  QDP_abort(1);
409  }
410  catch(std::bad_cast) {
411  QDPIO::cout << InlineMresEnv::name << ": Action entered is not suitable to be cast to DWF " << std::endl;
412  QDP_abort(1);
413  }
414 
415 
416  multi1d<Double> pseudo_prop_corr = sumMulti(localNorm2(quark_propagator),
417  phases.getSet());
418 
419  multi1d<DComplex> delta_prop_corr = sumMulti(trace(adj(quark_propagator)*delta_prop),
420  phases.getSet());
421 
422  multi1d<DComplex> deltaSq_prop_corr = sumMulti(trace(adj(delta_prop)*delta_prop),
423  phases.getSet());
424 
425  int length = pseudo_prop_corr.size();
426  multi1d<Real> shifted_pseudo(length);
427  multi1d<Real> shifted_delta(length);
428  multi1d<Real> shifted_deltaSq(length);
429 
430  for(int t=0; t<length; t++)
431  {
432  int t_eff( (t - t0 + length) % length ) ;
433  shifted_pseudo[t_eff] = real(pseudo_prop_corr[t]);
434  shifted_delta[t_eff] = real(delta_prop_corr[t]);
435  shifted_deltaSq[t_eff]= real(deltaSq_prop_corr[t]);
436  }
437 
438  push(xml_out, "DeltaProp_correlator");
439  write(xml_out, "delta_prop_corr", shifted_delta);
440  pop(xml_out);
441 
442  push(xml_out, "DeltaSqProp_correlator");
443  write(xml_out, "delta_sq_prop_corr", shifted_deltaSq);
444  pop(xml_out);
445 
446  push(xml_out, "PsuedoPseudo_correlator");
447  write(xml_out, "pseudo_prop_corr", shifted_pseudo);
448  pop(xml_out);
449 
450  pop(xml_out); // mres
451 
452  snoop.stop();
453  QDPIO::cout << InlineMresEnv::name << ": total time = "
454  << snoop.getTimeInSeconds()
455  << " secs" << std::endl;
456 
457  QDPIO::cout << InlineMresEnv::name << ": ran successfully" << std::endl;
458 
459  END_CODE();
460  }
461 
462 }
Inline measurement factory.
Base class for quadratic matter actions (e.g., fermions)
Definition: fermact.h:53
Class for counted reference semantics.
Definition: handle.h:33
Inline measurement of chiral fermion residual mass.
Definition: inline_mres_w.h:53
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
InlineMresParams params
Definition: inline_mres_w.h:71
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
Linear Operator.
Definition: linearop.h:27
Base class for unpreconditioned overlap-like fermion actions.
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
Wilson-like fermion actions.
Definition: fermact.orig.h:403
virtual LinearOperator< T > * DeltaLs(Handle< FermState< T, P, Q > > state, const GroupXML_t &invParam) const =0
Produce a DeltaLs = 1-epsilon^2(H) operator.
Class structure for fermion actions.
Fermion action factories.
All Wilson-type fermion actions.
void PropToFerm(const LatticePropagatorF &b, LatticeFermionF &a, int color_index, int spin_index)
Extract a LatticeFermion from a LatticePropagator.
Definition: transf.cc:226
void FermToProp(const LatticeFermionF &a, LatticePropagatorF &b, int color_index, int spin_index)
Insert a LatticeFermion into a LatticePropagator.
Definition: transf.cc:98
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.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
ForwardProp_t prop_header
Inline mres calculations.
Make xml file writer.
int j_decay
Definition: meslate.cc:22
int t
Definition: meslate.cc:37
Double tmp2
Definition: mesq.cc:30
Named object function std::map.
static bool registered
Local registration flag.
multi1d< LatticeColorMatrix > P
bool registerAll()
Register all the factories.
const std::string name
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
@ PLUS
Definition: chromabase.h:45
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
START_CODE()
void write(XMLWriter &xml, const std::string &path, const InlineMresParams::NamedObject_t &input)
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Definition: pbg5p_w.cc:27
::std::string string
Definition: gtest.h:1979
Base class for unpreconditioned overlap-like fermion actions.
Print out basic info about this program.
Routines associated with Chroma propagator IO.
Fourier transform phase factor support.
Propagator parameters.
Definition: qprop_io.h:75
Parameter structure.
Definition: inline_mres_w.h:26
void write(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineMresParams::Param_t param
struct Chroma::InlineMresParams::NamedObject_t named_obj
Propagator source construction parameters.
Definition: qprop_io.h:27