OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
OpalSimulation.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <sstream>
3#include <cstring>
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"
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 std::map<std::string, std::string> uvars)
45 : Simulation(args)
46 , objectives_(objectives)
47 , constraints_(constraints)
48 , comm_(comm)
49 , id_m(-1)
50{
51 namespace fs = boost::filesystem;
52
53 simTmpDir_ = args->getArg<std::string>("simtmpdir");
54 if (simTmpDir_.empty()) {
55 if(getenv("SIMTMPDIR") == nullptr) {
56 std::cout << "Environment variable SIMTMPDIR not defined!"
57 << std::endl;
58 simTmpDir_ = getenv("PWD");
59 } else
60 simTmpDir_ = getenv("SIMTMPDIR");
61 }
63
64 // prepare design variables given by the optimizer for generating the
65 // input file
66 std::vector<std::string> dict;
67 for(auto parameter : params) {
68 std::ostringstream tmp;
69 tmp.precision(15);
70 tmp << parameter.first << "=" << parameter.second;
71 dvarNames_.insert(parameter.first);
72 dict.push_back(tmp.str());
73
74 std::ostringstream value;
75 value.precision(15);
76 value << parameter.second;
77 userVariables_.insert(
78 std::pair<std::string, std::string>(parameter.first, value.str()));
79 }
80
81 /*
82 This is a copy from Comm/Splitter/ManyMasterSplit.h
83 in order to calculate the leader which is the unique ID in case
84 of more than one core per worker.
85 */
86
87 int my_rank=0;
88 MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
89 int world_size=0;
90 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
91
92 unsigned num_coworkers_worker_ = 0;
93 num_coworkers_worker_ = args->getArg<size_t>("num-coworkers");
94
95 unsigned group_start = 0;
96
97 unsigned worker_group = ((my_rank % world_size) - 2) / num_coworkers_worker_;
98
99 unsigned leader_ = group_start + 2 + worker_group * num_coworkers_worker_;
100 leader_ = leader_ % world_size;
101
102 // hash the dictionary to get a short unique directory name for temporary
103 // simulation data
104 std::string hash = NativeHashGenerator::generate(dict);
105
106 std::ostringstream tmp;
107 tmp.precision(15);
108
109 tmp << simTmpDir_ << "/" << hash << "_" << leader_;
110
111 simulationDirName_ = tmp.str();
112
113 std::string tmplDir = args->getArg<std::string>("templates");
114 if (tmplDir.empty()) {
115 if(getenv("TEMPLATES") == nullptr) {
116 throw OptPilotException("OpalSimulation::OpalSimulation",
117 "Environment variable TEMPLATES not defined!");
118 }
119 tmplDir = getenv("TEMPLATES");
120 }
121 std::string tmplFile = tmplDir + "/" + simulationName_ + ".tmpl";
122 // data file is assumed to be located in the root directory
123 std::string dataFile = simulationName_ + ".data";
124
125 if (!fs::exists(tmplFile))
126 throw OptPilotException("OpalSimulation::OpalSimulation",
127 "The template file '" + tmplFile + "' doesn't exit");
128
129 for (const auto& uvar : userVariables_) {
130 uvars[uvar.first] = uvar.second;
131 }
132
133 gs_.reset(new GenerateOpalSimulation(tmplFile, dataFile, uvars));
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
157void 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") == nullptr) {
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") != nullptr) {
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
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
380 std::cout.setstate(std::ios::failbit);
381#endif
382 // now we can run the simulation
383 run_opal(arg, inputFileName.str(), restartStep, Options::infoLevel, Options::warnLevel, comm_);
384
385 //restoreOut();
386#ifdef SUPRESS_OUTPUT
387 std::cout.clear();
388#endif
389
390 } catch(OpalException *ex) {
391
392 //restoreOut();
393#ifdef SUPRESS_OUTPUT
394 std::cout.clear();
395#endif
396
397 std::cerr << "Opal exception during simulation run: \n"
398 << ex->where() << "\n"
399 << ex->what() << std::endl;
400 std::cerr << "Continuing, disregarding this simulation.."
401 << std::endl;
402
403 } catch(ClassicException *ex) {
404
405 //restoreOut();
406#ifdef SUPRESS_OUTPUT
407 std::cout.clear();
408#endif
409
410 std::cerr << "Classic exception during simulation run: \n"
411 << ex->where() << "\n"
412 << ex->what() << std::endl;
413 std::cerr << "Continuing, disregarding this simulation.."
414 << std::endl;
415 } catch(std::exception &ex) {
416#ifdef SUPRESS_OUTPUT
417 std::cout.clear();
418#endif
419 std::cerr << "Exception occured during simulation run: \n"
420 << ex.what() << std::endl
421 << "Continuing, disregarding this simulation.." << std::endl;
422 } catch(...) {
423#ifdef SUPRESS_OUTPUT
424 std::cout.clear();
425#endif
426 std::cerr << "Unknown exception occured during simulation run.\n"
427 << "Continuing, disregarding this simulation.." << std::endl;
428
429 }
430
432
433 delete[] inputfile;
434 err = chdir(pwd_.c_str());
435 if (err != 0) {
436 std::cerr << "Cannot chdir to "
437 << pwd_ << std::endl;
438 }
439}
440
441
442std::map<std::string, std::vector<double> > OpalSimulation::getData(const std::vector<std::string> &statVariables) {
443 std::map<std::string, std::vector<double> > ret;
444 SDDS::SDDSParser parser(simulationDirName_ + "/" + simulationName_ + ".stat");
445 parser.run();
446 for (const std::string &var : statVariables) {
448 try {
449 column = parser.getColumnData(var);
450 } catch (SDDSParserException &e) {
451 std::cout << "failed to read data: " << e.what() << " in " << e.where() << std::endl;
452 continue;
453 }
454
455 std::vector<double> values;
456 values.reserve(column.size());
457 auto type = parser.getColumnType(var);
458 for (const auto& val: column) {
459 values.push_back(parser.getBoostVariantValue<double>(val,(int)type));
460 }
461 ret.insert(std::make_pair(var, values));
462 }
463
464 return ret;
465}
466
468
469 // std::cout << "collectResults" << std::endl;
470
471 // clear old solutions
472 requestedVars_.clear();
473
474 int err = chdir(simulationDirName_.c_str());
475 if (err != 0) {
476 std::cout << "Cannot chdir to "
477 << simulationDirName_.c_str() << std::endl;
478 std::cout << "Continuing, with cleanup.."
479 << std::endl;
480 cleanUp();
481 return;
482 }
483
484 std::string fn = simulationName_ + ".stat";
485 struct stat fileInfo;
486
487 // if no stat file, simulation parameters produced invalid bunch
488 if(stat(fn.c_str(), &fileInfo) != 0) {
489 invalidBunch();
490 } else {
492 try {
493 for(namedIt=objectives_.begin(); namedIt!=objectives_.end(); ++namedIt) {
494 if (namedIt->first == "dummy") continue; // FIXME SamplePilot has default objective named dummy
495 Expressions::Expr_t *objective = namedIt->second;
496
497 // find out which variables we need in order to evaluate the objective
498 variableDictionary_t variable_dictionary;
499 getVariableDictionary(variable_dictionary,fn,objective);
500
501 // and evaluate the expression using the built dictionary of
502 // variable values
503 Expressions::Result_t result =
504 objective->evaluate(variable_dictionary);
505
506 std::vector<double> values;
507 values.push_back(boost::get<0>(result));
508 bool is_valid = boost::get<1>(result);
509
510 reqVarInfo_t tmps = {EVALUATE, values, is_valid};
511 requestedVars_.insert(
512 std::pair<std::string, reqVarInfo_t>(namedIt->first, tmps));
513
514 }
515
516 // .. and constraints
517 for(namedIt=constraints_.begin(); namedIt!=constraints_.end(); ++namedIt) {
518
519 Expressions::Expr_t *constraint = namedIt->second;
520
521 // find out which variables we need in order to evaluate the constraint
522 variableDictionary_t variable_dictionary;
523 getVariableDictionary(variable_dictionary,fn,constraint);
524
525 Expressions::Result_t result =
526 constraint->evaluate(variable_dictionary);
527
528 std::vector<double> values;
529 values.push_back(boost::get<0>(result));
530 bool is_valid = boost::get<1>(result);
531
532 //FIXME: hack to give feedback about values of LHS and RHS
533 std::string constr_str = constraint->toString();
534 std::vector<std::string> split;
535 boost::split(split, constr_str, boost::is_any_of("<>!="),
536 boost::token_compress_on);
537 std::string lhs_constr_str = split[0];
538 std::string rhs_constr_str = split[1];
539 boost::trim_left_if(rhs_constr_str, boost::is_any_of("="));
540
541 functionDictionary_t funcs = constraint->getRegFuncs();
542 boost::scoped_ptr<Expressions::Expr_t> lhs(
543 new Expressions::Expr_t(lhs_constr_str, funcs));
544 boost::scoped_ptr<Expressions::Expr_t> rhs(
545 new Expressions::Expr_t(rhs_constr_str, funcs));
546
547 Expressions::Result_t lhs_res = lhs->evaluate(variable_dictionary);
548 Expressions::Result_t rhs_res = rhs->evaluate(variable_dictionary);
549
550 values.push_back(boost::get<0>(lhs_res));
551 values.push_back(boost::get<0>(rhs_res));
552
553 reqVarInfo_t tmps = {EVALUATE, values, is_valid};
554 requestedVars_.insert(
555 std::pair<std::string, reqVarInfo_t>(namedIt->first, tmps));
556
557 }
558 } catch(SDDSParserException &e) {
559 std::cout << "Evaluation of objective or constraint " << namedIt->first << " threw an exception ('" << e.what() << "' in " << e.where() << ")!" << std::endl;
560 invalidBunch();
561 } catch(OptPilotException &e) {
562 std::cout << "Evaluation of objective or constraint " << namedIt->first << " threw an exception ('" << e.what() << "' in " << e.where() << ")!" << std::endl;
563 invalidBunch();
564 } catch(std::exception &e) {
565 std::cout << "Evaluation of objective or constraint " << namedIt->first << " threw an exception ('" << e.what() << "')!" << std::endl;
566 invalidBunch();
567 } catch(...) {
568 std::cout << "Evaluation of objective or constraint " << namedIt->first << " threw an exception!" << std::endl;
569 invalidBunch();
570 }
571
572 }
573
574 err = chdir(pwd_.c_str());
575 if (err != 0) {
576 std::cout << "Cannot chdir to "
577 << simulationDirName_.c_str() << std::endl;
578 }
579}
580
582 const std::string& filename,
583 const Expressions::Expr_t* const expression) {
584
585 std::set<std::string> req_vars = expression->getReqVars();
586
587 // first check if required variables are design variables
588 for (auto req_it = req_vars.begin(); req_it!=req_vars.end();) {
589 auto it = userVariables_.find(*req_it);
590 if (it==userVariables_.end()) { // not a design var
591 ++req_it;
592 continue;
593 }
594 double value = std::stod((*it).second);
595 dictionary.insert(std::pair<std::string, double>(*req_it, value));
596 req_it = req_vars.erase(req_it); // remove and update iterator to next
597 }
598
599 if(req_vars.empty()) return;
600
601 // get remaining required variable values from the stat file
602 boost::scoped_ptr<SDDSReader> sddsr(new SDDSReader(filename));
603 sddsr->parseFile();
604
605 for(std::string req_var : req_vars) {
606 if(dictionary.count(req_var) != 0) continue;
607
608 double value = 0.0;
609 sddsr->getValue(-1 /*atTime*/, req_var, value);
610 dictionary.insert(std::pair<std::string, double>(req_var, value));
611 }
612}
613
615
616 for(auto namedObjective : objectives_) {
617 std::vector<double> tmp_values;
618 tmp_values.push_back(0.0);
619 reqVarInfo_t tmps = {EVALUATE, tmp_values, false};
620 requestedVars_.insert(
621 std::pair<std::string, reqVarInfo_t>(namedObjective.first, tmps));
622 }
623}
624
626 namespace fs = boost::filesystem;
627 try {
628 int my_rank = 0;
629 MPI_Comm_rank(comm_, &my_rank);
630 if (my_rank == 0) {
631 fs::path p(simulationDirName_.c_str());
632 fs::remove_all(p);
633 }
634 } catch(fs::filesystem_error &ex) {
635 std::cout << "Can't remove directory '" << simulationDirName_ << "', (" << ex.what() << ")" << std::endl;
636 } catch(...) {
637 std::cout << "Can't remove directory '" << simulationDirName_ << "'" << std::endl;
638 }
639}
640
641void OpalSimulation::cleanUp(const std::vector<std::string>& keep) {
642 namespace fs = boost::filesystem;
643
644 if ( keep.empty() ) {
645 // if empty we keep all files
646 return;
647 }
648
649 try {
650 int my_rank = 0;
651 MPI_Comm_rank(comm_, &my_rank);
652 if (my_rank != 0) {
653 return;
654 }
655 fs::path p(simulationDirName_.c_str());
656 {
657 fs::directory_iterator it{p};
658 while (it != fs::directory_iterator{}) {
659 std::string extension = Util::toUpper(fs::extension(it->path().filename()));
660
661 // remove .
662 extension.erase(0, 1);
663
664 auto result = std::find(keep.begin(), keep.end(), extension);
665
666 if ( result == keep.end() && ! fs::is_directory(it->path())) {
667 fs::remove(it->path());
668 }
669 ++it;
670 }
671 }
672 {
673 fs::directory_iterator it{p};
674 while (it != fs::directory_iterator{}) {
675 if (fs::is_directory(it->path()) && fs::is_empty(it->path())) {
676 fs::remove(it->path());
677 }
678 ++it;
679 }
680 }
681 } catch(fs::filesystem_error &ex) {
682 std::cout << "Can't remove file in directory '" << simulationDirName_
683 << "', (" << ex.what() << ")" << std::endl;
684 } catch(...) {
685 std::cout << "Can't remove file in directory '" << simulationDirName_
686 << "'" << std::endl;
687 }
688}
int run_opal(char *[], std::string inputfile, int restartStep, int infoLevel, int warnLevel, MPI_Comm comm)
Definition: opal.cpp:32
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
arg(a))
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
@ EVALUATE
Definition: Types.h:42
namedVariableCollection_t Param_t
Definition: Types.h:48
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:176
const std::string name
std::map< std::string, client::function::type > functionDictionary_t
Definition: Expression.h:56
std::map< std::string, double > variableDictionary_t
Definition: Expression.h:55
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Definition: Expression.h:74
const T * find(const T table[], const std::string &name)
Look up name.
Definition: TFind.h:34
boost::tuple< double, bool > Result_t
Definition: Expression.h:66
constexpr double e
The value of.
Definition: Physics.h:39
std::string::iterator iterator
Definition: MSLang.h:16
bool warn
Warn flag.
Definition: Options.cpp:33
int warnLevel
Definition: Options.cpp:34
int infoLevel
Definition: Options.cpp:29
bool info
Info flag.
Definition: Options.cpp:28
int seed
The current random seed.
Definition: Options.cpp:37
std::string toUpper(const std::string &str)
Definition: Util.cpp:146
boost::function< boost::tuple< double, bool >(arguments_t)> type
Definition: function.hpp:21
FRONT * fs
Definition: hypervolume.cpp:59
std::vector< variant_t > columnData_t
Definition: ast.hpp:50
The global OPAL structure.
Definition: OpalData.h:49
void setOptimizerFlag()
Definition: OpalData.cpp:292
static OpalData * getInstance()
Definition: OpalData.cpp:196
The abstract base class for all exceptions in CLASSIC.
std::string pwd_
holds current directory (for restoring)
void invalidBunch()
mark a solution as invalid
virtual ~OpalSimulation()
std::map< std::string, std::vector< double > > getData(const std::vector< std::string > &statVariables)
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
reqVarContainer_t requestedVars_
holds solutions returned to the optimizer
void setupSimulation()
create directories, input files, fieldmaps...
void copyH5_m()
copy H5 file
void redirectOutToFile()
redirect stdout and stderr to file
Expressions::Named_t objectives_
std::streambuf * strm_err_
stream buffer to redirect stderr
std::string simulationDirName_
full path of simulation directory (where simulation will be run)
std::set< std::string > dvarNames_
Expressions::Named_t constraints_
std::map< std::string, std::string > userVariables_
variable dictionary holding requested optimizer values
boost::scoped_ptr< GenerateOpalSimulation > gs_
object to generate simulation input files
std::string simTmpDir_
temporary directory for simulation data (environment var SIMTMPDIR)
std::streambuf * strm_buffer_
stream buffer to redirect output
void createSymlink_m(const std::string &path)
create symbolic links
std::string simulationName_
identification of the simulation (corresponding to output filename)
bool hasResultsAvailable()
check if we already have simulated the current set of design vars
void setupFSStructure()
create directories, input files, symlinks...
void collectResults()
Parse SDDS stat file and build up requested variable dictionary.
void restoreOut()
restore stdout and stderr to default
int id_m
job id (SAMPLE command)
OpalSimulation(Expressions::Named_t objectives, Expressions::Named_t constraints, Param_t params, std::string name, MPI_Comm comm, CmdArguments_t args, std::map< std::string, std::string > uvars)
The base class for all OPAL exceptions.
Definition: OpalException.h:28
virtual const std::string & what() const
Return the message string for the exception.
virtual const std::string & where() const
Return the name of the method or function which detected the exception.
std::string toString() const
Definition: Expression.h:126
functionDictionary_t getRegFuncs() const
Definition: Expression.h:127
Expressions::Result_t evaluate(variableDictionary_t vars)
evaluate an expression given a value dictionary of free variables
Definition: Expression.h:133
std::set< std::string > getReqVars() const
Definition: Expression.h:124
CmdArguments_t getArgs()
Definition: Simulation.h:48
static std::string generate(std::vector< std::string > arguments, size_t world_pid=0)
ast::columnData_t getColumnData(const std::string &columnName)
Definition: SDDSParser.cpp:116
ast::datatype getColumnType(const std::string &col_name)
Definition: SDDSParser.h:71
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:203