OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalSimulation.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <string.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/wait.h>
7 #include <sys/stat.h>
8 #include <dirent.h>
9 #include <cstdlib>
10 #include <vector>
11 #include <ctime>
12 #include <exception>
13 
15 
16 #include "Util/SDDSReader.h"
17 #include "Util/SDDSParser.h"
19 #include "Util/OptPilotException.h"
21 
23 
24 #include "Expression/SumErrSq.h"
25 #include "Expression/FromFile.h"
26 
27 #include "boost/variant.hpp"
28 #include "boost/smart_ptr.hpp"
29 #include "boost/algorithm/string.hpp"
30 
31 #include "boost/filesystem.hpp"
32 #include "boost/filesystem/operations.hpp"
33 
34 // access to OPAL lib
35 #include "opal.h"
37 #include "Utilities/Options.h"
38 #include "Utilities/Util.h"
39 
41  Expressions::Named_t constraints,
42  Param_t params, std::string name,
43  MPI_Comm comm, CmdArguments_t args)
44  : Simulation(args)
45  , objectives_(objectives)
46  , constraints_(constraints)
47  , comm_(comm)
48  , id_m(-1)
49 {
50  namespace fs = boost::filesystem;
51 
52  simTmpDir_ = args->getArg<std::string>("simtmpdir");
53  if (simTmpDir_ == "") {
54  if(getenv("SIMTMPDIR") == NULL) {
55  std::cout << "Environment variable SIMTMPDIR not defined!"
56  << std::endl;
57  simTmpDir_ = getenv("PWD");
58  } else
59  simTmpDir_ = getenv("SIMTMPDIR");
60  }
62 
63  // prepare design variables given by the optimizer for generating the
64  // input file
65  std::vector<std::string> dict;
66  for(auto parameter : params) {
67  std::ostringstream tmp;
68  tmp.precision(15);
69  tmp << parameter.first << "=" << parameter.second;
70  dvarNames_.insert(parameter.first);
71  dict.push_back(tmp.str());
72 
73  std::ostringstream value;
74  value.precision(15);
75  value << parameter.second;
76  userVariables_.insert(
77  std::pair<std::string, std::string>(parameter.first, value.str()));
78  }
79 
80  /*
81  This is a copy from Comm/Splitter/ManyMasterSplit.h
82  in order to calculate the leader which is the unique ID in case
83  of more than one core per worker.
84  */
85 
86  int my_rank=0;
87  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
88  int world_size=0;
89  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
90 
91  unsigned num_coworkers_worker_ = 0;
92  num_coworkers_worker_ = args->getArg<size_t>("num-coworkers");
93 
94  unsigned group_start = 0;
95 
96  unsigned worker_group = ((my_rank % world_size) - 2) / num_coworkers_worker_;
97 
98  unsigned leader_ = group_start + 2 + worker_group * num_coworkers_worker_;
99  leader_ = leader_ % world_size;
100 
101  // hash the dictionary to get a short unique directory name for temporary
102  // simulation data
103  std::string hash = NativeHashGenerator::generate(dict);
104 
105  std::ostringstream tmp;
106  tmp.precision(15);
107 
108  tmp << simTmpDir_ << "/" << hash << "_" << leader_;
109 
110  simulationDirName_ = tmp.str();
111 
112  std::string tmplDir = args->getArg<std::string>("templates");
113  if (tmplDir == "") {
114  if(getenv("TEMPLATES") == NULL) {
115  throw OptPilotException("OpalSimulation::OpalSimulation",
116  "Environment variable TEMPLATES not defined!");
117  }
118  tmplDir = getenv("TEMPLATES");
119  }
120  std::string tmplFile = tmplDir + "/" + simulationName_ + ".tmpl";
121  // data file is assumed to be located in the root directory
122  std::string dataFile = simulationName_ + ".data";
123  fs::path pwd = fs::current_path();
124  if (!fs::exists(dataFile))
125  throw OptPilotException("OpalSimulation::OpalSimulation",
126  "The data file '" + dataFile + "' \n" +
127  " doesn't exist in directory '" + pwd.native() + "'");
128 
129  if (!fs::exists(tmplFile))
130  throw OptPilotException("OpalSimulation::OpalSimulation",
131  "The template file '" + tmplFile + "' doesn't exit");
132 
133  gs_.reset(new GenerateOpalSimulation(tmplFile, dataFile, userVariables_));
134 }
135 
136 
138  requestedVars_.clear();
139  userVariables_.clear();
140 }
141 
143 
144  std::string infile = simulationDirName_ + "/" + simulationName_ + ".in";
145  struct stat fileInfo;
146 
147  if(stat(infile.c_str(), &fileInfo) == 0) {
148  std::cout << "-> Simulation input file (" << infile
149  << ") already exist from previous run.." << std::endl;
150  return true;
151  }
152 
153  return false;
154 }
155 
156 
157 void OpalSimulation::createSymlink_m(const std::string& path) {
158  namespace fs = boost::filesystem;
159 
160  for (auto &p: fs::directory_iterator(path)) {
161  fs::path source = p.path();
162  fs::path target(simulationDirName_ + "/");
163  target +=source.filename();
164 
165  try {
166  fs::create_symlink(source, target);
167  } catch (fs::filesystem_error &e) {
168  std::cerr << e.what() << "\n"
169  << "in OpalSimulation::createSymlink()" << std::endl;
170  }
171  }
172 }
173 
174 
176  CmdArguments_t args = getArgs();
177  std::string restartfile = args->getArg<std::string>("restartfile", "", false);
178 
179  if (restartfile.empty()) return;
180 
181  namespace fs = boost::filesystem;
182  if ( !fs::exists(restartfile) ) {
183  std::cerr << "H5 file '" + restartfile + "' doesn't exist." << "\n"
184  << "in OpalSimulation::copyH5_m()" << std::endl;
185 
186  return;
187  }
188 
189  try {
190  fs::path srcfile(restartfile);
191  fs::path targetfile(simulationDirName_ + "/" + simulationName_ + ".h5");
192  fs::copy_file(srcfile, targetfile);
193  } catch (fs::filesystem_error &ex) {
194  std::cerr << ex.what() << "\n"
195  << "in OpalSimulation::copyH5_m()" << std::endl;
196  }
197 }
198 
199 
201  namespace fs = boost::filesystem;
202 
203  CmdArguments_t args = getArgs();
204  std::string restartfile = args->getArg<std::string>("restartfile", "", false);
205 
206  if ( id_m > -1 ) {
207  std::ostringstream tmp;
208  tmp << simTmpDir_ << "/" << id_m;
209  simulationDirName_ = tmp.str();
210  }
211  std::string dataDir = simulationDirName_ + "/data";
212 
214  opal->setOptimizerFlag();
215 
216  // linking fieldmaps + distributions
217  if (getenv("FIELDMAPS") == NULL) {
218  throw OptPilotException("OpalSimulation::setupSimulation",
219  "Environment variable FIELDMAPS not defined!");
220  }
221 
223 
224  MPI_Barrier(comm_);
225 
226  if (!fs::exists(simulationDirName_)) {
227  throw OptPilotException("OpalSimulation::setupSimulation",
228  "Directory '" + simulationDirName_ + "' doesn't exist");
229  }
230 
231  if (!fs::exists(dataDir)) {
232  throw OptPilotException("OpalSimulation::setupSimulation",
233  "Directory '" + dataDir + "' doesn't exist");
234  }
235 
236  if (!restartfile.empty() &&
237  !fs::exists(simulationDirName_ + "/" + simulationName_ + ".h5")) {
238  throw OptPilotException("OpalSimulation::setupSimulation",
239  "H5 file '" + simulationDirName_ + "/" + simulationName_ + ".h5' doesn't exist");
240  }
241 }
242 
244  namespace fs = boost::filesystem;
245 
246  int rank = 0;
247  MPI_Comm_rank(comm_, &rank);
248  if (rank != 0) return; // only one processor in comm group has to setup files
249 
250  if (fs::exists(simulationDirName_)) {
251  fs::remove_all(simulationDirName_);
252  }
253 
254  try {
255  fs::create_directory(simulationDirName_);
256  fs::permissions(simulationDirName_,
257  fs::owner_all |
258  fs::group_read |
259  fs::group_exe |
260  fs::others_read |
261  fs::others_exe);
262 
263  } catch (fs::filesystem_error &e) {
264  std::cerr << e.what() << "\n"
265  << "in OpalSimulation::setupSimulation" << std::endl;
266  return;
267  }
268 
269  try {
270  std::string dataDir = simulationDirName_ + "/data";
271 
272  fs::create_directory(dataDir);
273  fs::permissions(dataDir,
274  fs::owner_all |
275  fs::group_read |
276  fs::group_exe |
277  fs::others_read |
278  fs::others_exe);
279 
280  } catch (fs::filesystem_error &e) {
281  std::cerr << e.what() << "\n"
282  << "in OpalSimulation::setupSimulation" << std::endl;
283  return;
284  }
285 
286  std::string infile = simulationDirName_ + "/" +
287  simulationName_ + ".in";
288  gs_->writeInputFile(infile);
289 
290  std::string fieldmapPath = getenv("FIELDMAPS");
291  this->createSymlink_m(fieldmapPath);
292 
293  if (getenv("DISTRIBUTIONS") != NULL) {
294  std::string distPath = getenv("DISTRIBUTIONS");
295  this->createSymlink_m(distPath);
296  }
297 
298  this->copyH5_m();
299 }
300 
302 
303  // backup stdout and err file handles
304  strm_buffer_ = std::cout.rdbuf();
305  strm_err_ = std::cerr.rdbuf();
306 
307  int world_pid = 0;
308  MPI_Comm_rank(MPI_COMM_WORLD, &world_pid);
309 
310  std::ostringstream fname;
311  fname << "sim.out." << world_pid;
312  std::ofstream file(fname.str().c_str());
313  fname << ".err";
314  std::ofstream err(fname.str().c_str());
315 
316  // and redirect stdout and err to new files
317  std::cout.rdbuf(file.rdbuf());
318  std::cerr.rdbuf(err.rdbuf());
319 }
320 
321 
323  std::cout.rdbuf(strm_buffer_);
324  std::cerr.rdbuf(strm_err_);
325 }
326 
327 
329  namespace fs = boost::filesystem;
330 
331  // make sure input file is not already existing
332  MPI_Barrier(comm_);
333  if( hasResultsAvailable() ) return;
334  MPI_Barrier(comm_);
335 
336  setupSimulation();
337 
338  pwd_ = fs::current_path().native();
339  pwd_ += "/";
340  int err = chdir(simulationDirName_.c_str());
341 
342  if (err != 0) {
343  std::cout << "Cannot chdir to "
344  << simulationDirName_.c_str() << std::endl;
345  std::cout << "Continuing 1, disregarding this simulation.."
346  << std::endl;
347  return;
348  }
349 
350  // setup OPAL command line options
351  std::ostringstream inputFileName;
352  inputFileName << simulationName_ << ".in";
353  char *inputfile = new char[inputFileName.str().size()+1] ;
354  strcpy(inputfile, inputFileName.str().c_str());
355  int seed = Options::seed;
356 
357  CmdArguments_t args = getArgs();
358  int restartStep= args->getArg<int>("restartstep",
360  std::string restartfile = args->getArg<std::string>("restartfile", "", false);
361 
362  try {
363  if ( restartStep > -2 && restartfile.empty() ) {
364  throw OpalException("OpalSimulation::run()",
365  "Restart specified but no restart H5 file available.");
366  }
367 
368  char exe_name[] = "opal";
369  char nocomm[] = "--nocomminit";
370  char info[] = "--info";
371  char info0[] = "0";
372  char warn[] = "--warn";
373  char warn0[] = "0";
374  char *arg[] = { exe_name, inputfile, nocomm, info, info0, warn, warn0 };
375 
376  //FIXME: this seems to crash OPAL in some cases
377  //redirectOutToFile();
378 #ifdef SUPRESS_OUTPUT
379  //XXX: hack to disable output to stdout and stderr
380  std::cout.setstate(std::ios::failbit);
381  // std::cerr.setstate(std::ios::failbit);
382 #endif
383  // now we can run the simulation
384  run_opal(arg, inputFileName.str(), restartStep, Options::infoLevel, Options::warnLevel, comm_);
385 
386  //restoreOut();
387 #ifdef SUPRESS_OUTPUT
388  std::cout.clear();
389  std::cerr.clear();
390 #endif
391 
392  } catch(OpalException *ex) {
393 
394  //restoreOut();
395 #ifdef SUPRESS_OUTPUT
396  std::cout.clear();
397  std::cerr.clear();
398 #endif
399 
400  std::cout << "Opal exception during simulation run: \n"
401  << ex->where() << "\n"
402  << ex->what() << std::endl;
403  std::cout << "Continuing 2, disregarding this simulation.."
404  << std::endl;
405 
406  } catch(ClassicException *ex) {
407 
408  //restoreOut();
409 #ifdef SUPRESS_OUTPUT
410  std::cout.clear();
411  std::cerr.clear();
412 #endif
413 
414  std::cout << "Classic exception during simulation run: \n"
415  << ex->where() << "\n"
416  << ex->what() << std::endl;
417  std::cout << "Continuing 3, disregarding this simulation.."
418  << std::endl;
419 
420  }
421 
423 
424  delete[] inputfile;
425  err = chdir(pwd_.c_str());
426  if (err != 0) {
427  std::cout << "Cannot chdir to "
428  << pwd_ << std::endl;
429  }
430 }
431 
432 
433 std::map<std::string, std::vector<double> > OpalSimulation::getData(const std::vector<std::string> &statVariables) {
434  std::map<std::string, std::vector<double> > ret;
435  SDDS::SDDSParser parser(simulationDirName_ + "/" + simulationName_ + ".stat");
436  parser.run();
437  for (const std::string &var : statVariables) {
439  try {
440  column = parser.getColumnData(var);
441  } catch (SDDSParserException &e) {
442  std::cout << "failed to read data: " << e.what() << " in " << e.where() << std::endl;
443  continue;
444  }
445 
446  std::vector<double> values;
447  values.reserve(column.size());
448  auto type = parser.getColumnType(var);
449  for (const auto val: column) {
450  values.push_back(parser.getBoostVariantValue<double>(val,(int)type));
451  }
452  ret.insert(std::make_pair(var, values));
453  }
454 
455  return ret;
456 }
457 
459 
460  // std::cout << "collectResults" << std::endl;
461 
462  // clear old solutions
463  requestedVars_.clear();
464 
465  int err = chdir(simulationDirName_.c_str());
466  if (err != 0) {
467  std::cout << "Cannot chdir to "
468  << simulationDirName_.c_str() << std::endl;
469  std::cout << "Continuing, with cleanup.."
470  << std::endl;
471  cleanUp();
472  return;
473  }
474 
475  std::string fn = simulationName_ + ".stat";
476  struct stat fileInfo;
477 
478  // if no stat file, simulation parameters produced invalid bunch
479  if(stat(fn.c_str(), &fileInfo) != 0) {
480  invalidBunch();
481  } else {
483  try {
484  for(namedIt=objectives_.begin(); namedIt!=objectives_.end(); ++namedIt) {
485  if (namedIt->first == "dummy") continue; // FIXME SamplePilot has default objective named dummy
486  Expressions::Expr_t *objective = namedIt->second;
487 
488  // find out which variables we need in order to evaluate the objective
489  variableDictionary_t variable_dictionary;
490  getVariableDictionary(variable_dictionary,fn,objective);
491 
492  // and evaluate the expression using the built dictionary of
493  // variable values
494  Expressions::Result_t result =
495  objective->evaluate(variable_dictionary);
496 
497  std::vector<double> values;
498  values.push_back(boost::get<0>(result));
499  bool is_valid = boost::get<1>(result);
500 
501  reqVarInfo_t tmps = {EVALUATE, values, is_valid};
502  requestedVars_.insert(
503  std::pair<std::string, reqVarInfo_t>(namedIt->first, tmps));
504 
505  }
506 
507  // .. and constraints
508  for(namedIt=constraints_.begin(); namedIt!=constraints_.end(); ++namedIt) {
509 
510  Expressions::Expr_t *constraint = namedIt->second;
511 
512  // find out which variables we need in order to evaluate the constraint
513  variableDictionary_t variable_dictionary;
514  getVariableDictionary(variable_dictionary,fn,constraint);
515 
516  Expressions::Result_t result =
517  constraint->evaluate(variable_dictionary);
518 
519  std::vector<double> values;
520  values.push_back(boost::get<0>(result));
521  bool is_valid = boost::get<1>(result);
522 
523  //FIXME: hack to give feedback about values of LHS and RHS
524  std::string constr_str = constraint->toString();
525  std::vector<std::string> split;
526  boost::split(split, constr_str, boost::is_any_of("<>!="),
527  boost::token_compress_on);
528  std::string lhs_constr_str = split[0];
529  std::string rhs_constr_str = split[1];
530  boost::trim_left_if(rhs_constr_str, boost::is_any_of("="));
531 
532  functionDictionary_t funcs = constraint->getRegFuncs();
533  boost::scoped_ptr<Expressions::Expr_t> lhs(
534  new Expressions::Expr_t(lhs_constr_str, funcs));
535  boost::scoped_ptr<Expressions::Expr_t> rhs(
536  new Expressions::Expr_t(rhs_constr_str, funcs));
537 
538  Expressions::Result_t lhs_res = lhs->evaluate(variable_dictionary);
539  Expressions::Result_t rhs_res = rhs->evaluate(variable_dictionary);
540 
541  values.push_back(boost::get<0>(lhs_res));
542  values.push_back(boost::get<0>(rhs_res));
543 
544  reqVarInfo_t tmps = {EVALUATE, values, is_valid};
545  requestedVars_.insert(
546  std::pair<std::string, reqVarInfo_t>(namedIt->first, tmps));
547 
548  }
549  } catch(SDDSParserException &e) {
550  std::cout << "Evaluation of objective or constraint " << namedIt->first << " threw an exception ('" << e.what() << "' in " << e.where() << ")!" << std::endl;
551  invalidBunch();
552  } catch(OptPilotException &e) {
553  std::cout << "Evaluation of objective or constraint " << namedIt->first << " threw an exception ('" << e.what() << "' in " << e.where() << ")!" << std::endl;
554  invalidBunch();
555  } catch(std::exception &e) {
556  std::cout << "Evaluation of objective or constraint " << namedIt->first << " threw an exception ('" << e.what() << "')!" << std::endl;
557  invalidBunch();
558  } catch(...) {
559  std::cout << "Evaluation of objective or constraint " << namedIt->first << " threw an exception!" << std::endl;
560  invalidBunch();
561  }
562 
563  }
564 
565  err = chdir(pwd_.c_str());
566  if (err != 0) {
567  std::cout << "Cannot chdir to "
568  << simulationDirName_.c_str() << std::endl;
569  }
570 }
571 
573  const std::string& filename,
574  const Expressions::Expr_t* const expression) {
575 
576  std::set<std::string> req_vars = expression->getReqVars();
577 
578  // first check if required variables are design variables
579  for (auto req_it = req_vars.begin(); req_it!=req_vars.end();) {
580  auto it = userVariables_.find(*req_it);
581  if (it==userVariables_.end()) { // not a design var
582  ++req_it;
583  continue;
584  }
585  double value = std::stod((*it).second);
586  dictionary.insert(std::pair<std::string, double>(*req_it, value));
587  req_it = req_vars.erase(req_it); // remove and update iterator to next
588  }
589 
590  if(req_vars.empty()) return;
591 
592  // get remaining required variable values from the stat file
593  boost::scoped_ptr<SDDSReader> sddsr(new SDDSReader(filename));
594  sddsr->parseFile();
595 
596  for(std::string req_var : req_vars) {
597  if(dictionary.count(req_var) != 0) continue;
598 
599  double value = 0.0;
600  sddsr->getValue(-1 /*atTime*/, req_var, value);
601  dictionary.insert(std::pair<std::string, double>(req_var, value));
602  }
603 }
604 
606 
607  for(auto namedObjective : objectives_) {
608  std::vector<double> tmp_values;
609  tmp_values.push_back(0.0);
610  reqVarInfo_t tmps = {EVALUATE, tmp_values, false};
611  requestedVars_.insert(
612  std::pair<std::string, reqVarInfo_t>(namedObjective.first, tmps));
613  }
614 }
615 
617  namespace fs = boost::filesystem;
618  try {
619  int my_rank = 0;
620  MPI_Comm_rank(comm_, &my_rank);
621  if (my_rank == 0) {
622  fs::path p(simulationDirName_.c_str());
623  fs::remove_all(p);
624  }
625  } catch(fs::filesystem_error &ex) {
626  std::cout << "Can't remove directory '" << simulationDirName_ << "', (" << ex.what() << ")" << std::endl;
627  } catch(...) {
628  std::cout << "Can't remove directory '" << simulationDirName_ << "'" << std::endl;
629  }
630 }
631 
632 void OpalSimulation::cleanUp(const std::vector<std::string>& keep) {
633  namespace fs = boost::filesystem;
634 
635  if ( keep.empty() ) {
636  // if empty we keep all files
637  return;
638  }
639 
640  try {
641  int my_rank = 0;
642  MPI_Comm_rank(comm_, &my_rank);
643  if (my_rank == 0) {
644  fs::path p(simulationDirName_.c_str());
645  fs::directory_iterator it{p};
646  while ( it != fs::directory_iterator{} ) {
647  std::string extension = Util::toUpper(fs::extension(it->path().filename()));
648 
649  // remove .
650  extension.erase(0, 1);
651 
652  auto result = std::find(keep.begin(), keep.end(), extension);
653 
654  if ( result == keep.end() ) {
655  fs::remove(it->path());
656  }
657  ++it;
658  }
659  }
660  } catch(fs::filesystem_error &ex) {
661  std::cout << "Can't remove file in directory '" << simulationDirName_
662  << "', (" << ex.what() << ")" << std::endl;
663  } catch(...) {
664  std::cout << "Can't remove file in directory '" << simulationDirName_
665  << "'" << std::endl;
666  }
667 }
int seed
The current random seed.
Definition: Options.cpp:41
The global OPAL structure.
Definition: OpalData.h:54
int infoLevel
Definition: Options.cpp:9
virtual const char * what() const
Expressions::Named_t constraints_
int run_opal(char *arg[], std::string inputfile, int restartStep, int infoLevel, int warnLevel, MPI_Comm comm)
Definition: opal.cpp:22
constexpr double e
The value of .
Definition: Physics.h:40
void setupFSStructure()
create directories, input files, symlinks...
std::string toString() const
Definition: Expression.h:107
reqVarContainer_t requestedVars_
holds solutions returned to the optimizer
virtual ~OpalSimulation()
int warnLevel
Definition: Options.cpp:11
The base class for all OPAL exceptions.
Definition: OpalException.h:28
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:169
std::string pwd_
holds current directory (for restoring)
std::string toUpper(const std::string &str)
Definition: Util.cpp:130
Expression to be evaluated in the framework.
Definition: Expression.h:75
std::string simTmpDir_
temporary directory for simulation data (environment var SIMTMPDIR)
Expressions::Named_t objectives_
FRONT * fs
Definition: hypervolume.cpp:59
ast::columnData_t getColumnData(const std::string &columnName)
Definition: SDDSParser.cpp:99
bool info
Info flag.
Definition: Options.cpp:8
std::string simulationDirName_
full path of simulation directory (where simulation will be run)
void restoreOut()
restore stdout and stderr to default
virtual const char * where() const
bool warn
Warn flag.
Definition: Options.cpp:10
std::streambuf * strm_err_
stream buffer to redirect stderr
Definition: Types.h:27
void copyH5_m()
copy H5 file
The abstract base class for all exceptions in CLASSIC.
Generates an OPAL input file from data and template file.
Abstract class every simulation has to implement to be able to work with the optimization pilot...
Definition: Simulation.h:20
static OpalData * getInstance()
Definition: OpalData.cpp:209
boost::tuple< double, bool > Result_t
Definition: Expression.h:37
std::set< std::string > getReqVars() const
Definition: Expression.h:105
namedVariableCollection_t Param_t
Definition: Types.h:33
bool hasResultsAvailable()
check if we already have simulated the current set of design vars
CmdArguments_t getArgs()
Definition: Simulation.h:31
void setOptimizerFlag()
Definition: OpalData.cpp:316
virtual const std::string & what() const
Return the message string for the exception.
Implements a parser and value extractor for Probe loss files.
Definition: SDDSReader.h:6
std::vector< variant_t > columnData_t
Definition: ast.hpp:42
void invalidBunch()
mark a solution as invalid
OpalSimulation(Expressions::Named_t objectives, Expressions::Named_t constraints, Param_t params, std::string name, MPI_Comm comm, CmdArguments_t args)
arg(a))
const T * find(const T table[], const std::string &name)
Look up name.
Definition: TFind.h:34
void setupSimulation()
create directories, input files, fieldmaps...
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Definition: Expression.h:45
Expressions::Result_t evaluate(variableDictionary_t vars)
evaluate an expression given a value dictionary of free variables
Definition: Expression.h:114
std::map< std::string, std::vector< double > > getData(const std::vector< std::string > &statVariables)
void createSymlink_m(const std::string &path)
create symbolic links
T getBoostVariantValue(const ast::variant_t &val, int datatype) const
Convert value from boost variant (only numeric types) to a value of type T.
Definition: SDDSParser.h:190
const std::string name
std::streambuf * strm_buffer_
stream buffer to redirect output
functionDictionary_t getRegFuncs() const
Definition: Expression.h:108
int id_m
job id (SAMPLE command)
boost::scoped_ptr< GenerateOpalSimulation > gs_
object to generate simulation input files
static std::string generate(std::vector< std::string > arguments, size_t world_pid=0)
virtual const char * what() const
std::string::iterator iterator
Definition: MSLang.h:16
std::set< std::string > dvarNames_
void getVariableDictionary(variableDictionary_t &dictionary, const std::string &filename, const Expressions::Expr_t *const expression)
get variables for expression evaluation from SDDS file. Can throw SDDSParserException ...
void redirectOutToFile()
redirect stdout and stderr to file
ast::datatype getColumnType(const std::string &col_name)
Definition: SDDSParser.h:58
std::map< std::string, double > variableDictionary_t
Definition: Expression.h:26
std::map< std::string, std::string > userVariables_
variable dictionary holding requested optimizer values
std::string simulationName_
identification of the simulation (corresponding to output filename)
std::map< std::string, client::function::type > functionDictionary_t
Definition: Expression.h:27
void collectResults()
Parse SDDS stat file and build up requested variable dictionary.
virtual const char * where() const
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:95
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
virtual const std::string & where() const
Return the name of the method or function which detected the exception.