Paramotopy
parallel parameter homotopy through bertini
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
failed_paths.cpp
Go to the documentation of this file.
1 #include "failed_paths.hpp"
2 
3 
4 //the master function for doing stuff to the failed points. called by paramotopy's main.
5 
6 void failinfo::MainMenu(ProgSettings & paramotopy_settings, runinfo & paramotopy_info){
7 
8  //make sure the run was completed.
9  if (!paramotopy_info.test_if_finished()) {
10  std::cout << "\n\nthe run for " << paramotopy_info.inputfilename << " appears not completed. please complete the run." << std::endl;
11  return; //run was not completed, ought not continue.
12  }
13 
14  //set settings for path failure.
15 
16  initial_fails.clear();
17  master_fails.clear();
18  terminal_fails.clear();
19 
20  failinfo::find_failed_paths(paramotopy_info,0,0);
21  initial_fails[0] = this->master_fails; //seed the data
22 
23  boost::filesystem::path makeme = paramotopy_info.base_dir;
24  makeme /= "failure_analysis";
25  boost::filesystem::create_directory(makeme);
26 
27 
28  failinfo::RecoverProgress(paramotopy_info);//gets how far we were
29 
30  paramotopy_settings.set_path_failure_settings();//sets the current settings from the base settings.
31  std::cout << "current iteration " << current_iteration << std::endl;
32  std::cout << "\nCurrently " << this->totalfails << " points with path failures.\n";
33  std::stringstream menu;
34  menu << "\n\nPath Failure Menu:\n\n"
35  << "1) ReRun Failed Paths\n"
36  << "2) Clear Failed Path Data (start over)\n"
37  << "3) Change path failure settings (resets tolerance tightening)\n"
38  << "4) Report failed paths to screen\n"
39  << "*\n"
40  << "0) Go Back\n"
41  << "\n: ";
42  int choice = -1001;
43  while (choice!=0) {
44  paramotopy_settings.DisplayCurrentSettings("PathFailure");
45  choice = get_int_choice(menu.str(),0,4);
46 
47  switch (choice) {
48  case 0:
49  std::cout << "exiting path failure\n";
50  paramotopy_info.GetPrevRandom();//restore to main random values
51  break;
52 
53  case 1:
54  failinfo::PerformAnalysis(paramotopy_settings, paramotopy_info);
55  break;
56 
57  case 2:
58  //delete path failure analysis files, start over
59  if (get_int_choice("are you sure? 0 no, 1 yes\n: ",0,1)==1) {
60  failinfo::StartOver(paramotopy_info);
61  }
62  paramotopy_settings.set_path_failure_settings();
63  break;
64 
65  case 3:
66  paramotopy_settings.PathFailureMenu();
67  paramotopy_settings.set_path_failure_settings();//sets the current settings from the base
68  break;
69 
70  case 4:
71  failinfo::report_failed_paths(paramotopy_info);
72  break;
73 
74  default:
75 
76  break;
77  }
78  paramotopy_info.UpdateAndSave();
79 
80  }
81 
82 
83 
84  return;
85 
86 
87 }
88 
89 
90 void failinfo::StartOver(runinfo & paramotopy_info){
91 
92  boost::filesystem::path dirtosearch = paramotopy_info.base_dir;
93  dirtosearch /= "failure_analysis";
94  std::vector< boost::filesystem::path > found_runs = FindDirectories(dirtosearch, "^pass");
95 
96  for (int ii = 0; ii<int(found_runs.size()); ++ii) {
97  boost::filesystem::remove_all(found_runs[ii]);
98  }
99 
100  this->master_fails.clear();
101  this->initial_fails.clear();
102  this->terminal_fails.clear();
103 
104  paramotopy_info.location = paramotopy_info.base_dir;
105  failinfo::find_failed_paths(paramotopy_info,0,0);
106  initial_fails[0] = this->master_fails;
107 
108 
109  this->current_iteration=0;
110  failinfo::set_location_fail(paramotopy_info);
111  failinfo::write_successful_resolves(paramotopy_info);
112  paramotopy_info.location = paramotopy_info.base_dir;
113 
114  failinfo::write_successful_resolves(paramotopy_info);
115 
116 
117 
118  paramotopy_info.GetPrevRandom();
119 
120 
121  return;
122 }
123 
124 
125 
126 
127 
128 
129 
130 
132 void failinfo::RecoverProgress(runinfo & paramotopy_info){
133 
134 
135  //first, we need to set current folder number
136  boost::filesystem::path dirtosearch = paramotopy_info.base_dir;
137  std::vector< boost::filesystem::path > failure_paths = FindDirectories(dirtosearch,"^failure_analysis");
138  if (failure_paths.size()==0) {
139  this->current_iteration=0;
140 // failinfo::set_location_fail(paramotopy_info);
141  failinfo::write_successful_resolves(paramotopy_info);
142  paramotopy_info.location = paramotopy_info.base_dir;
143  }
144  else{
145  dirtosearch /= "failure_analysis";
146 
147  std::vector< boost::filesystem::path > found_runs = FindDirectories(dirtosearch, "^pass"); // carat means beginning is `pass'
148  int tmpiteration;
149  if (found_runs.size()==0) {
150  this->current_iteration=0;
151  // failinfo::set_location_fail(paramotopy_info);
152  failinfo::write_successful_resolves(paramotopy_info);
153  paramotopy_info.location = paramotopy_info.base_dir;
154  }
155  else{
156  int highestiteration = -1;
157  for (int ii = 0; ii<int(found_runs.size()); ++ii) {
158  std::cout << "found " << found_runs[ii].string() << std::endl;
159  boost::filesystem::path tmppath = found_runs[ii];
160  tmppath /= "info";
161  std::ifstream fin(tmppath.c_str());
162  std::string tmpstr;
163  getline(fin,tmpstr);
164  std::stringstream ss;
165  ss << tmpstr;
166  ss >> tmpiteration;
167  fin.close();
168 
169 
170 
171  if (!TestIfFinished(found_runs[ii])){
172  std::cout << "removing folder " << found_runs[ii] << " because was not finished..." << std::endl;
173  boost::filesystem::remove_all(found_runs[ii]);
174  continue;
175  }
176 
177  if (tmpiteration > highestiteration){
178  highestiteration = tmpiteration;
179  }
180 
181 
182 
183  this->current_iteration = tmpiteration;
184  failinfo::set_location_fail(paramotopy_info);
185  failinfo::find_failed_paths(paramotopy_info,1,current_iteration+1);
186 
187  if (current_iteration>0) {
189  }
190 
191 
192 
193  }
194 
195 
196  this->current_iteration = highestiteration+1;
197  failinfo::set_location_fail(paramotopy_info);
198 
199  datagatherer lets_gather_some_data(paramotopy_info.base_dir,paramotopy_info.fundamental_dir,paramotopy_info.numvariables);
200  std::map< int, point > successful_resolves = lets_gather_some_data.ReadSuccessfulResolves();
201  failinfo::make_master_from_recovered(successful_resolves);
202 
203 
204  }
205 
206 
207  }
208 
209 
210 // failinfo::report_restored_data();
211 
212 
213  return;
214 }
215 
217 
218  std::map< int, std::vector< point> >::iterator iter;
219 
220  std::cout << "initial:" << std::endl;
221  for (iter=initial_fails.begin(); iter!=initial_fails.end(); iter++) {
222  std::cout << iter->first << std::endl;
223 
224  for (int ii=0; ii<int(iter->second.size()); ++ii) {
225  std::cout << iter->second[ii].index << std::endl;
226  }
227  }
228 
229  std::cout << "terminal:" << std::endl;
230  for (iter=terminal_fails.begin(); iter!=terminal_fails.end(); iter++) {
231  for (int ii=0; ii<int(iter->second.size()); ++ii) {
232  std::cout << iter->second[ii].index << std::endl;
233  }
234  }
235 
236  std::cout << "master:" << std::endl;
237  for (int ii=0; ii< int(master_fails.size()); ++ii) {
238  std::cout << master_fails[ii].index << std::endl;
239  }
240  return;
241 }
242 
243 
244 
245 void failinfo::make_master_from_recovered(std::map< int, point > successful_resolves){
246 
247 // std::cout << "successful_resolves has " << successful_resolves.size() << " elements." << std::endl;
248 
249  std::map< int, point >::iterator iter;
250  std::vector< point > tmpcrap;
251 //TODO: this really needs to be rewritten to be memory efficient.
252  for (iter=successful_resolves.begin(); iter!= successful_resolves.end(); iter++) {
253 
254 // std::cout << iter->first << std::endl;
255 
256  tmpcrap.push_back(iter->second);
257 
258  }
259 
260  std::sort(tmpcrap.begin(),tmpcrap.end());
261 
262  master_fails = tmpcrap;
263 
264  return;
265 }
266 
267 
268 
269 void failinfo::set_location_fail(runinfo & paramotopy_info){
270 
271 
272 
273  paramotopy_info.location = paramotopy_info.base_dir;
274  paramotopy_info.location /= "failure_analysis/pass";
275  std::stringstream ss;
276  ss << (this->current_iteration);
277  paramotopy_info.location += ss.str();
278 
279 // std::cout << "setting location fail " << paramotopy_info.location.string() << std::endl;
280 // boost::filesystem::create_directory(paramotopy_info.location);
281 
282  return;
283 }
284 
285 
286 
287 
288 
289 
290 
291 
292 void failinfo::PerformAnalysis(ProgSettings & paramotopy_settings, runinfo & paramotopy_info){
293 
294 
295 
296 
297 
298  for (int mm=0; (mm< paramotopy_settings.settings["PathFailure"]["maxautoiterations"].intvalue) && (totalfails>0); ++mm) {
299 
300 
301 
302  std::cout << "analyzing failed paths, iteration " << mm+1 << " of " << paramotopy_settings.settings["PathFailure"]["maxautoiterations"].intvalue << "\n";
303 
304  failinfo::set_location_fail(paramotopy_info);
305  boost::filesystem::create_directory(paramotopy_info.location);
306 
307  boost::filesystem::path openme = paramotopy_info.location;
308  openme /= "info";
309  std::ofstream fout(openme.c_str());
310  fout << this->current_iteration;
311  fout.close();
312  failinfo::write_failed_paths(paramotopy_info, current_iteration);
313 
314 
315  std::cout << "writing modified paramotopy\n";
316  paramotopy_info.WriteModifiedParamotopy( paramotopy_info.location, mm);
317 
318  //controls whether tolerances are tightened,
319  if (paramotopy_settings.settings["PathFailure"]["tightentolerances"].intvalue==1){
320  paramotopy_settings.tightentolerances();
321  }
322 
323 
324  //do a new step 1 solve (is actually a step 2 solve, to new random points)
325  boost::filesystem::path makeme = paramotopy_info.location;
326  boost::filesystem::create_directories(makeme/="step1");
327 
328  if (paramotopy_settings.settings["PathFailure"]["newrandommethod"].intvalue==1) {
329  std::cout << "doing new step one\n";
330  failinfo::new_step_one(paramotopy_settings, paramotopy_info);
331  }
332  else{
333  failinfo::copy_step_one(paramotopy_info.base_dir, paramotopy_info.location, mm, paramotopy_settings.settings["mode"]["startfilename"].value());
334  }
335 
336 
337  //run a step2 on the failed points.
338 
339 
340  std::string previous_start_file = "";
341  if (paramotopy_settings.settings["PathFailure"]["newrandommethod"].intvalue==1) {
342  previous_start_file = paramotopy_settings.settings["mode"]["startfilename"].value();
343  paramotopy_settings.setValue("mode","startfilename",std::string("nonsingular_solutions"));
344  }
345 
346  int terminationint = GetMcNumLines(paramotopy_info.location,paramotopy_info.numparam);
347 
348  if (terminationint==0) {
349  std::cerr << "have 0 points to solve for some reason." << std::endl;
350  break;
351  }
352 
353  int previous_mainmode = paramotopy_settings.settings["mode"]["main_mode"].intvalue;
354  int previous_num_procs = paramotopy_settings.settings["parallelism"]["numprocs"].intvalue;
355  int previous_numfilesatatime = paramotopy_settings.settings["parallelism"]["numfilesatatime"].intvalue;
356  // here put code for turning on/off parsing
357  if (terminationint+1 < previous_num_procs) {
358  paramotopy_settings.setValue("parallelism","numprocs",terminationint+1);
359  paramotopy_settings.setValue("parallelism","numfilesatatime",1);
360  }
361  else{
362  double fractpart, intpart;
363 
364  fractpart = modf ( (terminationint+1) / previous_num_procs , &intpart);
365 
366  int numprocstouse = std::max(double(1),intpart/5);
367  paramotopy_settings.setValue("parallelism","numfilesatatime",numprocstouse);
368  }
369 
370  paramotopy_settings.setValue("mode","main_mode",int(0));
371 
372 
373 
374  // the true boolean is to assume all failed paths are being done
375  // with a standard parameter continuation resolve
376  // and not any other option (i.e. solve at particular parameter
377  // point at finer settings because it doesn't match the
378  // NID at a random point. -- work needs to be done
379  // on failed path analysis stuff after this other implementation goes through
380 
381  steptwo_case(paramotopy_settings, paramotopy_info); // in menu_cases.cpp
382 
383 
384  //recall the old values for a couple of settings
385  if (paramotopy_settings.settings["PathFailure"]["newrandommethod"].intvalue==1) {
386  paramotopy_settings.setValue("mode","startfilename",std::string(previous_start_file));
387  }
388 
389  paramotopy_settings.setValue("mode","main_mode",previous_mainmode);
390  paramotopy_settings.setValue("parallelism","numprocs",previous_num_procs);
391  paramotopy_settings.setValue("parallelism","numfilesatatime",previous_numfilesatatime);
392  paramotopy_info.GetPrevRandom();
393  //need to check integrity of completed run -- sometimes will fail / be cancelled, and need to be able to recover from these halts.
394 
395  boost::filesystem::path path_to_check = paramotopy_info.location;
396  if (!TestIfFinished(path_to_check)){
397  //
398  std::cout << "it appears the run failed. removing files." << std::endl;
399  break;
400  }
401 
402  failinfo::find_failed_paths(paramotopy_info,2,this->current_iteration); // we find the points which had failures.
403 
404  failinfo::find_successful_resolves(paramotopy_info);
405 
406  failinfo::write_successful_resolves(paramotopy_info);
407 
408  std::cout << "\nThere were " << this->totalfails << " points with path failures, out of " << this->num_points_inspected << " total points.\n";
409 
410 
411  this->initial_fails[this->current_iteration+1] = this->terminal_fails[this->current_iteration];
412  this->current_iteration++;
413  }
414  //run a (step1) run to get new start point.
415 
416  return;
417 
418 }//re: perform_analysis
419 
420 
421 
422 
423 
425 
426 
427  boost::filesystem::path file_to_write_to = paramotopy_info.base_dir;
428 
429 
430  file_to_write_to /= "failure_analysis/successful_resolves";
431 
432  std::ofstream outputfile(file_to_write_to.string().c_str());
433 
434  if (!outputfile.is_open()) {
435  std::cerr << "failed to open " << file_to_write_to.string() << " to write resolve data" << std::endl;
436  return;
437  }
438 
439  outputfile << master_fails.size() << "\n";
440  for (int ii = 0; ii<int( master_fails.size() ); ++ii) {
441  outputfile << master_fails[ii].index << " " << master_fails[ii].collected_data.size() << "\n";
442 // std::cout << master_fails[ii].index << " " << master_fails[ii].collected_data.size() << std::endl;
443 
444 
445  if ( int(master_fails[ii].collected_data.size())>0){
446  std::map<std::string, std::string>::iterator iter;
447  std::stringstream namelist;
448  std::stringstream datalist;
449 
450  for ( iter=master_fails[ii].collected_data.begin(); iter!=master_fails[ii].collected_data.end(); ++iter) {
451  namelist << iter->first << " ";
452  datalist << iter->second;
453  }
454  outputfile << namelist.str() << "\n";
455  outputfile << datalist.str();
456  }
457  }
458  outputfile.close();
459 
460 
461  boost::filesystem::path blabla = paramotopy_info.base_dir;
462  blabla /= "failure_analysis/resolved_file";
463 
464  std::ofstream outputfile2(blabla.string().c_str());
465  outputfile2 << file_to_write_to.string();
466  outputfile2.close();
467  return;
468 }
469 
470 
472 
473  datagatherer lets_gather_some_data(paramotopy_info.numvariables, paramotopy_info.location);
474 
475 
476  std::vector< point > current_successful_resolves;
477  lets_gather_some_data.GatherDataForFails(this->terminal_fails[this->current_iteration],current_successful_resolves);
478 
479  //have successful_resolves, a vector of points, containing the data for re-solved points from this iteration. indices are WRT the current iteration.
480 
481  std::vector< int > relative_indices, final_indices;
482  relative_indices.resize(current_successful_resolves.size());
483  final_indices.resize(current_successful_resolves.size());
484 
485 
486  for (int ii=0; ii<int(current_successful_resolves.size()); ++ii) {
487  int failed_again_index = current_successful_resolves[ii].index;
488 
489  if (current_iteration == 0){
490  relative_indices[ii] = failed_again_index;
491  }
492 
493  for (int jj = current_iteration; jj>=0; --jj) {
494  failed_again_index = initial_fails[jj][failed_again_index].index;
495  if (jj==1) {
496  relative_indices[ii] = failed_again_index;
497  }
498  if (jj==0) {
499  final_indices[ii] = failed_again_index;
500  }
501  }
502 
503  }
504 
505  failinfo::merge_successful_resolves(current_successful_resolves,relative_indices,final_indices); //merges the data into the master list.
506 
507 
508 
509  return;
510 }
511 
512 
513 void failinfo::merge_successful_resolves(std::vector< point > current_successful_resolves, std::vector< int > relative_indices, std::vector< int > final_indices){
514 
515 
516  for (int ii=0; ii<int( current_successful_resolves.size() ); ++ii) {
517  if (master_fails[relative_indices[ii]].index != final_indices[ii]) {
518  std::cerr << "mismatch in indices when commiting to master list" << std::endl;
519  }
520  else{
521  master_fails[relative_indices[ii]].collected_data = current_successful_resolves[ii].collected_data;
522  }
523  }
524 
525  return;
526 }
527 
528 //write failed path info to the screen
530 
531 
532 
533  if (this->initial_fails[current_iteration].size() == 0) {
534  std::cout << current_iteration << " congratulations, your run had 0 path failures total!\n";
535  return;
536  }
537 
538 
539 
540  int premie = std::cout.precision();//for restoring at end of function
541  std::cout << std::setiosflags(std::ios::fixed | std::ios::showpoint);
542  std::cout.precision(3);
543  std::cout << "the ";
544  if (this->initial_fails[current_iteration].size()>30) {
545  std::cout << "last ";
546  }
547  std::cout << std::min(30,int(this->initial_fails[current_iteration].size())) << " parameter points with failures:\n\n";
548 
549 
550 
551  //get whether we have imaginary components for each column
552 
553  //preallocate
554  std::vector< bool > have_imaginary;
555  have_imaginary.resize(paramotopy_info.numparam);
556  for (int ii = 0;ii< paramotopy_info.numparam; ++ii) {
557  have_imaginary[ii] = false;
558  }
559 
560  //assign actual values
561  for (int ii=std::max(0,int(this->initial_fails[current_iteration].size())-30) ; ii < int(this->initial_fails[current_iteration].size()); ++ii) {
562  for (int jj = 0; jj<paramotopy_info.numparam; ++jj) {
563  if (fabs( this->initial_fails[current_iteration][ii].parameter_values[jj].second )>0.0001){
564  have_imaginary[jj] = true;
565  }
566  }
567  }
568 
569  std::vector< int > column_widths;
570  column_widths.resize(paramotopy_info.numparam);
571  for (int ii = 0; ii<paramotopy_info.numparam; ++ii) {
572  if (have_imaginary[ii]) {
573  column_widths[ii] = 16;
574  }
575  else{
576  column_widths[ii] = 9;
577  }
578  }
579  for (int ii = 0; ii<paramotopy_info.numparam; ++ii) {
580  std::cout << " " << paramotopy_info.ParameterNames[ii];
581  for (int jj=0; jj<(column_widths[ii]- int(paramotopy_info.ParameterNames[ii].length())+2); ++jj) {
582  std::cout << " ";
583  }
584  }
585  std::cout << std::endl << std::endl;
586  for (int ii=std::max(0,int(this->initial_fails[current_iteration].size())-30);ii < int(this->initial_fails[current_iteration].size()); ++ii) {
587  for (int jj = 0; jj<paramotopy_info.numparam; ++jj) {
588  std::stringstream ss;
589  ss << printf("%.3f",initial_fails[current_iteration][ii].parameter_values[jj].first);
590  if (initial_fails[current_iteration][ii].parameter_values[jj].second!=0){
591  ss << "+i*" << initial_fails[current_iteration][ii].parameter_values[jj].second;
592  }
593  std::string tmpstr = ss.str();
594  std::cout << tmpstr;
595  for (int kk=0; kk<( column_widths[jj]-int(tmpstr.size()) ); ++kk) {
596  std::cout << " ";
597  }
598  }
599  std::cout << std::endl;
600  }
601 
602 
603  std::cout << "\nThere were " << this->initial_fails[current_iteration].size() << " points with path failures, out of " << num_points_inspected << " total points.\n";
604 
605  std::cout.precision(premie);
606  std::cout.unsetf(std::ios::fixed | std::ios::showpoint);
607  return;
608 }
609 
610 
611 
612 
613 void failinfo::copy_step_one(boost::filesystem::path from_dir, boost::filesystem::path to_dir,
614  int iteration, std::string startfilename){
615 
616  std::string tmpstr;
617  boost::filesystem::path from_file = from_dir;
618 
619  from_file /= "step1";
620  from_file /= startfilename;
621 
622  boost::filesystem::path to_file = to_dir;
623  to_file /= "step1";
624  to_file /= startfilename;
625 
626  std::ifstream fin(from_file.c_str());
627  if (!fin.is_open()) {
628  std::cerr << "failed to open " << from_file << " to read" << std::endl;
629  }
630  std::ofstream fout(to_file.c_str());
631  if (!fout.is_open()) {
632  std::cerr << "failed to open " << to_file << " to write" << std::endl;
633  }
634 
635 
636 
637 
638  while (getline(fin,tmpstr)) {
639  fout << tmpstr << "\n";
640  }
641 
642  fin.close();
643  fout.close();
644 
645  return;
646 
647 }
648 
649 
650 
651 
652 std::string failinfo::new_step_one(ProgSettings & paramotopy_settings,runinfo & paramotopy_info){
653 
654 
655  std::string start;
656 
657 
658  int num_paths_to_track = GetStart(paramotopy_info.base_dir,
659  start,
660  paramotopy_settings.settings["mode"]["startfilename"].value());
661 
662 
663  //write step2 to memory.
664 
665  std::vector< std::pair< double, double> > new_random_values = paramotopy_info.MakeRandomValues(42);//lol the integer passed here is only to use polymorphism to get a slightly different function. joke's on you. lol lol lollololooolol.
666 
667  //now need to write to file in location.
668  std::string inputstring = WriteFailStep2(new_random_values,
669  paramotopy_settings,
670  paramotopy_info); // bool set to true for standardstep2
671 
672  paramotopy_info.RandomValues = new_random_values;
673 
674 
675  boost::filesystem::path bertinifilename = paramotopy_info.location;
676  bertinifilename /= "step1";
677  boost::filesystem::create_directories(bertinifilename);
678  bertinifilename /= "input";
679  std::ofstream fout;
680  fout.open(bertinifilename.c_str());
681  if (!fout.is_open()) {
682  std::cerr << "writing step1(2) input for failed paths FAILED to open to write\n";
683  }
684  fout << inputstring;
685  fout.close();
686 
687  bertinifilename = paramotopy_info.location;
688  bertinifilename /= "step1";
689  bertinifilename /= "start";
690  fout.open(bertinifilename.c_str());
691  if (!fout.is_open()) {
692  std::cerr << "writing step1(2) start file for failed paths FAILED to open\n";
693  }
694  fout << start;
695  fout.close();
696 
697 
698  //be intelligent about the number of processors to use.
699  int previous_num_procs = paramotopy_settings.settings["parallelism"]["numprocs"].intvalue;
700  // here put code for turning on/off parsing
701  if (num_paths_to_track < previous_num_procs) {
702  paramotopy_settings.setValue("parallelism","numprocs",num_paths_to_track+1);
703  }
704 
705 
706  //call bertini, in parallel if possible
707  CallBertiniStep1(paramotopy_settings,
708  paramotopy_info);
709 
710 
711  //restore the previous value for the numprocs setting
712  if (num_paths_to_track < previous_num_procs) {
713  paramotopy_settings.setValue("parallelism","numprocs",previous_num_procs);
714  }
715 
716 
717 
718  //get the start string
719  std::string start_string = "unset start string";
720 
721  return start_string;
722 }
723 
724 
725 
726 
727 
728 
729 
730 
731 
732 //writes the failed points and indices to two separate files in location.
733 void failinfo::write_failed_paths(runinfo paramotopy_info, int iteration){
734 
735 
736 
737  boost::filesystem::path mcfilename = paramotopy_info.location;
738  mcfilename /= "mc";
739 
740  if (boost::filesystem::exists(mcfilename)) {
741  boost::filesystem::remove(mcfilename);
742  }
743 
744  std::cout << "writing " << initial_fails[current_iteration].size() << " points to mc file" << std::endl;
745 
746 
747  std::ofstream fout;
748  fout.open(mcfilename.c_str());
749  if (!fout.is_open()) {
750  std::cerr << "failed to open " << mcfilename << " to write mc file. cannot continue." << std::endl;
751  exit(451);
752  }
753 
754  fout.precision(16);
755  fout << initial_fails[current_iteration].size() << "\n";
756  for (int ii = 0; ii < int(initial_fails[current_iteration].size()); ++ii) {
757  for (int jj = 0; jj < paramotopy_info.numparam; ++jj) {
758  fout << initial_fails[current_iteration][ii].parameter_values[jj].first << " " << initial_fails[current_iteration][ii].parameter_values[jj].second << " ";
759  }
760  fout << "\n";
761  }
762  fout.close();
763 
764 
765 
766  boost::filesystem::path failname = paramotopy_info.location;
767  failname /= "fail_indices";
768  fout.open(failname.c_str());
769  for (int ii = 0; ii < totalfails; ++ii) {
770  fout << initial_fails[current_iteration][ii].index << "\n";
771  }
772  fout.close();
773 
774  return;
775 }
776 
777 
778 
779 
780 //parses a series of 'failed_paths' files, searching for points which had such paths.
781 
782 //make sure you set paramotopy_info.location before calling this function
783 int failinfo::find_failed_paths(runinfo paramotopy_info, int temporal_flag, int iteration){
784 
785  if (temporal_flag==0) {
786  failinfo::get_folders_for_fail(paramotopy_info.base_dir);
787  }
788  else{
789  failinfo::get_folders_for_fail(paramotopy_info.location);
790  }
791 
792  //start by resetting some data members of the runinfo object.
793  this->num_points_inspected = 0;
794  this->totalfails = 0;
795 
796  std::vector< point > temporary_fails;
797 
798  // Data members used throughout the function
799  std::string inputfilename, outputfilename, wasteme, tmp, tmpstr; // location,
800  std::ifstream fin;
801  std::ofstream fout;
802 
803  std::stringstream ss, intstream;
804  //int linenumber;
805 
806 
807  point temppoint; //has data members index, parameter_values.
808  temppoint.parameter_values.resize(paramotopy_info.numparam);
809 
810 
811 
812  std::string tempname;
813 
814  for (int folder_counter=0; folder_counter<int(foldervector.size()); ++folder_counter){
815 
816  inputfilename = foldervector[folder_counter];
817  inputfilename.append("/failed_paths");
818 
819 
820  int filenum = 0, totalfails_thisfolder = 0;
821  struct stat filestatus;
822 
823  tempname = inputfilename;
824  tempname.append("0");
825 
826  //todo: rewrite using boost
827  while ( stat( tempname.c_str(), &filestatus ) ==0 ) { //while can open file
828  fin.open(tempname.c_str());
829  getline(fin,tmpstr); //the top line of the file should be the parameters, causing us to have to read in this line before we start anything.
830  int num_points_inspected_individual = 0; //keeps track of the number of points inspected in an individual file.
831  while ( getline(fin,tmpstr) ) { // get line. either blank (no more) or a # (line num or index)
832  if (tmpstr.length()==0 ){ // if true, then blank. file ought to be done
833 
834  break;
835  }
836  else { //not blank. work to do
837 
838 
839  ++num_points_inspected; // increment the point counters.
840  ++num_points_inspected_individual;
841  ss << tmpstr;
842  ss >> temppoint.index; //get the line number
843  ss.clear();
844  ss.str("");
845 
846  getline(fin,tmpstr); // gets the parameter values for this line. need to save if have fails
847  ss << tmpstr;
848 
849  //set the temporary parameter values
850  for (int i = 0; i < paramotopy_info.numparam; ++i) {
851  ss >> temppoint.parameter_values[i].first;
852  ss >> temppoint.parameter_values[i].second;
853  }
854  ss.clear();
855  ss.str("");
856 
857 
858  // parse the (previously) copied 'failedpaths' file.
859  int tempfailnum = ParseFailedPaths(fin,paramotopy_info.numvariables); // in para_aux_funcs.cpp
860 
861 
862  if (tempfailnum > 0){
863  temporary_fails.push_back(temppoint);
864  totalfails_thisfolder++;
865  }
866  }
867 
868  }
869  fin.close();
870 
871  //output the folder's summary to the screen
872  std::cout << tempname << " "
873  << totalfails_thisfolder << " "
874  << num_points_inspected_individual << "\n";
875 
876 
877  filenum++;//increment
878  ss << filenum; //make new file name
879  tempname = inputfilename; // reset.
880  tempname.append(ss.str()); // append the integer onto the end of the filename. will be the next to open (provided it exists).
881  ss.clear();
882  ss.str("");
883  } // re: while
884 
885 
886  totalfails += totalfails_thisfolder;
887  } //re:for (int folder_counter=0; folder_counter<foldervector.size(); ++folder_counter)
888 
889  std::sort( temporary_fails.begin(), temporary_fails.end() );
890 
891  //actually assign the data
892 
893 
894 
895  switch (temporal_flag) {
896  case 0:
897  this->master_fails.clear();
898  this->master_fails = temporary_fails;
899  break;
900 
901  case 1:
902  this->initial_fails[iteration] = temporary_fails;
903  break;
904 
905  case 2:
906  this->terminal_fails[iteration] = temporary_fails;
907  break;
908  default:
909  std::cerr << "invalid temporal flag passed in find_failed_paths" << std::endl;
910  break;
911  }
912 
913 
914  return num_points_inspected;
915 }
916 
917 
918 
919 
920 
921 
922 
923 
924 
925 
926 
927 
928 void failinfo::get_folders_for_fail(boost::filesystem::path dir){
929 
930  foldervector.clear();
931 
932 
933  //read in folder file.
934  boost::filesystem::path foldername = dir;
935  foldername /= "folders";
936  std::ifstream folderstream;
937  folderstream.open(foldername.c_str());
938 
939  if (!folderstream.is_open()) {
940  std::cerr << "failed to open file to read folders " << foldername.string() << std::endl;
941  }
942  else{
943  std::string tmpstr;
944 
945 
946  while (getline(folderstream,tmpstr)) {
947  foldervector.push_back(tmpstr);
948  }
949  folderstream.close();
950  }
951 
952  return;
953 }
954 
int ParseFailedPaths(std::ifstream &fin, int numvariables)
the parser for the failed_paths file type, which is output from bertini.
std::map< int, std::vector< point > > initial_fails
void report_restored_data()
void write_successful_resolves(runinfo paramotopy_info)
int num_points_inspected
int find_failed_paths(runinfo paramotopy_info, int temporal_flag, int iteration)
void merge_successful_resolves(std::vector< point > current_successful_resolves, std::vector< int > relative_indices, std::vector< int > final_indices)
void DisplayCurrentSettings(std::string category_name)
std::vector< std::pair< double, double > > RandomValues
Definition: runinfo.hpp:130
int numvariables
Definition: runinfo.hpp:60
std::map< int, point > ReadSuccessfulResolves()
void report_failed_paths(runinfo paramotopy_info)
boost::filesystem::path base_dir
Definition: runinfo.hpp:77
void RecoverProgress(runinfo &paramotopy_info)
this function does three things: recovers the iteration number, recovers the list of points which hav...
boost::filesystem::path fundamental_dir
Definition: runinfo.hpp:74
void get_folders_for_fail(boost::filesystem::path dir)
void StartOver(runinfo &paramotopy_info)
int GetMcNumLines(boost::filesystem::path base_dir, int numparam)
void copy_step_one(boost::filesystem::path from_dir, boost::filesystem::path to_dir, int iteration, std::string startfilename)
void UpdateAndSave()
Definition: runinfo.cpp:1315
void find_successful_resolves(runinfo &paramotopy_info)
std::vector< boost::filesystem::path > FindDirectories(boost::filesystem::path, std::string expression)
void MainMenu(ProgSettings &paramotopy_settings, runinfo &paramotopy_info)
Definition: failed_paths.cpp:6
int numparam
Definition: runinfo.hpp:64
Class containing parameter values, index, and collected data.
Definition: point.hpp:32
bool TestIfFinished(boost::filesystem::path &path_to_check)
bool GatherDataForFails(std::vector< point > terminal_fails, std::vector< point > &successful_resolves)
std::vector< std::string > foldervector
void CallBertiniStep1(ProgSettings paramotopy_settings, runinfo paramotopy_info)
Definition: step1_funcs.cpp:5
void tightentolerances()
int totalfails
int get_int_choice(std::string display_string, int min_value, int max_value)
void set_location_fail(runinfo &paramotopy_info)
std::map< int, std::vector< point > > terminal_fails
void PerformAnalysis(ProgSettings &paramotopy_settings, runinfo &paramotopy_info)
void set_path_failure_settings()
std::vector< std::string > ParameterNames
Definition: runinfo.hpp:104
bool test_if_finished()
Definition: runinfo.cpp:1287
void make_master_from_recovered(std::map< int, point > successful_resolves)
boost::filesystem::path inputfilename
Definition: runinfo.hpp:90
boost::filesystem::path location
Definition: runinfo.hpp:71
Class for gathering data, from failed path analysis, and from completed runs.
std::string new_step_one(ProgSettings &paramotopy_settings, runinfo &paramotopy_info)
std::vector< std::pair< double, double > > parameter_values
Definition: point.hpp:46
categorymap settings
std::vector< std::pair< double, double > > MakeRandomValues(int garbageint)
Definition: runinfo.cpp:788
A class that stores the general program settings of Paramotopy.
bool GetPrevRandom()
Definition: runinfo.cpp:451
std::vector< point > master_fails
long long index
Definition: point.hpp:38
A class for the input file parser.
Definition: runinfo.hpp:41
std::string WriteFailStep2(std::vector< std::pair< double, double > > CValues, ProgSettings paramotopy_settings, runinfo paramotopy_info)
Definition: step2_funcs.cpp:40
void write_failed_paths(runinfo paramotopy_info, int iteration)
void WriteModifiedParamotopy(boost::filesystem::path dir, int iteration)
Definition: runinfo.cpp:97
int current_iteration
void setValue(std::string categoryName, std::string settingName, std::string settingValue)
int GetStart(boost::filesystem::path dir, std::string &start, std::string startfilename)