Skip to content

Commit

Permalink
#810 Add the possibility to zip the inputs and outputs for N simulation
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitri Baron <[email protected]>
  • Loading branch information
barondim committed Dec 20, 2024
1 parent 901fea6 commit 60b29e5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions sources/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ target_link_libraries(dfl_Common

PRIVATE
Boost::filesystem
libZIP::libZIP
)
add_library(DynaFlowLauncher::common ALIAS dfl_Common)
install(FILES ${CMAKE_SOURCE_DIR}/etc/Dictionaries/DFLLog_en_GB.dic ${CMAKE_SOURCE_DIR}/etc/Dictionaries/DFLError_en_GB.dic DESTINATION share)
Expand Down
2 changes: 1 addition & 1 deletion sources/Common/include/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#pragma once

#include <boost/optional.hpp>
#include <boost/program_options.hpp>
#include <iostream>
#include <string>
Expand Down Expand Up @@ -43,6 +42,7 @@ class Options {
std::string networkFilePath; ///< Network filepath to process
std::string contingenciesFilePath; ///< Contingencies filepath for security analysis
std::string configPath; ///< Launcher configuration filepath
std::string zipArchivePath; ///< zip archive path to unzip to get input files
std::string dynawoLogLevel; ///< chosen log level
};

Expand Down
39 changes: 31 additions & 8 deletions sources/Common/src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#include "version.h"

#include <libzip/ZipInputStream.h>

#include <DYNFileSystemUtils.h>

#include <algorithm>
#include <boost/filesystem.hpp>
#include <sstream>
Expand Down Expand Up @@ -81,14 +85,18 @@ Options::basename(const std::string& filepath) {
return path.filename().replace_extension().generic_string();
}

Options::Options() : desc_{}, config_{"", "", "", "", defaultLogLevel_} {
desc_.add_options()("help,h", "Display help message")(
"log-level", po::value<ParsedLogLevel>(),
(std::string("Dynawo logger level (allowed values are ERROR, WARN, INFO, DEBUG): default is ") + defaultLogLevel_).c_str())(
"network", po::value<std::string>(&config_.networkFilePath)->required(), "Network file path to process (IIDM support only)")(
"contingencies", po::value<std::string>(&config_.contingenciesFilePath), "Contingencies file path to process (Security Analysis)")(
"config", po::value<std::string>(&config_.configPath)->required(), "launcher Configuration file to use")("version,v", "Display version")(
"nsa", "Run steady state calculation followed by security analysis. Requires contingencies file to be defined.");
Options::Options() : desc_{}, config_{"", "", "", "", "", defaultLogLevel_} {
desc_.add_options()
("help,h", "Display help message")
("version,v", "Display version")
("log-level", po::value<ParsedLogLevel>(),
(std::string("Dynawo logger level (allowed values are ERROR, WARN, INFO, DEBUG): default is ") + defaultLogLevel_).c_str())
("network", po::value<std::string>(&config_.networkFilePath)->required(), "Network file path to process (IIDM support only)")
("config", po::value<std::string>(&config_.configPath)->required(), "launcher Configuration file to use")
("contingencies", po::value<std::string>(&config_.contingenciesFilePath), "Contingencies file path to process (Security Analysis)")
("nsa", "Run steady state calculation followed by security analysis. Requires contingencies file to be defined.")
("input-archive", po::value<std::string>(&config_.zipArchivePath),
"Path to a ZIP archive containing input files for '--network', '--config', and '--contingencies'.");
}

Options::Request
Expand All @@ -108,6 +116,21 @@ Options::parse(int argc, char* argv[]) {

po::notify(vm);

if (vm.count("input-archive") > 0) {
boost::shared_ptr<zip::ZipFile> archive = zip::ZipInputStream::read(config_.zipArchivePath);
std::string archiveParentPath = boost::filesystem::path(config_.zipArchivePath).parent_path().string();
for (std::map<std::string, boost::shared_ptr<zip::ZipEntry>>::const_iterator archiveIt = archive->getEntries().begin();
archiveIt != archive->getEntries().end(); ++archiveIt) {
std::string name = archiveIt->first;
std::string data(archiveIt->second->getData());
std::ofstream file;
std::string filepath = createAbsolutePath(name, archiveParentPath);
file.open(createAbsolutePath(name, archiveParentPath).c_str(), std::ios::binary);
file << data;
file.close();
}
}

// These are not binded automatically
if (vm.count("log-level") > 0) {
config_.dynawoLogLevel = vm["log-level"].as<ParsedLogLevel>().logLevelDefinition;
Expand Down
6 changes: 5 additions & 1 deletion sources/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ void Context::executeSecurityAnalysis() {
multipleJobs->setScenarios(scenarios);
auto saLauncher = boost::make_shared<DYNAlgorithms::SystematicAnalysisLauncher>();
saLauncher->setMultipleJobs(multipleJobs);
saLauncher->setOutputFile("aggregatedResults.xml");
if (def_.outputIsZip) {
saLauncher->setOutputFile("output.zip");
} else {
saLauncher->setOutputFile("aggregatedResults.xml");
}
saLauncher->setDirectory(config_.outputDir().generic_string());
saLauncher->init();
saLauncher->launch();
Expand Down
1 change: 1 addition & 0 deletions sources/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Context {
boost::filesystem::path settingFilePath; ///< setting file path for dynamic data base
boost::filesystem::path assemblingFilePath; ///< assembling file path for dynamic data base
boost::filesystem::path contingenciesFilePath; ///< contigencies file path for Security Analysis simulation
bool outputIsZip; ///< true if the output is zip archive, false otherwise
std::string dynawoLogLevel; ///< string representation of the dynawo log level
boost::filesystem::path dynawoResDir; ///< DYNAWO resources
std::string locale; ///< localization
Expand Down
2 changes: 2 additions & 0 deletions sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ static inline double elapsed(const std::chrono::steady_clock::time_point &timePo

static boost::shared_ptr<dfl::Context> buildContext(dfl::inputs::SimulationParams const &params, dfl::inputs::Configuration &config) {
auto timeContextStart = std::chrono::steady_clock::now();
bool outputIsZip = !params.runtimeConfig->zipArchivePath.empty();
dfl::Context::ContextDef def{config.getStartingPointMode(),
params.simulationKind,
params.networkFilePath,
config.settingFilePath(),
config.assemblingFilePath(),
params.runtimeConfig->contingenciesFilePath,
outputIsZip,
params.runtimeConfig->dynawoLogLevel,
params.resourcesDirPath,
params.locale};
Expand Down

0 comments on commit 60b29e5

Please sign in to comment.