From 96c13d7ee62d314093b95f41d1fd07daa3935524 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 11:18:24 +0100 Subject: [PATCH 01/34] Add dir loadfile/ , add readSystem --- src/solver/modeler/CMakeLists.txt | 1 + src/solver/modeler/loadFiles/CMakeLists.txt | 27 ++++++++++++ .../antares/solver/loadFiles/loadFiles.h | 34 ++++++++++++++ src/solver/modeler/loadFiles/readSystem.cpp | 44 +++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 src/solver/modeler/loadFiles/CMakeLists.txt create mode 100644 src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h create mode 100644 src/solver/modeler/loadFiles/readSystem.cpp diff --git a/src/solver/modeler/CMakeLists.txt b/src/solver/modeler/CMakeLists.txt index 3c631240ac..2ad5b9a49d 100644 --- a/src/solver/modeler/CMakeLists.txt +++ b/src/solver/modeler/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(api) add_subdirectory(ortoolsImpl) +add_subdirectory(loadFiles) diff --git a/src/solver/modeler/loadFiles/CMakeLists.txt b/src/solver/modeler/loadFiles/CMakeLists.txt new file mode 100644 index 0000000000..f0ed12e20f --- /dev/null +++ b/src/solver/modeler/loadFiles/CMakeLists.txt @@ -0,0 +1,27 @@ +set(SOURCES + readSystem.cpp +) + +# Create the library +add_library(loadFiles STATIC ${SOURCES}) +add_library(Antares::loadFiles ALIAS loadFiles) + +# Specify include directories +target_include_directories(loadFiles + PUBLIC + $ +) + +# Link dependencies (if any) +target_link_libraries(loadFiles + PUBLIC + Antares::antares-study-system-model + PRIVATE + io + Antares::systemParser + Antares::modelConverter +) + +install(DIRECTORY include/antares + DESTINATION "include" +) diff --git a/src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h b/src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h new file mode 100644 index 0000000000..c3018b9d09 --- /dev/null +++ b/src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h @@ -0,0 +1,34 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + +#pragma once + +#include + +#include "antares/study/system-model/system.h" + +namespace Antares::Solver::LoadFiles +{ + +Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath, + const std::vector& libraries); + +} // namespace Antares::Solver::LoadFiles diff --git a/src/solver/modeler/loadFiles/readSystem.cpp b/src/solver/modeler/loadFiles/readSystem.cpp new file mode 100644 index 0000000000..474b9ece60 --- /dev/null +++ b/src/solver/modeler/loadFiles/readSystem.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + +#include + +#include +#include + +#include "antares/solver/loadFiles/loadFiles.h" + +namespace fs = std::filesystem; + +namespace Antares::Solver::LoadFiles +{ + +Study::SystemModel::System loadSystem(const fs::path& studyPath, const std::vector& libraries) +{ + const std::string systemStr = IO::readFile(studyPath / "input" / "system.yml"); + + SystemParser::Parser parser; + SystemParser::System systemObj = parser.parse(systemStr); + + return SystemConverter::convert(systemObj, libraries);; +} + +} // namespace Antares::Solver::LoadFiles From ffe15545c3988788edee6ed5c149511309ef36f8 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 11:19:59 +0100 Subject: [PATCH 02/34] format --- src/solver/modeler/loadFiles/readSystem.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/solver/modeler/loadFiles/readSystem.cpp b/src/solver/modeler/loadFiles/readSystem.cpp index 474b9ece60..040860fa3e 100644 --- a/src/solver/modeler/loadFiles/readSystem.cpp +++ b/src/solver/modeler/loadFiles/readSystem.cpp @@ -20,10 +20,8 @@ */ #include - #include #include - #include "antares/solver/loadFiles/loadFiles.h" namespace fs = std::filesystem; @@ -31,14 +29,15 @@ namespace fs = std::filesystem; namespace Antares::Solver::LoadFiles { -Study::SystemModel::System loadSystem(const fs::path& studyPath, const std::vector& libraries) +Study::SystemModel::System loadSystem(const fs::path& studyPath, + const std::vector& libraries) { - const std::string systemStr = IO::readFile(studyPath / "input" / "system.yml"); + const std::string systemStr = IO::readFile(studyPath / "input" / "system.yml"); SystemParser::Parser parser; SystemParser::System systemObj = parser.parse(systemStr); - return SystemConverter::convert(systemObj, libraries);; + return SystemConverter::convert(systemObj, libraries); } } // namespace Antares::Solver::LoadFiles From e8da3754e8bae81a19fbbd2f63bb674902214be3 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 11:34:04 +0100 Subject: [PATCH 03/34] add readLibraries.cpp --- src/solver/modeler/loadFiles/CMakeLists.txt | 2 + .../antares/solver/loadFiles/loadFiles.h | 3 +- .../modeler/loadFiles/readLibraries.cpp | 38 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/solver/modeler/loadFiles/readLibraries.cpp diff --git a/src/solver/modeler/loadFiles/CMakeLists.txt b/src/solver/modeler/loadFiles/CMakeLists.txt index f0ed12e20f..81a507a8f5 100644 --- a/src/solver/modeler/loadFiles/CMakeLists.txt +++ b/src/solver/modeler/loadFiles/CMakeLists.txt @@ -1,5 +1,6 @@ set(SOURCES readSystem.cpp + readLibraries.cpp ) # Create the library @@ -19,6 +20,7 @@ target_link_libraries(loadFiles PRIVATE io Antares::systemParser + Antares::modelParser Antares::modelConverter ) diff --git a/src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h b/src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h index c3018b9d09..61c417f585 100644 --- a/src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h +++ b/src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h @@ -23,7 +23,8 @@ #include -#include "antares/study/system-model/system.h" +#include +#include namespace Antares::Solver::LoadFiles { diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp new file mode 100644 index 0000000000..d0acff1a97 --- /dev/null +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -0,0 +1,38 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + +#include +#include +#include +#include "antares/solver/loadFiles/loadFiles.h" + +namespace fs = std::filesystem; + +namespace Antares::Solver::LoadFiles +{ + +Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) +{ + Study::SystemModel::Library lib; + return lib; +} + +} // namespace Antares::Solver::LoadFiles From b4a2a7479b7db90d537d42a7879ed016502eb08d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 11:39:54 +0100 Subject: [PATCH 04/34] add function to read one lib file --- src/solver/modeler/loadFiles/readLibraries.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index d0acff1a97..f96c333d08 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -20,8 +20,8 @@ */ #include -#include #include +#include #include "antares/solver/loadFiles/loadFiles.h" namespace fs = std::filesystem; @@ -29,10 +29,13 @@ namespace fs = std::filesystem; namespace Antares::Solver::LoadFiles { -Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) +static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) { - Study::SystemModel::Library lib; - return lib; + const std::string libraryStr = IO::readFile(filePath); + + ModelParser::Parser parser; + ModelParser::Library libraryObj = parser.parse(libraryStr); + return ModelConverter::convert(libraryObj); } } // namespace Antares::Solver::LoadFiles From 478b08740a74d4221eed333ade0d1ec0269765bf Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 13:26:19 +0100 Subject: [PATCH 05/34] add a loadLibraries func --- .../modeler/loadFiles/readLibraries.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index f96c333d08..daae948199 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -20,6 +20,7 @@ */ #include +#include #include #include #include "antares/solver/loadFiles/loadFiles.h" @@ -38,4 +39,23 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) return ModelConverter::convert(libraryObj); } + +std::vector loadLibraries(const fs::path& studyPath) +{ + std::vector libraries; + + const fs::path directoryPath = studyPath / "input" / "model-libraries"; + for (const auto& entry : fs::directory_iterator(directoryPath)) + { + if (entry.path().extension() != "yml") + { + logs.info() << "File ignored because of wrong extension: " << entry.path(); + continue; + } + + libraries.push_back(loadSingleLibrary(entry.path())); + } + + return libraries; +} } // namespace Antares::Solver::LoadFiles From 67c3754d7b4c3da66dd4741aeea1b15f5d6fcdfa Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 14:08:24 +0100 Subject: [PATCH 06/34] format --- src/solver/modeler/loadFiles/readLibraries.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index daae948199..432385041c 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -39,13 +39,12 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) return ModelConverter::convert(libraryObj); } - std::vector loadLibraries(const fs::path& studyPath) { std::vector libraries; const fs::path directoryPath = studyPath / "input" / "model-libraries"; - for (const auto& entry : fs::directory_iterator(directoryPath)) + for (const auto& entry: fs::directory_iterator(directoryPath)) { if (entry.path().extension() != "yml") { From 2fb43d61807dae89f604fb9d58e9df036dc61d01 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 14:31:21 +0100 Subject: [PATCH 07/34] Add unit test folder --- src/solver/modeler/loadFiles/CMakeLists.txt | 10 ++-- .../{ => modeler}/loadFiles/loadFiles.h | 0 .../modeler/loadFiles/readLibraries.cpp | 2 +- src/solver/modeler/loadFiles/readSystem.cpp | 2 +- src/tests/src/solver/modeler/CMakeLists.txt | 1 + .../solver/modeler/loadFiles/CMakeLists.txt | 14 +++++ .../loadFiles/testLoadModelerFiles.cpp | 54 +++++++++++++++++++ 7 files changed, 77 insertions(+), 6 deletions(-) rename src/solver/modeler/loadFiles/include/antares/solver/{ => modeler}/loadFiles/loadFiles.h (100%) create mode 100644 src/tests/src/solver/modeler/loadFiles/CMakeLists.txt create mode 100644 src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp diff --git a/src/solver/modeler/loadFiles/CMakeLists.txt b/src/solver/modeler/loadFiles/CMakeLists.txt index 81a507a8f5..54ebf5b3e3 100644 --- a/src/solver/modeler/loadFiles/CMakeLists.txt +++ b/src/solver/modeler/loadFiles/CMakeLists.txt @@ -1,20 +1,22 @@ set(SOURCES readSystem.cpp readLibraries.cpp + + include/antares/solver/modeler/loadFiles/loadFiles.h ) # Create the library -add_library(loadFiles STATIC ${SOURCES}) -add_library(Antares::loadFiles ALIAS loadFiles) +add_library(loadModelerFiles STATIC ${SOURCES}) +add_library(Antares::loadModelerFiles ALIAS loadModelerFiles) # Specify include directories -target_include_directories(loadFiles +target_include_directories(loadModelerFiles PUBLIC $ ) # Link dependencies (if any) -target_link_libraries(loadFiles +target_link_libraries(loadModelerFiles PUBLIC Antares::antares-study-system-model PRIVATE diff --git a/src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h b/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h similarity index 100% rename from src/solver/modeler/loadFiles/include/antares/solver/loadFiles/loadFiles.h rename to src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index 432385041c..d71615f080 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -23,7 +23,7 @@ #include #include #include -#include "antares/solver/loadFiles/loadFiles.h" +#include "antares/solver/modeler/loadFiles/loadFiles.h" namespace fs = std::filesystem; diff --git a/src/solver/modeler/loadFiles/readSystem.cpp b/src/solver/modeler/loadFiles/readSystem.cpp index 040860fa3e..f51f5d83d1 100644 --- a/src/solver/modeler/loadFiles/readSystem.cpp +++ b/src/solver/modeler/loadFiles/readSystem.cpp @@ -22,7 +22,7 @@ #include #include #include -#include "antares/solver/loadFiles/loadFiles.h" +#include "antares/solver/modeler/loadFiles/loadFiles.h" namespace fs = std::filesystem; diff --git a/src/tests/src/solver/modeler/CMakeLists.txt b/src/tests/src/solver/modeler/CMakeLists.txt index 53d257b04e..d532a0a77d 100644 --- a/src/tests/src/solver/modeler/CMakeLists.txt +++ b/src/tests/src/solver/modeler/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(api) +add_subdirectory(loadFiles) diff --git a/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt b/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt new file mode 100644 index 0000000000..81bbf085cc --- /dev/null +++ b/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt @@ -0,0 +1,14 @@ +add_executable(load-modeler-files + testLoadModelerFiles.cpp) + +target_link_libraries(load-modeler-files + PRIVATE + Boost::unit_test_framework + Antares::loadModelerFiles + test_utils_unit +) + +set_target_properties(load-modeler-files PROPERTIES FOLDER Unit-tests/test-writer) + +add_test(NAME load-modeler-files COMMAND load-modeler-files) +set_tests_properties(load-modeler-files PROPERTIES LABELS unit) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp new file mode 100644 index 0000000000..8512eeba33 --- /dev/null +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -0,0 +1,54 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ +#define WIN32_LEAN_AND_MEAN + +#include +#define BOOST_TEST_MODULE load modeler files + +#include + +#include + +#include "files-system.h" + +BOOST_AUTO_TEST_SUITE(read_modeler_parameters) + +BOOST_AUTO_TEST_CASE(all_properties_set) +{ + /* const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); */ + /* const auto fileP = working_tmp_dir / "parameters.yaml"; */ + /* { */ + /* std::ofstream param(fileP); */ + /* param << R"( */ + /* solver: sirius */ + /* solver-logs: false */ + /* solver-parameters: PRESOLVE 1 */ + /* no-output: true)"; */ + /* } */ + + /* auto params = Antares::Solver::parseModelerParameters(fileP); */ + /* BOOST_CHECK_EQUAL(params.solver, "sirius"); */ + /* BOOST_CHECK_EQUAL(params.solverLogs, false); */ + /* BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); */ + /* BOOST_CHECK_EQUAL(params.noOutput, true); */ +} + +BOOST_AUTO_TEST_SUITE_END() From ad4ca2d68ec533f99a0e192680c90bcf25bec3f3 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 15:33:37 +0100 Subject: [PATCH 08/34] First test case --- .../solver/modeler/loadFiles/loadFiles.h | 3 ++ .../modeler/loadFiles/readLibraries.cpp | 2 +- .../loadFiles/testLoadModelerFiles.cpp | 51 ++++++++++++------- src/tests/src/utils/files-system.cpp | 4 +- src/tests/src/utils/files-system.h | 2 +- 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h b/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h index 61c417f585..63ab4bb732 100644 --- a/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h +++ b/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include @@ -32,4 +33,6 @@ namespace Antares::Solver::LoadFiles Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath, const std::vector& libraries); +std::vector loadLibraries(const std::filesystem::path& studyPath); + } // namespace Antares::Solver::LoadFiles diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index d71615f080..33fefacc23 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -46,7 +46,7 @@ std::vector loadLibraries(const fs::path& studyPath const fs::path directoryPath = studyPath / "input" / "model-libraries"; for (const auto& entry: fs::directory_iterator(directoryPath)) { - if (entry.path().extension() != "yml") + if (entry.path().extension() != ".yml") { logs.info() << "File ignored because of wrong extension: " << entry.path(); continue; diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index 8512eeba33..d3fe9c4c82 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -31,24 +31,41 @@ BOOST_AUTO_TEST_SUITE(read_modeler_parameters) -BOOST_AUTO_TEST_CASE(all_properties_set) +namespace fs = std::filesystem; + +struct FixtureLoadFile +{ + fs::path studyPath; + fs::path inputPath; + fs::path libraryDirPath; + + FixtureLoadFile() + { + studyPath = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); + inputPath = createFolder(studyPath, "input"); + libraryDirPath = createFolder(inputPath, "model-libraries"); + } + + ~FixtureLoadFile() + { + fs::remove_all(studyPath); + } +}; + +BOOST_FIXTURE_TEST_CASE(read_one_lib_file, FixtureLoadFile) { - /* const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); */ - /* const auto fileP = working_tmp_dir / "parameters.yaml"; */ - /* { */ - /* std::ofstream param(fileP); */ - /* param << R"( */ - /* solver: sirius */ - /* solver-logs: false */ - /* solver-parameters: PRESOLVE 1 */ - /* no-output: true)"; */ - /* } */ - - /* auto params = Antares::Solver::parseModelerParameters(fileP); */ - /* BOOST_CHECK_EQUAL(params.solver, "sirius"); */ - /* BOOST_CHECK_EQUAL(params.solverLogs, false); */ - /* BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); */ - /* BOOST_CHECK_EQUAL(params.noOutput, true); */ + std::ofstream libStream(libraryDirPath / "simple.yml"); + libStream << R"( + library: + id: lib_id + description: lib_description + port-types: [] + models: [] + )"; + libStream.close(); + + auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath); + /* BOOST_CHECK_EQUAL(libraries[0].Id(), "lib_id"); */ } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/tests/src/utils/files-system.cpp b/src/tests/src/utils/files-system.cpp index f6097ee82b..e8d6163ea7 100644 --- a/src/tests/src/utils/files-system.cpp +++ b/src/tests/src/utils/files-system.cpp @@ -10,7 +10,7 @@ fs::path generateAndCreateDirName(const std::string& dirName) return working_dir; } -void createFolder(const std::string& path, const std::string& folder_name) +fs::path createFolder(const std::string& path, const std::string& folder_name) { fs::path folder_path = fs::path(path.c_str()) / folder_name.c_str(); @@ -22,6 +22,8 @@ void createFolder(const std::string& path, const std::string& folder_name) { std::cerr << "Exception creating folder '" + folder_name + "': " + e.what() + "\n"; } + + return folder_path; } void createFile(const std::string& folder_path, const std::string& file_name) diff --git a/src/tests/src/utils/files-system.h b/src/tests/src/utils/files-system.h index 092b498350..9ad4503e54 100644 --- a/src/tests/src/utils/files-system.h +++ b/src/tests/src/utils/files-system.h @@ -31,6 +31,6 @@ std::filesystem::path generateAndCreateDirName(const std::string&); -void createFolder(const std::string& path, const std::string& folder_name); +std::filesystem::path createFolder(const std::string& path, const std::string& folder_name); void createFile(const std::string& folder_path, const std::string& file_name); void removeFolder(std::string& path, std::string& folder_name); From cba7b31a7bcee1191a88db44c7394603082a9c91 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 15:43:52 +0100 Subject: [PATCH 09/34] several libs --- .../loadFiles/testLoadModelerFiles.cpp | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index d3fe9c4c82..7380019f87 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -65,7 +65,54 @@ BOOST_FIXTURE_TEST_CASE(read_one_lib_file, FixtureLoadFile) libStream.close(); auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath); - /* BOOST_CHECK_EQUAL(libraries[0].Id(), "lib_id"); */ + BOOST_CHECK_EQUAL(libraries[0].Id(), "lib_id"); +} + +BOOST_FIXTURE_TEST_CASE(read_several_lib_file, FixtureLoadFile) +{ + std::ofstream libStream(libraryDirPath / "simple.yml"); + libStream << R"( + library: + id: lib_id + description: lib_description + port-types: [] + models: [] + )"; + libStream.close(); + + std::ofstream libStream2(libraryDirPath / "2.yml"); + libStream2 << R"( + library: + id: lib_id2 + description: lib_description + port-types: [] + models: [] + )"; + libStream2.close(); + + std::ofstream libStream3(libraryDirPath / "3.yml"); + libStream3 << R"( + library: + id: lib_id3 + description: lib_description + port-types: [] + models: [] + )"; + libStream3.close(); + + auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath); + + auto checkLibIdInVector = [&libraries](const std::string& libId) + { + return std::ranges::find_if(libraries, [&libId](const auto& l) { return l.Id() == libId; }) + != libraries.end(); + }; + + BOOST_CHECK(checkLibIdInVector("lib_id")); + BOOST_CHECK(checkLibIdInVector("lib_id2")); + BOOST_CHECK(checkLibIdInVector("lib_id3")); + + BOOST_CHECK(!checkLibIdInVector("id not in vector")); } BOOST_AUTO_TEST_SUITE_END() From 78e083f8eeaff18210af4519a27bbee16c061fa2 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 15:48:11 +0100 Subject: [PATCH 10/34] comments --- src/libs/antares/io/CMakeLists.txt | 4 +++- src/solver/modeler/loadFiles/CMakeLists.txt | 2 +- src/solver/modeler/loadFiles/readLibraries.cpp | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/antares/io/CMakeLists.txt b/src/libs/antares/io/CMakeLists.txt index 9e3211e14b..f2f1eae17d 100644 --- a/src/libs/antares/io/CMakeLists.txt +++ b/src/libs/antares/io/CMakeLists.txt @@ -12,6 +12,8 @@ source_group("io" FILES ${SRC_IO}) add_library(io ${SRC_IO} ) +add_library(Antares::io ALIAS io) + target_link_libraries(io PRIVATE @@ -26,4 +28,4 @@ target_include_directories(io install(DIRECTORY include/antares DESTINATION "include" -) \ No newline at end of file +) diff --git a/src/solver/modeler/loadFiles/CMakeLists.txt b/src/solver/modeler/loadFiles/CMakeLists.txt index 54ebf5b3e3..d7a1c0118c 100644 --- a/src/solver/modeler/loadFiles/CMakeLists.txt +++ b/src/solver/modeler/loadFiles/CMakeLists.txt @@ -20,7 +20,7 @@ target_link_libraries(loadModelerFiles PUBLIC Antares::antares-study-system-model PRIVATE - io + Antares::io Antares::systemParser Antares::modelParser Antares::modelConverter diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index 33fefacc23..ebccd6b90c 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -48,7 +48,8 @@ std::vector loadLibraries(const fs::path& studyPath { if (entry.path().extension() != ".yml") { - logs.info() << "File ignored because of wrong extension: " << entry.path(); + logs.info() << entry.path() + << " ignored, only files having the `.yml` extension are loaded"; continue; } From 385f53a32d4fd0131df27f0b6b738eb2bba91be4 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 16:33:43 +0100 Subject: [PATCH 11/34] test load system --- .../loadFiles/testLoadModelerFiles.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index 7380019f87..8f57540fb5 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -115,4 +115,35 @@ BOOST_FIXTURE_TEST_CASE(read_several_lib_file, FixtureLoadFile) BOOST_CHECK(!checkLibIdInVector("id not in vector")); } +BOOST_FIXTURE_TEST_CASE(read_system_file, FixtureLoadFile) +{ + std::ofstream libStream(libraryDirPath / "simple.yml"); + libStream << R"( + library: + id: std + description: lib_description + port-types: [] + models: + - id: generator + description: A basic generator model + + )"; + libStream.close(); + + std::ofstream systemStream(inputPath / "system.yml"); + systemStream << R"( + system: + id: base_system + description: two components + components: + - id: N + model: std.generator + scenario-group: group-234 + )"; + systemStream.close(); + + auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath); + auto system = Antares::Solver::LoadFiles::loadSystem(studyPath, libraries); +} + BOOST_AUTO_TEST_SUITE_END() From 6f8969684bae3127ea1c6d9e010edabf30fcff1d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 16:34:03 +0100 Subject: [PATCH 12/34] comments --- src/solver/modeler/loadFiles/readLibraries.cpp | 1 + src/solver/modeler/loadFiles/readSystem.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index ebccd6b90c..c824883271 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -35,6 +35,7 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) const std::string libraryStr = IO::readFile(filePath); ModelParser::Parser parser; + // Add try/catch and error handling ModelParser::Library libraryObj = parser.parse(libraryStr); return ModelConverter::convert(libraryObj); } diff --git a/src/solver/modeler/loadFiles/readSystem.cpp b/src/solver/modeler/loadFiles/readSystem.cpp index f51f5d83d1..187213b917 100644 --- a/src/solver/modeler/loadFiles/readSystem.cpp +++ b/src/solver/modeler/loadFiles/readSystem.cpp @@ -35,6 +35,7 @@ Study::SystemModel::System loadSystem(const fs::path& studyPath, const std::string systemStr = IO::readFile(studyPath / "input" / "system.yml"); SystemParser::Parser parser; + // Add try/catch and error handling SystemParser::System systemObj = parser.parse(systemStr); return SystemConverter::convert(systemObj, libraries); From 67cd455d3ac5122a5eb005c1e94e6d570a59b735 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 17:03:09 +0100 Subject: [PATCH 13/34] add headers --- src/solver/modeler/parameters/encoder.hxx | 21 ++++++++++++++++++ .../modeler/parameters/modelerParameters.h | 21 ++++++++++++++++++ .../parameters/parseModelerParameters.h | 22 +++++++++++++++++++ .../parameters/parseModelerParameters.cpp | 21 ++++++++++++++++++ 4 files changed, 85 insertions(+) diff --git a/src/solver/modeler/parameters/encoder.hxx b/src/solver/modeler/parameters/encoder.hxx index 32de3e0d83..c43d195ccc 100644 --- a/src/solver/modeler/parameters/encoder.hxx +++ b/src/solver/modeler/parameters/encoder.hxx @@ -1,3 +1,24 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + #include #include "yaml-cpp/yaml.h" diff --git a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/modelerParameters.h b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/modelerParameters.h index c6977a748b..6ea6e1072d 100644 --- a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/modelerParameters.h +++ b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/modelerParameters.h @@ -1,3 +1,24 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + #pragma once #include diff --git a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h index 2409fcddf1..a323b39b0f 100644 --- a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h +++ b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h @@ -1,3 +1,24 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + #pragma once #include @@ -8,4 +29,5 @@ namespace Antares::Solver { ModelerParameters parseModelerParameters(const std::filesystem::path& path); + } // namespace Antares::Solver diff --git a/src/solver/modeler/parameters/parseModelerParameters.cpp b/src/solver/modeler/parameters/parseModelerParameters.cpp index 39935db38c..a249e5114c 100644 --- a/src/solver/modeler/parameters/parseModelerParameters.cpp +++ b/src/solver/modeler/parameters/parseModelerParameters.cpp @@ -1,3 +1,24 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + #include #include From a807358b5df136a74545cf358baeeccc73ef2902 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 17:16:20 +0100 Subject: [PATCH 14/34] add a main --- src/solver/modeler/CMakeLists.txt | 60 +++++++++++++++++++++++++++++++ src/solver/modeler/main.cpp | 31 ++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/solver/modeler/main.cpp diff --git a/src/solver/modeler/CMakeLists.txt b/src/solver/modeler/CMakeLists.txt index 334e4c6c60..44178780e0 100644 --- a/src/solver/modeler/CMakeLists.txt +++ b/src/solver/modeler/CMakeLists.txt @@ -2,3 +2,63 @@ add_subdirectory(api) add_subdirectory(ortoolsImpl) add_subdirectory(loadFiles) add_subdirectory(parameters) + + +# +# Resource file for Windows +# +if (WIN32) + file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.o") + FILE(COPY "${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.ico" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/win32/") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.rc.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.rc") + + if (MINGW) + # resource compilation for mingw + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/win32/modeler.o" + COMMAND windres.exe "-I${CMAKE_CURRENT_SOURCE_DIR}" + "-i${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.rc" + -o "${CMAKE_CURRENT_BINARY_DIR}/win32/modeler.o") + set(SRCS ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/win32/modeler.o") + else () + set(SRCS ${SRCS} "win32/modeler.rc") + endif () +endif () + +OMESSAGE(" :: modeler") + +set(exec_name "antares-modeler") + +add_library(modeler-lib INTERFACE + ${SRCS} +) + +add_executable(antares-modeler + main.cpp + ${SRCS} +) + +set_target_properties(antares-modeler PROPERTIES OUTPUT_NAME ${exec_name}) + +target_link_libraries(modeler-lib + INTERFACE + Antares::loadModelerFiles + modeler-parameters +) + +target_link_libraries(antares-modeler + PRIVATE + modeler-lib +) + +import_std_libs(antares-modeler) +executable_strip(antares-modeler) + +copy_dependency(sirius_solver antares-modeler) + +install(TARGETS antares-modeler EXPORT antares-modeler DESTINATION bin) + +INSTALL(EXPORT antares-modeler + FILE antares-modelerConfig.cmake + DESTINATION cmake +) diff --git a/src/solver/modeler/main.cpp b/src/solver/modeler/main.cpp new file mode 100644 index 0000000000..5759b59b2f --- /dev/null +++ b/src/solver/modeler/main.cpp @@ -0,0 +1,31 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + +#include + +#include +#include + +int main(int argc, const char** argv) +{ + + return 0; +} From 0b3794a2e2def9c9ebc59f68d9b99530ae29ae2b Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 19 Dec 2024 17:28:35 +0100 Subject: [PATCH 15/34] fill main --- src/solver/modeler/main.cpp | 17 +++++++++++++++-- .../parameters/parseModelerParameters.cpp | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/solver/modeler/main.cpp b/src/solver/modeler/main.cpp index 5759b59b2f..cc1a782cad 100644 --- a/src/solver/modeler/main.cpp +++ b/src/solver/modeler/main.cpp @@ -20,12 +20,25 @@ */ #include - #include -#include +#include + +using namespace Antares; +using namespace Antares::Solver; int main(int argc, const char** argv) { + if (argc < 1) + { + logs.error() << "No study path provided, exiting."; + return EXIT_FAILURE; + } + + std::filesystem::path studyPath(argv[1]); + + const auto parameters = parseModelerParameters(studyPath); + const auto libraries = LoadFiles::loadLibraries(studyPath); + const auto system = LoadFiles::loadSystem(studyPath, libraries); return 0; } diff --git a/src/solver/modeler/parameters/parseModelerParameters.cpp b/src/solver/modeler/parameters/parseModelerParameters.cpp index a249e5114c..2c92ff6d53 100644 --- a/src/solver/modeler/parameters/parseModelerParameters.cpp +++ b/src/solver/modeler/parameters/parseModelerParameters.cpp @@ -23,6 +23,7 @@ #include #include +#include #include "encoder.hxx" From b5a44c70ee0f692e56c5c70e1335181b9cdd4a15 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 20 Dec 2024 12:04:41 +0100 Subject: [PATCH 16/34] parameters.yml in class, correct extension: yml and not yaml --- .../solver/modeler/parameters/parseModelerParameters.h | 2 +- src/solver/modeler/parameters/parseModelerParameters.cpp | 4 ++-- .../solver/modeler/parameters/testParametersParsing.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h index a323b39b0f..441c9c8deb 100644 --- a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h +++ b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h @@ -28,6 +28,6 @@ namespace Antares::Solver { -ModelerParameters parseModelerParameters(const std::filesystem::path& path); +ModelerParameters parseModelerParameters(const std::filesystem::path& studyPath); } // namespace Antares::Solver diff --git a/src/solver/modeler/parameters/parseModelerParameters.cpp b/src/solver/modeler/parameters/parseModelerParameters.cpp index 2c92ff6d53..a42050dab9 100644 --- a/src/solver/modeler/parameters/parseModelerParameters.cpp +++ b/src/solver/modeler/parameters/parseModelerParameters.cpp @@ -29,9 +29,9 @@ namespace Antares::Solver { -ModelerParameters parseModelerParameters(const std::filesystem::path& path) +ModelerParameters parseModelerParameters(const std::filesystem::path& studyPath) { - const auto contents = Antares::IO::readFile(path); + const auto contents = Antares::IO::readFile(studyPath / "parameters.yml"); YAML::Node root = YAML::Load(contents); return root.as(); } diff --git a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp b/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp index aa2b14732b..786ca627d4 100644 --- a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp +++ b/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp @@ -34,7 +34,7 @@ BOOST_AUTO_TEST_SUITE(read_modeler_parameters) BOOST_AUTO_TEST_CASE(all_properties_set) { const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); - const auto fileP = working_tmp_dir / "parameters.yaml"; + const auto fileP = working_tmp_dir / "parameters.yml"; { std::ofstream param(fileP); param << R"( @@ -44,7 +44,7 @@ solver-parameters: PRESOLVE 1 no-output: true)"; } - auto params = Antares::Solver::parseModelerParameters(fileP); + auto params = Antares::Solver::parseModelerParameters(working_tmp_dir); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); @@ -54,7 +54,7 @@ no-output: true)"; BOOST_AUTO_TEST_CASE(all_properties_set_out_of_order) { const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); - const auto fileP = working_tmp_dir / "parameters.yaml"; + const auto fileP = working_tmp_dir / "parameters.yml"; { std::ofstream param(fileP); param << R"( @@ -64,7 +64,7 @@ solver-parameters: PRESOLVE 1 no-output: true)"; } - auto params = Antares::Solver::parseModelerParameters(fileP); + auto params = Antares::Solver::parseModelerParameters(working_tmp_dir); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); From beb7339ea13109306ad00533f97d132e0862cb59 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 20 Dec 2024 12:08:31 +0100 Subject: [PATCH 17/34] test file not yml --- .../src/solver/modeler/loadFiles/testLoadModelerFiles.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index 8f57540fb5..05f272f3d3 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -68,6 +68,13 @@ BOOST_FIXTURE_TEST_CASE(read_one_lib_file, FixtureLoadFile) BOOST_CHECK_EQUAL(libraries[0].Id(), "lib_id"); } +BOOST_FIXTURE_TEST_CASE(dont_read_bad_extension, FixtureLoadFile) +{ + createFile(studyPath, "abc.txt"); + auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath); + BOOST_CHECK(libraries.empty()); +} + BOOST_FIXTURE_TEST_CASE(read_several_lib_file, FixtureLoadFile) { std::ofstream libStream(libraryDirPath / "simple.yml"); From 869a67a926b1e38b9aab553c24cb7c1fa04ae20b Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 20 Dec 2024 12:19:03 +0100 Subject: [PATCH 18/34] handle invalid directory for the study --- src/solver/modeler/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/solver/modeler/main.cpp b/src/solver/modeler/main.cpp index cc1a782cad..fc5f8d6ff6 100644 --- a/src/solver/modeler/main.cpp +++ b/src/solver/modeler/main.cpp @@ -35,6 +35,13 @@ int main(int argc, const char** argv) } std::filesystem::path studyPath(argv[1]); + logs.info() << "Study path: " << studyPath; + + if (!std::filesystem::is_directory(studyPath)) + { + logs.error() << "The path provided isn't a valid directory, exiting"; + return EXIT_FAILURE; + } const auto parameters = parseModelerParameters(studyPath); const auto libraries = LoadFiles::loadLibraries(studyPath); From 7d8c30672e9fc4990a71215b1fa48cdf5478eae8 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 20 Dec 2024 13:33:24 +0100 Subject: [PATCH 19/34] fix test --- src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index 05f272f3d3..1d7c088af9 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -70,7 +70,7 @@ BOOST_FIXTURE_TEST_CASE(read_one_lib_file, FixtureLoadFile) BOOST_FIXTURE_TEST_CASE(dont_read_bad_extension, FixtureLoadFile) { - createFile(studyPath, "abc.txt"); + createFile(libraryDirPath, "abc.txt"); auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath); BOOST_CHECK(libraries.empty()); } From 02f366f740f4ed85730581e5fa540cbb2519e2a2 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 20 Dec 2024 13:58:16 +0100 Subject: [PATCH 20/34] use namespace loadFiles for parameters --- src/solver/modeler/main.cpp | 2 +- .../solver/modeler/parameters/parseModelerParameters.h | 4 ++-- src/solver/modeler/parameters/parseModelerParameters.cpp | 4 ++-- .../src/solver/modeler/parameters/testParametersParsing.cpp | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/solver/modeler/main.cpp b/src/solver/modeler/main.cpp index fc5f8d6ff6..ac28dbf124 100644 --- a/src/solver/modeler/main.cpp +++ b/src/solver/modeler/main.cpp @@ -43,7 +43,7 @@ int main(int argc, const char** argv) return EXIT_FAILURE; } - const auto parameters = parseModelerParameters(studyPath); + const auto parameters = LoadFiles::parseModelerParameters(studyPath); const auto libraries = LoadFiles::loadLibraries(studyPath); const auto system = LoadFiles::loadSystem(studyPath, libraries); diff --git a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h index 441c9c8deb..cccbb96b15 100644 --- a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h +++ b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h @@ -25,9 +25,9 @@ #include -namespace Antares::Solver +namespace Antares::Solver::LoadFiles { ModelerParameters parseModelerParameters(const std::filesystem::path& studyPath); -} // namespace Antares::Solver +} // namespace Antares::Solver::LoadFiles diff --git a/src/solver/modeler/parameters/parseModelerParameters.cpp b/src/solver/modeler/parameters/parseModelerParameters.cpp index a42050dab9..c41ca4c81a 100644 --- a/src/solver/modeler/parameters/parseModelerParameters.cpp +++ b/src/solver/modeler/parameters/parseModelerParameters.cpp @@ -27,7 +27,7 @@ #include "encoder.hxx" -namespace Antares::Solver +namespace Antares::Solver::LoadFiles { ModelerParameters parseModelerParameters(const std::filesystem::path& studyPath) { @@ -35,4 +35,4 @@ ModelerParameters parseModelerParameters(const std::filesystem::path& studyPath) YAML::Node root = YAML::Load(contents); return root.as(); } -} // namespace Antares::Solver +} // namespace Antares::Solver::LoadFiles diff --git a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp b/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp index 786ca627d4..829bcfc82e 100644 --- a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp +++ b/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp @@ -31,6 +31,8 @@ BOOST_AUTO_TEST_SUITE(read_modeler_parameters) +using namespace Antares::Solver::LoadFiles; + BOOST_AUTO_TEST_CASE(all_properties_set) { const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); @@ -44,7 +46,7 @@ solver-parameters: PRESOLVE 1 no-output: true)"; } - auto params = Antares::Solver::parseModelerParameters(working_tmp_dir); + auto params = parseModelerParameters(working_tmp_dir); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); @@ -64,7 +66,7 @@ solver-parameters: PRESOLVE 1 no-output: true)"; } - auto params = Antares::Solver::parseModelerParameters(working_tmp_dir); + auto params = parseModelerParameters(working_tmp_dir); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); From d429081431728054b3b953f3659b56faf8c24470 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 20 Dec 2024 14:54:55 +0100 Subject: [PATCH 21/34] error handling for libraries loading --- src/solver/modeler/loadFiles/readLibraries.cpp | 17 ++++++++++++++--- .../modeler/loadFiles/testLoadModelerFiles.cpp | 13 +++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index c824883271..dec3433b47 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -35,9 +35,20 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) const std::string libraryStr = IO::readFile(filePath); ModelParser::Parser parser; - // Add try/catch and error handling - ModelParser::Library libraryObj = parser.parse(libraryStr); - return ModelConverter::convert(libraryObj); + + try + { + ModelParser::Library libraryObj = parser.parse(libraryStr); + return ModelConverter::convert(libraryObj); + } + catch (const std::runtime_error& e) + { + logs.error() << "Error while parsing or converting this yaml file:"; + logs.error() << filePath; + logs.error() << e.what(); + + throw std::runtime_error(e.what()); + } } std::vector loadLibraries(const fs::path& studyPath) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index 1d7c088af9..8f7ded731c 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -75,6 +75,19 @@ BOOST_FIXTURE_TEST_CASE(dont_read_bad_extension, FixtureLoadFile) BOOST_CHECK(libraries.empty()); } +BOOST_FIXTURE_TEST_CASE(incorrect_library, FixtureLoadFile) +{ + std::ofstream libStream(libraryDirPath / "simple.yml"); + libStream << R"( + library: + port-types: [] + models: [] + )"; + libStream.close(); + + BOOST_CHECK_THROW(Antares::Solver::LoadFiles::loadLibraries(studyPath), std::runtime_error); +} + BOOST_FIXTURE_TEST_CASE(read_several_lib_file, FixtureLoadFile) { std::ofstream libStream(libraryDirPath / "simple.yml"); From f8c3d70dfd1fc95d31e04b1680ceced8c6cb8569 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 20 Dec 2024 15:12:43 +0100 Subject: [PATCH 22/34] error handling for system --- .../modeler/loadFiles/readLibraries.cpp | 2 +- src/solver/modeler/loadFiles/readSystem.cpp | 17 +++++++++--- .../loadFiles/testLoadModelerFiles.cpp | 26 +++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index dec3433b47..df9f2235ec 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -43,7 +43,7 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) } catch (const std::runtime_error& e) { - logs.error() << "Error while parsing or converting this yaml file:"; + logs.error() << "Error while parsing or converting this library yaml file:"; logs.error() << filePath; logs.error() << e.what(); diff --git a/src/solver/modeler/loadFiles/readSystem.cpp b/src/solver/modeler/loadFiles/readSystem.cpp index 187213b917..02872ff635 100644 --- a/src/solver/modeler/loadFiles/readSystem.cpp +++ b/src/solver/modeler/loadFiles/readSystem.cpp @@ -20,6 +20,7 @@ */ #include +#include #include #include #include "antares/solver/modeler/loadFiles/loadFiles.h" @@ -33,12 +34,20 @@ Study::SystemModel::System loadSystem(const fs::path& studyPath, const std::vector& libraries) { const std::string systemStr = IO::readFile(studyPath / "input" / "system.yml"); - SystemParser::Parser parser; - // Add try/catch and error handling - SystemParser::System systemObj = parser.parse(systemStr); - return SystemConverter::convert(systemObj, libraries); + try + { + SystemParser::System systemObj = parser.parse(systemStr); + return SystemConverter::convert(systemObj, libraries); + } + catch (const std::runtime_error& e) + { + logs.error() << "Error while parsing or converting the system file:"; + logs.error() << e.what(); + + throw std::runtime_error(e.what()); + } } } // namespace Antares::Solver::LoadFiles diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index 8f7ded731c..d3ce837f63 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -166,4 +166,30 @@ BOOST_FIXTURE_TEST_CASE(read_system_file, FixtureLoadFile) auto system = Antares::Solver::LoadFiles::loadSystem(studyPath, libraries); } +BOOST_FIXTURE_TEST_CASE(read_invalid_system_file, FixtureLoadFile) +{ + std::ofstream libStream(libraryDirPath / "simple.yml"); + libStream << R"( + library: + id: std + description: lib_description + port-types: [] + models: + - id: generator + description: A basic generator model + + )"; + libStream.close(); + + std::ofstream systemStream(inputPath / "system.yml"); + systemStream << R"( + system: + )"; + systemStream.close(); + + auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath); + BOOST_CHECK_THROW(Antares::Solver::LoadFiles::loadSystem(studyPath, libraries), + std::runtime_error); +} + BOOST_AUTO_TEST_SUITE_END() From 9d93c9d73b62a1df80ab4e6191bd1690e4141596 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 23 Dec 2024 14:38:23 +0100 Subject: [PATCH 23/34] catch yaml exception, use mark if available --- src/solver/modeler/loadFiles/readLibraries.cpp | 14 +++++++++++++- src/solver/modeler/loadFiles/readSystem.cpp | 13 +++++++++++++ src/solver/modeler/main.cpp | 14 +++++++++++--- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index df9f2235ec..fb286270c4 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -19,6 +19,8 @@ * along with Antares_Simulator. If not, see . */ +#include + #include #include #include @@ -35,12 +37,22 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) const std::string libraryStr = IO::readFile(filePath); ModelParser::Parser parser; - try { ModelParser::Library libraryObj = parser.parse(libraryStr); return ModelConverter::convert(libraryObj); } + catch (const YAML::Exception& e) + { + logs.error() << "Error while parsing this library yaml file: " << filePath; + if (!e.mark.is_null()) + { + logs.error() << "Line " << e.mark.line << " column " << e.mark.column; + } + logs.error() << e.what(); + + throw std::runtime_error(e.what()); + } catch (const std::runtime_error& e) { logs.error() << "Error while parsing or converting this library yaml file:"; diff --git a/src/solver/modeler/loadFiles/readSystem.cpp b/src/solver/modeler/loadFiles/readSystem.cpp index 02872ff635..6b2d8d05ab 100644 --- a/src/solver/modeler/loadFiles/readSystem.cpp +++ b/src/solver/modeler/loadFiles/readSystem.cpp @@ -19,6 +19,8 @@ * along with Antares_Simulator. If not, see . */ +#include + #include #include #include @@ -41,6 +43,17 @@ Study::SystemModel::System loadSystem(const fs::path& studyPath, SystemParser::System systemObj = parser.parse(systemStr); return SystemConverter::convert(systemObj, libraries); } + catch (const YAML::Exception& e) + { + logs.error() << "Error while parsing the yaml system file"; + if (!e.mark.is_null()) + { + logs.error() << "Line " << e.mark.line << " column " << e.mark.column; + } + logs.error() << e.what(); + + throw std::runtime_error(e.what()); + } catch (const std::runtime_error& e) { logs.error() << "Error while parsing or converting the system file:"; diff --git a/src/solver/modeler/main.cpp b/src/solver/modeler/main.cpp index ac28dbf124..e0e3ec1823 100644 --- a/src/solver/modeler/main.cpp +++ b/src/solver/modeler/main.cpp @@ -43,9 +43,17 @@ int main(int argc, const char** argv) return EXIT_FAILURE; } - const auto parameters = LoadFiles::parseModelerParameters(studyPath); - const auto libraries = LoadFiles::loadLibraries(studyPath); - const auto system = LoadFiles::loadSystem(studyPath, libraries); + try + { + const auto parameters = LoadFiles::parseModelerParameters(studyPath); + const auto libraries = LoadFiles::loadLibraries(studyPath); + const auto system = LoadFiles::loadSystem(studyPath, libraries); + } + catch (...) + { + logs.error() << "Error while loading files, exiting"; + return EXIT_FAILURE; + } return 0; } From 5bda7723ab605a6962491a4220dd9741c55ca1d8 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 11:59:17 +0100 Subject: [PATCH 24/34] Add loadParameters.cpp --- src/solver/modeler/CMakeLists.txt | 2 +- src/solver/modeler/loadFiles/CMakeLists.txt | 1 + .../solver/modeler/loadFiles/loadFiles.h | 7 ++- .../modeler/loadFiles/readParameters.cpp | 61 +++++++++++++++++++ src/solver/modeler/parameters/CMakeLists.txt | 18 +++--- .../parameters/parseModelerParameters.cpp | 7 ++- .../solver/modeler/loadFiles/CMakeLists.txt | 1 + .../solver/modeler/parameters/CMakeLists.txt | 2 +- 8 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 src/solver/modeler/loadFiles/readParameters.cpp diff --git a/src/solver/modeler/CMakeLists.txt b/src/solver/modeler/CMakeLists.txt index 44178780e0..d3d8953f01 100644 --- a/src/solver/modeler/CMakeLists.txt +++ b/src/solver/modeler/CMakeLists.txt @@ -43,7 +43,7 @@ set_target_properties(antares-modeler PROPERTIES OUTPUT_NAME ${exec_name}) target_link_libraries(modeler-lib INTERFACE Antares::loadModelerFiles - modeler-parameters + Antares::modelerParameters ) target_link_libraries(antares-modeler diff --git a/src/solver/modeler/loadFiles/CMakeLists.txt b/src/solver/modeler/loadFiles/CMakeLists.txt index d7a1c0118c..e332714917 100644 --- a/src/solver/modeler/loadFiles/CMakeLists.txt +++ b/src/solver/modeler/loadFiles/CMakeLists.txt @@ -24,6 +24,7 @@ target_link_libraries(loadModelerFiles Antares::systemParser Antares::modelParser Antares::modelConverter + Antares::modelerParameters ) install(DIRECTORY include/antares diff --git a/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h b/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h index 63ab4bb732..9fb01d9453 100644 --- a/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h +++ b/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h @@ -24,15 +24,18 @@ #include #include +#include #include #include namespace Antares::Solver::LoadFiles { -Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath, - const std::vector& libraries); +ModelerParameters loadParameters(const std::filesystem::path& studyPath); std::vector loadLibraries(const std::filesystem::path& studyPath); +Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath, + const std::vector& libraries); + } // namespace Antares::Solver::LoadFiles diff --git a/src/solver/modeler/loadFiles/readParameters.cpp b/src/solver/modeler/loadFiles/readParameters.cpp new file mode 100644 index 0000000000..77882131cd --- /dev/null +++ b/src/solver/modeler/loadFiles/readParameters.cpp @@ -0,0 +1,61 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + +#include + +#include +#include +#include "antares/solver/modeler/parameters/parseModelerParameters.h" +#include "antares/solver/modeler/loadFiles/loadFiles.h" + +namespace fs = std::filesystem; + +namespace Antares::Solver::LoadFiles +{ + +ModelerParameters loadParameters(const fs::path& studyPath) +{ + try + { + const std::string paramStr = IO::readFile(studyPath / "parameters.yml"); + return parseModelerParameters(paramStr); + } + catch (const YAML::Exception& e) + { + logs.error() << "Error while parsing the yaml parameters file"; + if (!e.mark.is_null()) + { + logs.error() << "Line " << e.mark.line << " column " << e.mark.column; + } + logs.error() << e.what(); + + throw std::runtime_error(e.what()); + } + catch (const std::runtime_error& e) + { + logs.error() << "Error while parsing the yaml parameters file:"; + logs.error() << e.what(); + + throw std::runtime_error(e.what()); + } +} + +} // namespace Antares::Solver::LoadFiles diff --git a/src/solver/modeler/parameters/CMakeLists.txt b/src/solver/modeler/parameters/CMakeLists.txt index 33cfda091e..7ab35d5002 100644 --- a/src/solver/modeler/parameters/CMakeLists.txt +++ b/src/solver/modeler/parameters/CMakeLists.txt @@ -1,14 +1,16 @@ -add_library(modeler-parameters - include/antares/solver/modeler/parameters/modelerParameters.h - include/antares/solver/modeler/parameters/parseModelerParameters.h - parseModelerParameters.cpp - encoder.hxx) +add_library(modelerParameters + include/antares/solver/modeler/parameters/modelerParameters.h + include/antares/solver/modeler/parameters/parseModelerParameters.h + parseModelerParameters.cpp + encoder.hxx) -target_link_libraries(modeler-parameters +add_library(Antares::modelerParameters ALIAS modelerParameters) + +target_link_libraries(modelerParameters PRIVATE yaml-cpp - Antares::io) + Antares::io) -target_include_directories(modeler-parameters +target_include_directories(modelerParameters PUBLIC $) diff --git a/src/solver/modeler/parameters/parseModelerParameters.cpp b/src/solver/modeler/parameters/parseModelerParameters.cpp index c41ca4c81a..46782344e4 100644 --- a/src/solver/modeler/parameters/parseModelerParameters.cpp +++ b/src/solver/modeler/parameters/parseModelerParameters.cpp @@ -20,7 +20,6 @@ */ #include -#include #include #include @@ -29,10 +28,12 @@ namespace Antares::Solver::LoadFiles { -ModelerParameters parseModelerParameters(const std::filesystem::path& studyPath) + +ModelerParameters parseModelerParameters(const std::filesystem::path& filePath) { - const auto contents = Antares::IO::readFile(studyPath / "parameters.yml"); + const auto contents = Antares::IO::readFile(filePath); YAML::Node root = YAML::Load(contents); return root.as(); } + } // namespace Antares::Solver::LoadFiles diff --git a/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt b/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt index 81bbf085cc..816e2d54f3 100644 --- a/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt +++ b/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt @@ -5,6 +5,7 @@ target_link_libraries(load-modeler-files PRIVATE Boost::unit_test_framework Antares::loadModelerFiles + Antares::modelerParameters test_utils_unit ) diff --git a/src/tests/src/solver/modeler/parameters/CMakeLists.txt b/src/tests/src/solver/modeler/parameters/CMakeLists.txt index 85c27e2969..3870a14e1f 100644 --- a/src/tests/src/solver/modeler/parameters/CMakeLists.txt +++ b/src/tests/src/solver/modeler/parameters/CMakeLists.txt @@ -3,5 +3,5 @@ include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) add_boost_test(parse-parameters SRC testParametersParsing.cpp LIBS - modeler-parameters + Antares::modelerParameters test_utils_unit) From 0dc1f63d0fd7ff0357b8c9da6d75c1d7859e925d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 12:01:18 +0100 Subject: [PATCH 25/34] Remove windows related lines in modeler main cmake --- src/solver/modeler/CMakeLists.txt | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/solver/modeler/CMakeLists.txt b/src/solver/modeler/CMakeLists.txt index d3d8953f01..cb31b11fd4 100644 --- a/src/solver/modeler/CMakeLists.txt +++ b/src/solver/modeler/CMakeLists.txt @@ -3,28 +3,6 @@ add_subdirectory(ortoolsImpl) add_subdirectory(loadFiles) add_subdirectory(parameters) - -# -# Resource file for Windows -# -if (WIN32) - file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.o") - FILE(COPY "${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.ico" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/win32/") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.rc.cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.rc") - - if (MINGW) - # resource compilation for mingw - add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/win32/modeler.o" - COMMAND windres.exe "-I${CMAKE_CURRENT_SOURCE_DIR}" - "-i${CMAKE_CURRENT_SOURCE_DIR}/win32/modeler.rc" - -o "${CMAKE_CURRENT_BINARY_DIR}/win32/modeler.o") - set(SRCS ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/win32/modeler.o") - else () - set(SRCS ${SRCS} "win32/modeler.rc") - endif () -endif () - OMESSAGE(" :: modeler") set(exec_name "antares-modeler") From 20df9eb8da4b34745f86da091ed98fa5aa11cb22 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 12:01:51 +0100 Subject: [PATCH 26/34] format --- src/solver/modeler/loadFiles/readParameters.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/modeler/loadFiles/readParameters.cpp b/src/solver/modeler/loadFiles/readParameters.cpp index 77882131cd..a799bba27d 100644 --- a/src/solver/modeler/loadFiles/readParameters.cpp +++ b/src/solver/modeler/loadFiles/readParameters.cpp @@ -23,8 +23,8 @@ #include #include -#include "antares/solver/modeler/parameters/parseModelerParameters.h" #include "antares/solver/modeler/loadFiles/loadFiles.h" +#include "antares/solver/modeler/parameters/parseModelerParameters.h" namespace fs = std::filesystem; From d74f59574d50a37cfcf4ee7b47093dbfc1208b10 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 12:29:17 +0100 Subject: [PATCH 27/34] fix tests --- src/solver/modeler/loadFiles/CMakeLists.txt | 1 + src/solver/modeler/main.cpp | 2 +- .../src/solver/modeler/parameters/testParametersParsing.cpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/solver/modeler/loadFiles/CMakeLists.txt b/src/solver/modeler/loadFiles/CMakeLists.txt index e332714917..7badae16f2 100644 --- a/src/solver/modeler/loadFiles/CMakeLists.txt +++ b/src/solver/modeler/loadFiles/CMakeLists.txt @@ -1,6 +1,7 @@ set(SOURCES readSystem.cpp readLibraries.cpp + readParameters.cpp include/antares/solver/modeler/loadFiles/loadFiles.h ) diff --git a/src/solver/modeler/main.cpp b/src/solver/modeler/main.cpp index e0e3ec1823..b557e04b5b 100644 --- a/src/solver/modeler/main.cpp +++ b/src/solver/modeler/main.cpp @@ -45,7 +45,7 @@ int main(int argc, const char** argv) try { - const auto parameters = LoadFiles::parseModelerParameters(studyPath); + const auto parameters = LoadFiles::loadParameters(studyPath); const auto libraries = LoadFiles::loadLibraries(studyPath); const auto system = LoadFiles::loadSystem(studyPath, libraries); } diff --git a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp b/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp index 829bcfc82e..9a283cba76 100644 --- a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp +++ b/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp @@ -46,7 +46,7 @@ solver-parameters: PRESOLVE 1 no-output: true)"; } - auto params = parseModelerParameters(working_tmp_dir); + auto params = parseModelerParameters(fileP); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); @@ -66,7 +66,7 @@ solver-parameters: PRESOLVE 1 no-output: true)"; } - auto params = parseModelerParameters(working_tmp_dir); + auto params = parseModelerParameters(fileP); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); From 732b0ef952fbaa486c556cce892f9838ad2732f5 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 12:42:57 +0100 Subject: [PATCH 28/34] try fix windows unit tests --- .../src/solver/modeler/loadFiles/testLoadModelerFiles.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index d3ce837f63..1e476ac379 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -42,8 +42,8 @@ struct FixtureLoadFile FixtureLoadFile() { studyPath = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); - inputPath = createFolder(studyPath, "input"); - libraryDirPath = createFolder(inputPath, "model-libraries"); + inputPath = createFolder(studyPath.string(), "input"); + libraryDirPath = createFolder(inputPath.string(), "model-libraries"); } ~FixtureLoadFile() From b39407f833cfedfdeb4a12ced194c4a9dd5fc8ad Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 12:56:41 +0100 Subject: [PATCH 29/34] try fix windows unit tests 2 --- src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index 1e476ac379..d6868fdb45 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -70,7 +70,7 @@ BOOST_FIXTURE_TEST_CASE(read_one_lib_file, FixtureLoadFile) BOOST_FIXTURE_TEST_CASE(dont_read_bad_extension, FixtureLoadFile) { - createFile(libraryDirPath, "abc.txt"); + createFile(libraryDirPath.string(), "abc.txt"); auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath); BOOST_CHECK(libraries.empty()); } From 663b786697716087713ee7da364c0910154f9a80 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 14:38:30 +0100 Subject: [PATCH 30/34] catch specific error in main --- .../antares/solver/modeler/loadFiles/loadFiles.h | 10 ++++++++++ src/solver/modeler/loadFiles/readLibraries.cpp | 10 +++++----- src/solver/modeler/loadFiles/readParameters.cpp | 4 ++-- src/solver/modeler/loadFiles/readSystem.cpp | 10 +++++----- src/solver/modeler/main.cpp | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h b/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h index 9fb01d9453..6d716b6b0f 100644 --- a/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h +++ b/src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h @@ -38,4 +38,14 @@ std::vector loadLibraries(const std::filesystem::pa Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath, const std::vector& libraries); +/// Generic error class for all loading errors to catch in the main +class ErrorLoadingYaml: public std::runtime_error +{ +public: + explicit ErrorLoadingYaml(const std::string& s): + runtime_error(s) + { + } +}; + } // namespace Antares::Solver::LoadFiles diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index fb286270c4..555e8cfc19 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -34,12 +34,12 @@ namespace Antares::Solver::LoadFiles static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) { - const std::string libraryStr = IO::readFile(filePath); - - ModelParser::Parser parser; try { + const std::string libraryStr = IO::readFile(filePath); + ModelParser::Parser parser; ModelParser::Library libraryObj = parser.parse(libraryStr); + return ModelConverter::convert(libraryObj); } catch (const YAML::Exception& e) @@ -51,7 +51,7 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) } logs.error() << e.what(); - throw std::runtime_error(e.what()); + throw ErrorLoadingYaml(e.what()); } catch (const std::runtime_error& e) { @@ -59,7 +59,7 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) logs.error() << filePath; logs.error() << e.what(); - throw std::runtime_error(e.what()); + throw ErrorLoadingYaml(e.what()); } } diff --git a/src/solver/modeler/loadFiles/readParameters.cpp b/src/solver/modeler/loadFiles/readParameters.cpp index a799bba27d..eaf9c62644 100644 --- a/src/solver/modeler/loadFiles/readParameters.cpp +++ b/src/solver/modeler/loadFiles/readParameters.cpp @@ -47,14 +47,14 @@ ModelerParameters loadParameters(const fs::path& studyPath) } logs.error() << e.what(); - throw std::runtime_error(e.what()); + throw ErrorLoadingYaml(e.what()); } catch (const std::runtime_error& e) { logs.error() << "Error while parsing the yaml parameters file:"; logs.error() << e.what(); - throw std::runtime_error(e.what()); + throw ErrorLoadingYaml(e.what()); } } diff --git a/src/solver/modeler/loadFiles/readSystem.cpp b/src/solver/modeler/loadFiles/readSystem.cpp index 6b2d8d05ab..2718b477fc 100644 --- a/src/solver/modeler/loadFiles/readSystem.cpp +++ b/src/solver/modeler/loadFiles/readSystem.cpp @@ -35,12 +35,12 @@ namespace Antares::Solver::LoadFiles Study::SystemModel::System loadSystem(const fs::path& studyPath, const std::vector& libraries) { - const std::string systemStr = IO::readFile(studyPath / "input" / "system.yml"); - SystemParser::Parser parser; - try { + const std::string systemStr = IO::readFile(studyPath / "input" / "system.yml"); + SystemParser::Parser parser; SystemParser::System systemObj = parser.parse(systemStr); + return SystemConverter::convert(systemObj, libraries); } catch (const YAML::Exception& e) @@ -52,14 +52,14 @@ Study::SystemModel::System loadSystem(const fs::path& studyPath, } logs.error() << e.what(); - throw std::runtime_error(e.what()); + throw ErrorLoadingYaml(e.what()); } catch (const std::runtime_error& e) { logs.error() << "Error while parsing or converting the system file:"; logs.error() << e.what(); - throw std::runtime_error(e.what()); + throw ErrorLoadingYaml(e.what()); } } diff --git a/src/solver/modeler/main.cpp b/src/solver/modeler/main.cpp index b557e04b5b..a99096e331 100644 --- a/src/solver/modeler/main.cpp +++ b/src/solver/modeler/main.cpp @@ -49,7 +49,7 @@ int main(int argc, const char** argv) const auto libraries = LoadFiles::loadLibraries(studyPath); const auto system = LoadFiles::loadSystem(studyPath, libraries); } - catch (...) + catch (const LoadFiles::ErrorLoadingYaml&) { logs.error() << "Error while loading files, exiting"; return EXIT_FAILURE; From 4c42da5a06edfa2b00cc80638ed78fb43c8b762a Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 14:43:19 +0100 Subject: [PATCH 31/34] catch generic exception in main --- src/solver/modeler/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/solver/modeler/main.cpp b/src/solver/modeler/main.cpp index a99096e331..ba93687e92 100644 --- a/src/solver/modeler/main.cpp +++ b/src/solver/modeler/main.cpp @@ -54,6 +54,12 @@ int main(int argc, const char** argv) logs.error() << "Error while loading files, exiting"; return EXIT_FAILURE; } + catch (const std::exception& e) + { + logs.error() << e.what(); + logs.error() << "Error during the execution, exiting"; + return EXIT_FAILURE; + } return 0; } From 4dd06fa588d6fe2122fe7f59c78ed164cb777bd0 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 15:42:45 +0100 Subject: [PATCH 32/34] change tests layout --- .../parameters/parseModelerParameters.h | 2 +- .../parameters/parseModelerParameters.cpp | 5 +- src/tests/src/solver/modeler/CMakeLists.txt | 1 - .../solver/modeler/loadFiles/CMakeLists.txt | 21 +++---- .../loadFiles/testLoadModelerFiles.cpp | 2 +- .../testParameters.cpp} | 56 ++++++++----------- .../solver/modeler/parameters/CMakeLists.txt | 7 --- 7 files changed, 35 insertions(+), 59 deletions(-) rename src/tests/src/solver/modeler/{parameters/testParametersParsing.cpp => loadFiles/testParameters.cpp} (59%) delete mode 100644 src/tests/src/solver/modeler/parameters/CMakeLists.txt diff --git a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h index cccbb96b15..f0c9bd7238 100644 --- a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h +++ b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h @@ -28,6 +28,6 @@ namespace Antares::Solver::LoadFiles { -ModelerParameters parseModelerParameters(const std::filesystem::path& studyPath); +ModelerParameters parseModelerParameters(const std::string& content); } // namespace Antares::Solver::LoadFiles diff --git a/src/solver/modeler/parameters/parseModelerParameters.cpp b/src/solver/modeler/parameters/parseModelerParameters.cpp index 46782344e4..470b7a66e4 100644 --- a/src/solver/modeler/parameters/parseModelerParameters.cpp +++ b/src/solver/modeler/parameters/parseModelerParameters.cpp @@ -29,10 +29,9 @@ namespace Antares::Solver::LoadFiles { -ModelerParameters parseModelerParameters(const std::filesystem::path& filePath) +ModelerParameters parseModelerParameters(const std::string& content) { - const auto contents = Antares::IO::readFile(filePath); - YAML::Node root = YAML::Load(contents); + YAML::Node root = YAML::Load(content); return root.as(); } diff --git a/src/tests/src/solver/modeler/CMakeLists.txt b/src/tests/src/solver/modeler/CMakeLists.txt index b5d0efe1f8..d532a0a77d 100644 --- a/src/tests/src/solver/modeler/CMakeLists.txt +++ b/src/tests/src/solver/modeler/CMakeLists.txt @@ -1,3 +1,2 @@ add_subdirectory(api) add_subdirectory(loadFiles) -add_subdirectory(parameters) diff --git a/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt b/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt index 816e2d54f3..896c759e06 100644 --- a/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt +++ b/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt @@ -1,15 +1,10 @@ -add_executable(load-modeler-files - testLoadModelerFiles.cpp) +include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) -target_link_libraries(load-modeler-files - PRIVATE - Boost::unit_test_framework +add_boost_test(loadFiles + SRC + testLoadModelerFiles.cpp + testParameters.cpp + LIBS + Antares::modelerParameters Antares::loadModelerFiles - Antares::modelerParameters - test_utils_unit -) - -set_target_properties(load-modeler-files PROPERTIES FOLDER Unit-tests/test-writer) - -add_test(NAME load-modeler-files COMMAND load-modeler-files) -set_tests_properties(load-modeler-files PROPERTIES LABELS unit) + test_utils_unit) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index d6868fdb45..6c0d8c288a 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -52,7 +52,7 @@ struct FixtureLoadFile } }; -BOOST_FIXTURE_TEST_CASE(read_one_lib_file, FixtureLoadFile) +BOOST_FIXTURE_TEST_CASE(read_one_lib_treile, FixtureLoadFile) { std::ofstream libStream(libraryDirPath / "simple.yml"); libStream << R"( diff --git a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp b/src/tests/src/solver/modeler/loadFiles/testParameters.cpp similarity index 59% rename from src/tests/src/solver/modeler/parameters/testParametersParsing.cpp rename to src/tests/src/solver/modeler/loadFiles/testParameters.cpp index 9a283cba76..20b2750134 100644 --- a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testParameters.cpp @@ -21,56 +21,46 @@ #define WIN32_LEAN_AND_MEAN #include -#define BOOST_TEST_MODULE parse modeler parameters - #include -#include +#include #include "files-system.h" -BOOST_AUTO_TEST_SUITE(read_modeler_parameters) - -using namespace Antares::Solver::LoadFiles; - -BOOST_AUTO_TEST_CASE(all_properties_set) +BOOST_AUTO_TEST_CASE(read_parameters) { - const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); - const auto fileP = working_tmp_dir / "parameters.yml"; - { - std::ofstream param(fileP); - param << R"( -solver: sirius -solver-logs: false -solver-parameters: PRESOLVE 1 -no-output: true)"; - } + auto studyPath = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); + std::ofstream paramStream(studyPath / "parameters.yml"); + paramStream << R"( + solver: sirius + solver-logs: false + solver-parameters: PRESOLVE 1 + no-output: true + )"; + paramStream.close(); - auto params = parseModelerParameters(fileP); + auto params = Antares::Solver::LoadFiles::loadParameters(studyPath); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); BOOST_CHECK_EQUAL(params.noOutput, true); } -BOOST_AUTO_TEST_CASE(all_properties_set_out_of_order) +BOOST_AUTO_TEST_CASE(read_parameters_out_of_order) { - const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); - const auto fileP = working_tmp_dir / "parameters.yml"; - { - std::ofstream param(fileP); - param << R"( -solver-logs: false -solver: sirius -solver-parameters: PRESOLVE 1 -no-output: true)"; - } + auto studyPath = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); + std::ofstream paramStream(studyPath / "parameters.yml"); + paramStream << R"( + solver-logs: false + solver: sirius + solver-parameters: PRESOLVE 1 + no-output: true + )"; + paramStream.close(); - auto params = parseModelerParameters(fileP); + auto params = Antares::Solver::LoadFiles::loadParameters(studyPath); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); BOOST_CHECK_EQUAL(params.noOutput, true); } - -BOOST_AUTO_TEST_SUITE_END() diff --git a/src/tests/src/solver/modeler/parameters/CMakeLists.txt b/src/tests/src/solver/modeler/parameters/CMakeLists.txt deleted file mode 100644 index 3870a14e1f..0000000000 --- a/src/tests/src/solver/modeler/parameters/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) - -add_boost_test(parse-parameters - SRC testParametersParsing.cpp - LIBS - Antares::modelerParameters - test_utils_unit) From 58e11481a93482a5b48b00e05e420872f8ee221e Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 15:43:58 +0100 Subject: [PATCH 33/34] test parameter missing --- .../src/solver/modeler/loadFiles/testParameters.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/tests/src/solver/modeler/loadFiles/testParameters.cpp b/src/tests/src/solver/modeler/loadFiles/testParameters.cpp index 20b2750134..a3a81cbfd8 100644 --- a/src/tests/src/solver/modeler/loadFiles/testParameters.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testParameters.cpp @@ -64,3 +64,16 @@ BOOST_AUTO_TEST_CASE(read_parameters_out_of_order) BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); BOOST_CHECK_EQUAL(params.noOutput, true); } + +BOOST_AUTO_TEST_CASE(parameters_missing) +{ + auto studyPath = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); + std::ofstream paramStream(studyPath / "parameters.yml"); + paramStream << R"( + solver-logs: false + no-output: true + )"; + paramStream.close(); + + BOOST_CHECK_THROW(Antares::Solver::LoadFiles::loadParameters(studyPath), std::runtime_error); +} From 511dc7e8bd22739903699ab887d9f2e134699c74 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 15:48:32 +0100 Subject: [PATCH 34/34] format --- src/tests/src/solver/modeler/loadFiles/testParameters.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/src/solver/modeler/loadFiles/testParameters.cpp b/src/tests/src/solver/modeler/loadFiles/testParameters.cpp index a3a81cbfd8..b351160fc3 100644 --- a/src/tests/src/solver/modeler/loadFiles/testParameters.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testParameters.cpp @@ -21,6 +21,7 @@ #define WIN32_LEAN_AND_MEAN #include + #include #include