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