Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#418 Update following 3259 dynawo. #420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions sources/Launcher/DYNComputeLoadVariationLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "DYNAggrResXmlExporter.h"

#include <JOBXmlImporter.h>
#include <JOBIterators.h>
#include <JOBJobsCollection.h>
#include <JOBJobEntry.h>
#include <DYNFileSystemUtils.h>
Expand All @@ -45,8 +44,8 @@ ComputeLoadVariationLauncher::launch() {
subDir << "step-" << variation_;
std::string workingDir = createAbsolutePath(loadIncrease->getId(), createAbsolutePath(subDir.str(), workingDirectory_));
if (!exists(workingDir))
create_directory(workingDir);
else if (!is_directory(workingDir))
createDirectory(workingDir);
else if (!isDirectory(workingDir))
throw DYNAlgorithmsError(DirectoryDoesNotExist, workingDir);

inputs_.readInputs(workingDirectory_, loadIncrease->getJobsFile());
Expand Down
8 changes: 3 additions & 5 deletions sources/Launcher/DYNComputeSimulationLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "MacrosMessage.h"

#include <DYNFileSystemUtils.h>
#include <JOBIterators.h>
#include <JOBJobEntry.h>
#include <JOBOutputsEntry.h>
#include <JOBJobsCollection.h>
Expand All @@ -40,7 +39,7 @@ void
ComputeSimulationLauncher::launch() {
boost::posix_time::ptime t0 = boost::posix_time::second_clock::local_time();
std::string outputFileFullPath = outputFile_;
std::string workingDir = absolute(remove_file_name(inputFile_));
std::string workingDir = absolute(removeFileName(inputFile_));
workingDirectory_ = workingDir;
initLog();
if (outputFileFullPath.empty()) {
Expand All @@ -49,9 +48,8 @@ ComputeSimulationLauncher::launch() {
job::XmlImporter importer;
boost::shared_ptr<job::JobsCollection> jobsCollection = importer.importFromFile(inputFile_);
workingDirectory_ = workingDir;
for (job::job_iterator itJobEntry = jobsCollection->begin(); itJobEntry != jobsCollection->end(); ++itJobEntry) {
boost::shared_ptr<job::JobEntry>& job = *itJobEntry;
std::cout << DYNLog(LaunchingJob, (*itJobEntry)->getName()) << std::endl;
for (auto& job : jobsCollection->getNonCstJobs()) {
std::cout << DYNLog(LaunchingJob, job->getName()) << std::endl;
SimulationResult result;
SimulationParameters params;
initParametersWithJob(job, params);
Expand Down
156 changes: 75 additions & 81 deletions sources/Launcher/DYNMarginCalculationLauncher.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sources/Launcher/DYNMultiVariantInputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MultiVariantInputs::readInputs(const std::string& workingDirectory, const std::s
job::XmlImporter importer;
boost::shared_ptr<job::JobsCollection> jobsCollection = importer.importFromFile(createAbsolutePath(jobFile, workingDirectory));
// implicit : only one job per file
jobEntry_ = *jobsCollection->begin();
jobEntry_ = jobsCollection->getJobs()[0];

// Compute the iidm file path according to the criteria:
// - priority to the file given in parameter
Expand Down
72 changes: 33 additions & 39 deletions sources/Launcher/DYNRobustnessAnalysisLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <JOBDynModelsEntryFactory.h>
#include <JOBModelerEntry.h>
#include <JOBSimulationEntryFactory.h>
#include <JOBIterators.h>
#include <JOBJobsCollection.h>
#include <DYNMacrosMessage.h>
#include <DYNDataInterfaceFactory.h>
Expand Down Expand Up @@ -97,15 +96,15 @@ void
RobustnessAnalysisLauncher::init(const bool doInitLog) {
// check if directory exists, if directory is not set, workingDirectory is the current directory
workingDirectory_ = "";
if ( directory_ == "" ) {
workingDirectory_ = current_path();
if (directory_.empty()) {
workingDirectory_ = currentPath();
} else if (!isAbsolutePath(directory_)) {
workingDirectory_ = createAbsolutePath(directory_, current_path());
workingDirectory_ = createAbsolutePath(directory_, currentPath());
} else {
workingDirectory_ = directory_;
}

if ( !is_directory(workingDirectory_) )
if (!isDirectory(workingDirectory_))
throw DYNAlgorithmsError(DirectoryDoesNotExist, workingDirectory_);

if (doInitLog && multiprocessing::context().isRootProc())
Expand Down Expand Up @@ -145,7 +144,7 @@ RobustnessAnalysisLauncher::init(const bool doInitLog) {

struct Version {
Version() {}
Version(std::string n, std::string v, std::string b, std::string h) :
Version(const std::string& n, const std::string& v, const std::string& b, const std::string& h) :
projectName(n),
versionString(v),
gitBranch(b),
Expand All @@ -158,7 +157,7 @@ struct Version {
};

void
RobustnessAnalysisLauncher::initLog() {
RobustnessAnalysisLauncher::initLog() const {
std::vector<Trace::TraceAppender> appenders;
Trace::TraceAppender appender;
std::string outputPath(createAbsolutePath("dynawo.log", workingDirectory_));
Expand All @@ -182,8 +181,8 @@ RobustnessAnalysisLauncher::initLog() {

// known projects versions
std::vector<Version> versions;
versions.push_back(Version("Dynawo", DYNAWO_VERSION_STRING, DYNAWO_GIT_BRANCH, DYNAWO_GIT_HASH));
versions.push_back(Version("Dynawo-algorithms", DYNAWO_ALGORITHMS_VERSION_STRING, DYNAWO_ALGORITHMS_GIT_BRANCH, DYNAWO_ALGORITHMS_GIT_HASH));
versions.emplace_back(Version("Dynawo", DYNAWO_VERSION_STRING, DYNAWO_GIT_BRANCH, DYNAWO_GIT_HASH));
versions.emplace_back(Version("Dynawo-algorithms", DYNAWO_ALGORITHMS_VERSION_STRING, DYNAWO_ALGORITHMS_GIT_BRANCH, DYNAWO_ALGORITHMS_GIT_HASH));
std::set<std::string> projects;
projects.insert("DYNAWO");
projects.insert("DYNAWO-ALGORITHMS");
Expand All @@ -201,7 +200,7 @@ RobustnessAnalysisLauncher::initLog() {
std::string gitHash = section.second.get("GIT_HASH", "0");
std::string project = boost::algorithm::to_upper_copy(section.first);
if (projects.count(project) == 0) {
versions.push_back(Version(section.first, versionString, gitBranch, gitHash));
versions.emplace_back(Version(section.first, versionString, gitBranch, gitHash));
projects.insert(project);
}
}
Expand All @@ -226,10 +225,9 @@ RobustnessAnalysisLauncher::unzipAndGetMultipleJobsFileName(const std::string& i
// Only the main proc should open the archive
// Unzip the input file in the working directory
boost::shared_ptr<zip::ZipFile> archive = zip::ZipInputStream::read(inputFileFullPath);
for (std::map<std::string, boost::shared_ptr<zip::ZipEntry> >::const_iterator itE = archive->getEntries().begin();
itE != archive->getEntries().end(); ++itE) {
std::string nom = itE->first;
std::string data(itE->second->getData());
for (const auto& entry : archive->getEntries()) {
std::string nom = entry.first;
std::string data(entry.second->getData());
std::ofstream file;
file.open(createAbsolutePath(nom, workingDirectory_).c_str(), std::ios::binary);
file << data;
Expand Down Expand Up @@ -358,13 +356,12 @@ RobustnessAnalysisLauncher::createAndInitSimulation(const std::string& workingDi
result.setLostEquipmentsFileExtensionFromExportMode("XML");

if (job->getOutputsEntry() && job->getOutputsEntry()->getLogsEntry()) {
std::vector<boost::shared_ptr<job::AppenderEntry> > appendersEntry = job->getOutputsEntry()->getLogsEntry()->getAppenderEntries();
for (std::vector<boost::shared_ptr<job::AppenderEntry> >::iterator itApp = appendersEntry.begin(), itAppEnd = appendersEntry.end();
itApp != itAppEnd; ++itApp) {
if ((*itApp)->getTag() == "") {
const std::vector<boost::shared_ptr<job::AppenderEntry> >& appendersEntry = job->getOutputsEntry()->getLogsEntry()->getAppenderEntries();
for (const auto& appenderEntry : appendersEntry) {
if (appenderEntry->getTag().empty()) {
std::string file = createAbsolutePath(job->getOutputsEntry()->getOutputsDirectory(), workingDir);
file = createAbsolutePath("logs", file);
file = createAbsolutePath((*itApp)->getFilePath(), file);
file = createAbsolutePath(appenderEntry->getFilePath(), file);
result.setLogPath(file);
break;
}
Expand Down Expand Up @@ -463,17 +460,17 @@ RobustnessAnalysisLauncher::writeOutputs(const SimulationResult& result) const {
Trace::resetCustomAppenders(); // to force flush
Trace::resetPersistantCustomAppender(logTag_, DYN::INFO); // to force flush
std::string constraintPath = createAbsolutePath("constraints", workingDirectory_);
if (!is_directory(constraintPath))
create_directory(constraintPath);
if (!isDirectory(constraintPath))
createDirectory(constraintPath);
std::string timelinePath = createAbsolutePath("timeLine", workingDirectory_);
if (!is_directory(timelinePath))
create_directory(timelinePath);
if (!isDirectory(timelinePath))
createDirectory(timelinePath);
std::string lostEquipmentsPath = createAbsolutePath("lostEquipments", workingDirectory_);
if (!is_directory(lostEquipmentsPath))
create_directory(lostEquipmentsPath);
if (!isDirectory(lostEquipmentsPath))
createDirectory(lostEquipmentsPath);
std::string logPath = createAbsolutePath("logs", workingDirectory_);
if (!is_directory(logPath))
create_directory(logPath);
if (!isDirectory(logPath))
createDirectory(logPath);
if (!result.getConstraintsStreamStr().empty()) {
std::ofstream file;
std::string filepath = createAbsolutePath("constraints_" + result.getUniqueScenarioId() + "." + result.getConstraintsFileExtension(), constraintPath);
Expand Down Expand Up @@ -528,11 +525,8 @@ RobustnessAnalysisLauncher::writeResults() const {
if (zipIt) {
boost::shared_ptr<zip::ZipFile> archive = zip::ZipFileFactory::newInstance();

for (std::map<std::string, std::string>::const_iterator it = mapData.begin();
it != mapData.end();
it++) {
archive->addEntry(it->first, it->second);
}
for (const auto& mapPair : mapData)
archive->addEntry(mapPair.first, mapPair.second);

zip::ZipOutputStream::write(outputFileFullPath_, archive);
}
Expand Down Expand Up @@ -728,10 +722,10 @@ RobustnessAnalysisLauncher::cleanResult(const std::string& id) const {

bool
RobustnessAnalysisLauncher::findExportIIDM(const std::vector<boost::shared_ptr<job::FinalStateEntry> >& finalStates) {
for (std::vector<boost::shared_ptr<job::FinalStateEntry> >::const_iterator it = finalStates.begin(); it != finalStates.end(); ++it) {
if (!(*it)->getTimestamp()) {
for (const auto& finalState : finalStates) {
if (!finalState->getTimestamp()) {
// one without timestamp : it means that it concerns the final state
return (*it)->getExportIIDMFile();
return finalState->getExportIIDMFile();
}
}

Expand All @@ -740,18 +734,18 @@ RobustnessAnalysisLauncher::findExportIIDM(const std::vector<boost::shared_ptr<j

bool
RobustnessAnalysisLauncher::findExportDump(const std::vector<boost::shared_ptr<job::FinalStateEntry> >& finalStates) {
for (std::vector<boost::shared_ptr<job::FinalStateEntry> >::const_iterator it = finalStates.begin(); it != finalStates.end(); ++it) {
if (!(*it)->getTimestamp()) {
for (const auto& finalState : finalStates) {
if (!finalState->getTimestamp()) {
// one without timestamp : it means that it concerns the final state
return (*it)->getExportDumpFile();
return finalState->getExportDumpFile();
}
}

return false;
}

void
RobustnessAnalysisLauncher::initParametersWithJob(boost::shared_ptr<job::JobEntry> job, SimulationParameters& params) {
RobustnessAnalysisLauncher::initParametersWithJob(const boost::shared_ptr<job::JobEntry>& job, SimulationParameters& params) {
const std::vector<boost::shared_ptr<job::FinalStateEntry> >& finalStateEntries = job->getOutputsEntry()->getFinalStateEntries();
// It is considered that only the first final entry is relevant for parameters for systematic analysis
if (!finalStateEntries.empty()) {
Expand Down
4 changes: 2 additions & 2 deletions sources/Launcher/DYNRobustnessAnalysisLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class RobustnessAnalysisLauncher {
* @param job the job to use
* @param params the parameters to update
*/
static void initParametersWithJob(boost::shared_ptr<job::JobEntry> job, SimulationParameters& params);
static void initParametersWithJob(const boost::shared_ptr<job::JobEntry>& job, SimulationParameters& params);

/**
* @brief Export a save result file
Expand All @@ -211,7 +211,7 @@ class RobustnessAnalysisLauncher {
/**
* @brief Initialize algorithm log
*/
void initLog();
void initLog() const;

protected:
const std::string logTag_; ///< tag string in dynawo.log
Expand Down
5 changes: 2 additions & 3 deletions sources/Launcher/DYNSystematicAnalysisLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <DYNSimulation.h>
#include <DYNError.h>
#include <JOBXmlImporter.h>
#include <JOBIterators.h>
#include <JOBJobsCollection.h>
#include <JOBJobEntry.h>
#include <JOBOutputsEntry.h>
Expand Down Expand Up @@ -82,8 +81,8 @@ SystematicAnalysisLauncher::launch() {
multiprocessing::forEach(0, events.size(), [this, &events](unsigned int i){
std::string workingDir = createAbsolutePath(events[i]->getId(), workingDirectory_);
if (!exists(workingDir))
create_directory(workingDir);
else if (!is_directory(workingDir))
createDirectory(workingDir);
else if (!isDirectory(workingDir))
throw DYNAlgorithmsError(DirectoryDoesNotExist, workingDir);
});

Expand Down
11 changes: 5 additions & 6 deletions sources/Launcher/test/TestRobustnessAnalysisLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include <DYNFileSystemUtils.h>
#include <JOBXmlImporter.h>
#include <JOBIterators.h>
#include <JOBJobsCollection.h>
#include <JOBJobEntry.h>
#include <JOBModelerEntry.h>
Expand Down Expand Up @@ -134,7 +133,7 @@ TEST(TestLauncher, TestRobustnessAnalysisLauncher) {
MyLauncher launcher;

launcher.testInputFile("");
std::string absoluteFile = createAbsolutePath("MyAbsoluteFile", current_path());
std::string absoluteFile = createAbsolutePath("MyAbsoluteFile", currentPath());
launcher.setInputFile(absoluteFile);
launcher.testInputFile(absoluteFile);

Expand All @@ -147,16 +146,16 @@ TEST(TestLauncher, TestRobustnessAnalysisLauncher) {
launcher.testDirectory("MyDirectory");

ASSERT_THROW_DYNAWO(launcher.init(), DYN::Error::GENERAL, DYNAlgorithms::KeyAlgorithmsError_t::DirectoryDoesNotExist);
launcher.testWorkingDirectory(createAbsolutePath("MyDirectory", current_path()));
launcher.testWorkingDirectory(createAbsolutePath("MyDirectory", currentPath()));

std::string absoluteDir = createAbsolutePath("MyAbsoluteDirectory", current_path());
std::string absoluteDir = createAbsolutePath("MyAbsoluteDirectory", currentPath());
launcher.setDirectory(absoluteDir);
ASSERT_THROW_DYNAWO(launcher.init(), DYN::Error::GENERAL, DYNAlgorithms::KeyAlgorithmsError_t::DirectoryDoesNotExist);
launcher.testWorkingDirectory(absoluteDir);

launcher.setDirectory("");
ASSERT_THROW_DYNAWO(launcher.init(), DYN::Error::GENERAL, DYNAlgorithms::KeyAlgorithmsError_t::FileDoesNotExist);
launcher.testWorkingDirectory(current_path());
launcher.testWorkingDirectory(currentPath());

launcher.setInputFile("res/MyDummyInputFile.xml");
ASSERT_THROW_DYNAWO(launcher.init(), DYN::Error::GENERAL, DYNAlgorithms::KeyAlgorithmsError_t::FileDoesNotExist);
Expand All @@ -171,7 +170,7 @@ TEST(TestLauncher, TestRobustnessAnalysisLauncher) {
launcher.setDirectory("res");
launcher.setOutputFile("MyOutputFile.zip");
ASSERT_NO_THROW(launcher.init());
launcher.testOutputFileFullPath(createAbsolutePath("MyOutputFile.zip", createAbsolutePath("res", current_path())));
launcher.testOutputFileFullPath(createAbsolutePath("MyOutputFile.zip", createAbsolutePath("res", currentPath())));
launcher.testMultipleJobs();
launcher.launch();
}
Expand Down
Loading