CHROMA
dilution_quark_source_const_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Dilution scheme specified by MAKE_SOURCE and PROPAGATOR calls
3  *
4  */
5 
6 #include "handle.h"
11 #include "meas/sources/zN_src.h"
12 #include "util/ft/sftmom.h"
13 
14 
15 namespace Chroma
16 {
17 
18  // Read parameters
19  void read(XMLReader& xml, const std::string& path, DilutionQuarkSourceConstEnv::Params& param)
20  {
22  param = tmp;
23  }
24 
25 
26  // Writer
27  void write(XMLWriter& xml, const std::string& path, const DilutionQuarkSourceConstEnv::Params& param)
28  {
29  param.writeXML(xml, path);
30  }
31 
32 
33  /*!
34  * \ingroup hadron
35  *
36  *
37  */
38  namespace DilutionQuarkSourceConstEnv
39  {
40  //Read Quark dilution files per timeslice
42  {
43  XMLReader inputtop(xml, path);
44 
45  read(inputtop, "DilutionFiles", input.dilution_files);
46  }
47 
48  //Read Quark timeslice files
49  void read(XMLReader& xml, const std::string& path, DilutionQuarkSourceConstEnv::Params::QuarkFiles_t& input)
50  {
51  XMLReader inputtop(xml, path);
52 
53  read(inputtop, "TimeSliceFiles", input.timeslice_files);
54  }
55 
56 
57  //Write Quark dilution files
59  {
60  push(xml, path);
61  write(xml, "dilution_files", input.dilution_files);
62  pop(xml);
63  }
64 
65  //Write Quark time slice files
66  void write(XMLWriter& xml, const std::string& path, const DilutionQuarkSourceConstEnv::Params::QuarkFiles_t& input)
67  {
68  push(xml, path);
69  write(xml, "timeslice_files", input.timeslice_files);
70  pop(xml);
71  }
72 
73 
74  //! Initialize
76  {
77  UseSourceHeaderSmearing = false ;
78  }
79 
80 
81  //! Read parameters
82  Params::Params(XMLReader& xml, const std::string& path)
83  {
84  XMLReader paramtop(xml, path);
85 
86  int version;
87  read(paramtop, "version", version);
88 
89  switch (version)
90  {
91  case 1:
92  /**************************************************************************/
93  break;
94 
95  default :
96  /**************************************************************************/
97 
98  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
99  QDP_abort(1);
100  }
101 
102  UseSourceHeaderSmearing = true ;
103  read(paramtop, "QuarkFiles", quark_files);
104  if(paramtop.count("UseSourceHeaderSmearing")!=0)
105  read(paramtop, "UseSourceHeaderSmearing", UseSourceHeaderSmearing);
106  }
107 
108 
109 
110  // Writer
111  void Params::writeXML(XMLWriter& xml, const std::string& path) const
112  {
113  push(xml, path);
114 
115  int version = 1;
116  write(xml, "version", version);
117  write(xml, "QuarkFiles", quark_files);
119  write(xml, "UseSourceHeaderSmearing", UseSourceHeaderSmearing);
120  pop(xml);
121  }
122 
123  // Anonymous namespace for registration
124  namespace
125  {
126  DilutionScheme<LatticeFermion>* createScheme(XMLReader& xml_in,
127  const std::string& path)
128  {
129  return new ConstDilutionScheme(Params(xml_in, path));
130  }
131 
132  //! Local registration flag
133  bool registered = false;
134  }
135 
136  const std::string name = "DILUTION_QUARK_SOURCE_CONST_FERM";
137 
138  //! Register all the factories
139  bool registerAll()
140  {
141  bool success = true;
142 
143  if (! registered)
144  {
145  success &= TheFermDilutionSchemeFactory::Instance().registerObject(name, createScheme);
146  registered = true;
147  }
148  return success;
149  }
150 
151 
152 
155  {
156  bool val = false;
157 
158  //Check if the seeds are the same
159  Seed seedA, seedB;
160 
161  std::istringstream xml_a(dilA.source_header.source.xml);
162  XMLReader rdr_a(xml_a);
163 
164  std::istringstream xml_b(dilB.source_header.source.xml);
165  XMLReader rdr_b(xml_b);
166 
167 
168  read(rdr_a, "/Source/ran_seed" , seedA);
169  read(rdr_b, "/Source/ran_seed" , seedB);
170 
171  val |= toBool(seedA != seedB);
172  if (val)
173  {
174  QDPIO::cerr<< "random seeds are not the same." <<std::endl;
175  }
176 
177  //Check Spatial mask and spatial mask size
178 
179  multi1d<int> mask_sizeA, mask_sizeB, cmaskA, cmaskB, smaskA, smaskB;
180  multi1d< multi1d<int> > maskA, maskB;
181 
182  read(rdr_a, "/Source/spatial_mask_size" , mask_sizeA);
183  read(rdr_b, "/Source/spatial_mask_size" , mask_sizeB);
184  val |= toBool(mask_sizeA != mask_sizeB);
185  if (val)
186  {
187  QDPIO::cerr<< "spatial mask sizes are not the same." <<std::endl;
188  }
189 
190  read(rdr_a, "/Source/spatial_mask" , maskA);
191  read(rdr_b, "/Source/spatial_mask" , maskB);
192  val |= toBool(maskA != maskB);
193  if (val)
194  {
195  QDPIO::cerr<< "spatial masks are not the same." <<std::endl;
196  }
197 
198  read(rdr_a, "/Source/color_mask" , cmaskA);
199  read(rdr_b, "/Source/color_mask" , cmaskB);
200  val |= toBool(maskA != maskB);
201  if (val)
202  {
203  QDPIO::cerr<< "color masks are not the same." <<std::endl;
204  }
205 
206  read(rdr_a, "/Source/spin_mask" , smaskA);
207  read(rdr_b, "/Source/spin_mask" , smaskB);
208  val |= toBool(maskA != maskB);
209  if (val)
210  {
211  QDPIO::cerr<< "spin masks are not the same." <<std::endl;
212  }
213 
214  return val;
215 
216  }
217  //-------------------------------------------------------------------------------
218  // Function call
220  {
221  START_CODE();
222 
223  StopWatch snoop;
224  snoop.reset();
225  snoop.start();
226 
227  //
228  // Read the soultion headers
229  //
230  StopWatch swatch;
231  swatch.reset();
232  swatch.start();
233 
234  //zN source N
235  int N;
236 
237  try
238  {
239 
240  bool initq = false;
241  Real kappa;
242 
243  QDPIO::cout << "Attempt to read solutions " << std::endl;
244 
246 
247  QDPIO::cout<< "time_slices.size = " << quark.time_slices.size() << std::endl;
248 
249  for (int t0 = 0 ; t0 < quark.time_slices.size() ; ++t0 )
250  {
251  quark.time_slices[t0].dilutions.resize(
252  params.quark_files.timeslice_files[t0].dilution_files.size() );
253 
254  QDPIO::cout << "dilutions.size = " <<
255  quark.time_slices[t0].dilutions.size() << std::endl;
256 
257  int time;
258 
259  for(int dil = 0; dil < quark.time_slices[t0].dilutions.size(); ++dil)
260  {
261  quark.time_slices[t0].dilutions[dil].soln_file =
262  params.quark_files.timeslice_files[t0].dilution_files[dil];
263 
264  XMLReader file_xml, record_xml, record_xml_source;
265 
266  QDPIO::cout << "reading file = " <<
267  quark.time_slices[t0].dilutions[dil].soln_file << std::endl;
268 
269  QDPFileReader from(file_xml,
270  quark.time_slices[t0].dilutions[dil].soln_file, QDPIO_SERIAL);
271 
272  //Use the record xml only, throw away the lattice fermion
273  LatticeFermion junk;
274  read(from, record_xml, junk);
275  close(from);
276 
277  read(record_xml, "/Propagator/PropSource",
278  quark.time_slices[t0].dilutions[dil].source_header);
279  read(record_xml, "/Propagator/ForwardProp",
280  quark.time_slices[t0].dilutions[dil].prop_header);
281 
282  //read the current N
283  int currN;
284  read(record_xml, "/Propagator/PropSource/Source/N", currN);
285 
286  if (!initq)
287  {
288  read(record_xml, "/Propagator/PropSource/Source/ran_seed",
289  quark.seed);
290 
291  read(record_xml, "/Propagator/PropSource/Source/N", N);
292  quark.decay_dir =
293  quark.time_slices[t0].dilutions[dil].source_header.j_decay;
294 
295  //Test that kappa is the same for all dilutions of this
296  //quark
297  std::istringstream xml_k(
298  quark.time_slices[t0].dilutions[dil].prop_header.fermact.xml);
299  XMLReader proptop(xml_k);
300 
301  if ( toBool(proptop.count("/FermionAction/Kappa") != 0) )
302  {
303  read(proptop, "/FermionAction/Kappa", kappa);
304  }
305  else
306  {
307  Real mass;
308  read(proptop, "/FermionAction/Mass", mass);
310  }
311 
312  //Test that config is the same for every dilution
313  XMLReader xml_tmp(record_xml, "/Propagator/Config_info");
314  std::ostringstream os;
315  xml_tmp.print(os);
316 
317  cfgInfo = os.str();
318 
319  initq = true;
320  }
321 
322  Real kappa2;
323  std::istringstream xml_k2(
324  quark.time_slices[t0].dilutions[dil].prop_header.fermact.xml);
325  XMLReader proptop2(xml_k2);
326 
327 
328  if ( toBool(proptop2.count("/FermionAction/Kappa") != 0) )
329  {
330  read(proptop2, "/FermionAction/Kappa", kappa2);
331  }
332  else
333  {
334  Real mass;
335  read(proptop2, "/FermionAction/Mass", mass);
336  kappa2 = massToKappa(mass);
337  }
338 
339  if ( toBool(kappa != kappa2) )
340  {
341  QDPIO::cerr << "Kappa is not the same for all dilutions: t0=" <<
342  t0 << " dil= "<< dil << " kappa2 = "<< kappa2 << std::endl;
343 
344  QDP_abort(1);
345  }
346 
347  if (currN != N)
348  {
349  QDPIO::cerr << "N is not the same for all dilutions: t0 = " <<
350  t0 << " dil = " << dil << std::endl;
351  }
352 
353  //Test that t0 is the same for all dilutions on this timeslice
354  //grab the first t0 to prime the process
355 
356  if (dil == 0)
357  {
358  time = quark.time_slices[t0].dilutions[dil].source_header.t_source;
359  }
360 
361  if (time != quark.time_slices[t0].dilutions[dil].source_header.t_source)
362  {
363  QDPIO::cerr << "t0's DO NOT MATCH FOR ALL DILUTIONS ON TIME SLICE "
364  << t0 << std::endl;
365 
366  QDP_abort(1);
367  }
368 
369 
370  //Test that each t0 has the same dilutions per timeslice
371  if ( quark.time_slices[t0].dilutions[dil] !=
372  quark.time_slices[0].dilutions[dil] )
373  {
374  QDPIO::cerr << "Dilutions do not match on time slice " <<
375  t0 << " dil = "<< dil<< std::endl;
376 
377  QDP_abort(1);
378  }
379 
380  //Test that this dilution element was created on correct cfg
381  std::string currCfgInfo;
382  {
383  XMLReader xml_tmp(record_xml, "/Propagator/Config_info");
384  std::ostringstream os;
385  xml_tmp.print(os);
386 
387  currCfgInfo = os.str();
388  }
389 
390  if (cfgInfo != currCfgInfo)
391  {
392  QDPIO::cerr << "Cfgs do not match on time slice " <<
393  t0 << " dil = "<< dil<< std::endl;
394 
395  QDP_abort(1);
396  }
397 
398  }//dil
399 
400  quark.time_slices[t0].t0 = time;
401 
402  }//t0
403 
404 
405 #if 0
406 #warning "Turned off the sanity check that the dilutions summed to a unity operator on a time-slice"
407  //Ensure that the given dilutions form a full dilution scheme per
408  //timeslice. Only need to check a single timeslice as
409  //we have guaranteed the same dilutions per timeslice
410 
411  LatticeFermion quark_noise; // noisy source on entire lattice
413  zN_src(quark_noise, N);
414 
415 
416  for (int dil = 0 ; dil < quark.time_slices[0].dilutions.size() ; ++dil)
417  {
418  LatticeFermion source = dilutedSource(0, dil);
419  quark_noise -= source;
420  }
421 
422  SftMom phases_nomom(0, true,
423  quark.time_slices[0].dilutions[0].source_header.j_decay);
424 
425  Double dcnt = norm2(quark_noise,
426  phases_nomom.getSet()[quark.time_slices[0].t0] );
427 
428  if (toDouble(dcnt) != 0.0)
429  {
430  QDPIO::cerr << "Not a complete dilution scheme per timeslice" <<
431  std::endl;
432 
433  QDP_abort(1);
434  }
435 #endif
436 
437  } //try
438  catch (const std::string& e)
439  {
440  QDPIO::cerr << "Error extracting headers: " << e << std::endl;
441  QDP_abort(1);
442  }
443  swatch.stop();
444 
445  QDPIO::cout << "Source and solution headers successfully read: time = "
446  << swatch.getTimeInSeconds()
447  << " secs" << std::endl;
448 
449 
450  END_CODE();
451  } // init
452 
453 
454 
455  //Create and return the diluted source
456  //For gauge invariance testing reasons, this routine could be changed
457  //to get the source from the named object std::map
458  LatticeFermion ConstDilutionScheme::dilutedSource(int t0, int dil ) const
459  {
461  quark.time_slices[t0].dilutions[dil];
462 
463 /*
464 //For now read the source
465 LatticeFermion sour;
466 
467 std::string filename =
468 params.quark_files.timeslice_files[t0].dilution_files[dil];
469 
470 filename.erase(0,9);
471 
472 std::string source_filename = "zN_source" + filename;
473 
474 XMLReader file_xml, record_xml;
475 
476 QDPIO::cout << "reading file = " << source_filename << std::endl;
477 QDPFileReader from(file_xml, source_filename, QDPIO_SERIAL);
478 
479 read(from, record_xml, sour);
480 */
481 
482 
483  //Dummy gauge field to send to the source construction routine;
484  multi1d<LatticeColorMatrix> dummy;
485 
486 
487  // Build source construction
488  QDPIO::cout << "Source_id = " << qq.source_header.source.id << std::endl;
489  QDPIO::cout << "Source = XX" << qq.source_header.source.xml << "XX" << std::endl;
490 
491  std::istringstream xml_s(qq.source_header.source.xml);
492  XMLReader sourcetop(xml_s);
493 
495  {
496  QDPIO::cerr << "Expected source_type = " << DiluteZNQuarkSourceConstEnv::getName() << std::endl;
497  QDP_abort(1);
498  }
499 
500  // Manually create the params so I can peek into them and use the source constructor
501  DiluteZNQuarkSourceConstEnv::Params srcParams(sourcetop,
503 
505  QDPIO::cout<<name
506  <<": Will NOT use Smearing/displacement options specified in the header\n"<<std::endl ;
507  srcParams.smear = false ;
508  }
509  else{
510  QDPIO::cout<<name<<": Smearing/displacement not implemented\n"<<std::endl ;
511  QDPIO::cout<<name
512  <<": Will NOT use Smearing/displacement options specified in the header\n"<<std::endl ;
513  srcParams.smear = false ;
514  }
515 
517 
519 
520 
521  LatticeFermion sour = srcConst(dummy);
522 
523 
524  /*
525  multi1d<int> orig(4);
526  for (int i = 0 ; i < 4 ; ++i)
527  {
528  orig=0;
529  }
530 
531  LatticeColorVector vtr = peekSpin(sour, 2);
532  LatticeComplex comp = peekColor( vtr , 0 );
533  QDPIO::cout<< "Sourceval = "<<
534  peekSite( comp, orig ) << std::endl;
535  */
536 
537  return sour;
538 
539  } //dilutedSource
540 
541 
542  LatticeFermion ConstDilutionScheme::dilutedSolution(int t0, int dil) const
543  {
544 
545  const std::string & filename = quark.time_slices[t0].dilutions[dil].soln_file;
546 
547  LatticeFermion soln;
548 
549  XMLReader file_xml, record_xml;
550 
551  QDPIO::cout << "reading file = " << filename << std::endl;
552  QDPFileReader from(file_xml, filename, QDPIO_SERIAL);
553 
554  read(from, record_xml, soln);
555 
556 /*
557  multi1d<int> orig(4);
558  for (int i = 0 ; i < 4 ; ++i)
559  {
560  orig=0;
561  }
562 
563  LatticeColorVector vtr = peekSpin(soln, 2);
564  LatticeComplex comp = peekColor( vtr , 0 );
565  QDPIO::cout<< "Sinkval = "<<
566  peekSite( comp, orig ) << std::endl;
567 
568 */
569  return soln;
570  }
571 
572 
573 
574  } // namespace DilutionQuarkSourceConstEnv
575 
576 }// namespace Chroma
Random complex Z(N) sources using dilution.
Dilution scheme constructed by propagator solutions over diluted MAKE_SOURCE calls.
LatticeFermion dilutedSolution(int t0, int dil) const
Return the solution std::vector corresponding to the diluted source.
LatticeFermion dilutedSource(int t0, int dil) const
Return the diluted source std::vector.
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
Random Z(N) source construction using dilution.
Dilution scheme inferred from pre-generated solutions.
Factory for dilution schemes.
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.
Real massToKappa(const Real &Mass)
Convert a Kappa to a mass.
Definition: param_io.cc:31
void zN_src(LatticeFermion &a, int N)
Volume source of Z(N) noise.
Definition: zN_src.cc:41
Class for counted reference semantics.
void setrn(int iseed[4])
Definition: make_seeds.cc:38
Named object function std::map.
static bool registered
Local registration flag.
std::string getName()
Return the name.
void write(XMLWriter &xml, const std::string &path, const DilutionQuarkSourceConstEnv::Params::QuarkFiles_t::TimeSliceFiles_t &input)
bool operator!=(const QuarkSourceSolutions_t::TimeSlices_t::Dilutions_t &dilA, const QuarkSourceSolutions_t::TimeSlices_t::Dilutions_t &dilB)
void read(XMLReader &xml, const std::string &path, DilutionQuarkSourceConstEnv::Params::QuarkFiles_t::TimeSliceFiles_t &input)
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
Double mass
Definition: pbg5p_w.cc:54
pop(xml_out)
START_CODE()
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
int kappa
Definition: pade_trln_w.cc:112
Real dummy
Definition: qtopcor.cc:36
Fourier transform phase factor support.
Random complex Z(N) sources using dilution.
void writeXML(XMLWriter &xml_out, const std::string &path) const
Volume source of Z(N) noise.