-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modeler 2.5a: Read models and system yaml files [ANT-2306] #2540
Merged
Merged
Changes from 36 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
96c13d7
Add dir loadfile/ , add readSystem
payetvin ffe1554
format
payetvin e8da375
add readLibraries.cpp
payetvin b4a2a74
add function to read one lib file
payetvin 478b087
add a loadLibraries func
payetvin 67c3754
format
payetvin 2fb43d6
Add unit test folder
payetvin ad4ca2d
First test case
payetvin cba7b31
several libs
payetvin 78e083f
comments
payetvin 4978046
merge develop, conflicts
payetvin 385f53a
test load system
payetvin 6f89696
comments
payetvin 67cd455
add headers
payetvin a807358
add a main
payetvin 0b3794a
fill main
payetvin b5a44c7
parameters.yml in class, correct extension: yml and not yaml
payetvin beb7339
test file not yml
payetvin 869a67a
handle invalid directory for the study
payetvin 7d8c306
fix test
payetvin 02f366f
use namespace loadFiles for parameters
payetvin d429081
error handling for libraries loading
payetvin f8c3d70
error handling for system
payetvin 9d93c9d
catch yaml exception, use mark if available
payetvin 557edaf
Merge branch 'develop' into feature/2.5-read-input-files
payetvin 5bda772
Add loadParameters.cpp
payetvin 0dc1f63
Remove windows related lines in modeler main cmake
payetvin 20df9eb
format
payetvin d74f595
fix tests
payetvin 732b0ef
try fix windows unit tests
payetvin b39407f
try fix windows unit tests 2
payetvin 663b786
catch specific error in main
payetvin 4c42da5
catch generic exception in main
payetvin 4dd06fa
change tests layout
payetvin 58e1148
test parameter missing
payetvin 511dc7e
format
payetvin 00183c4
add error handling functions to avoid duplication
payetvin 559f739
add error handling for read system and libraries
payetvin bf08250
format
payetvin a230b55
rename file to handleErrors.cpp
payetvin e1679bf
format
payetvin abb4e33
path to string conversion fir windows
payetvin 6df9b65
split try catch for parameters
payetvin 9341362
split try catch for system and libraries loading
payetvin e80708b
format
payetvin cbe01b2
test yaml error with mark
payetvin 267d5fa
Add info logs when files are loaded
payetvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
add_subdirectory(api) | ||
add_subdirectory(ortoolsImpl) | ||
add_subdirectory(loadFiles) | ||
add_subdirectory(parameters) | ||
|
||
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 | ||
Antares::modelerParameters | ||
) | ||
|
||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
set(SOURCES | ||
readSystem.cpp | ||
readLibraries.cpp | ||
readParameters.cpp | ||
|
||
include/antares/solver/modeler/loadFiles/loadFiles.h | ||
) | ||
|
||
# Create the library | ||
add_library(loadModelerFiles STATIC ${SOURCES}) | ||
add_library(Antares::loadModelerFiles ALIAS loadModelerFiles) | ||
|
||
# Specify include directories | ||
target_include_directories(loadModelerFiles | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
) | ||
|
||
# Link dependencies (if any) | ||
target_link_libraries(loadModelerFiles | ||
PUBLIC | ||
Antares::antares-study-system-model | ||
PRIVATE | ||
Antares::io | ||
Antares::systemParser | ||
Antares::modelParser | ||
Antares::modelConverter | ||
Antares::modelerParameters | ||
) | ||
|
||
install(DIRECTORY include/antares | ||
DESTINATION "include" | ||
) |
51 changes: 51 additions & 0 deletions
51
src/solver/modeler/loadFiles/include/antares/solver/modeler/loadFiles/loadFiles.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 <https://opensource.org/license/mpl-2-0/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <vector> | ||
|
||
#include <antares/solver/modeler/parameters/modelerParameters.h> | ||
#include <antares/study/system-model/library.h> | ||
#include <antares/study/system-model/system.h> | ||
|
||
namespace Antares::Solver::LoadFiles | ||
{ | ||
|
||
ModelerParameters loadParameters(const std::filesystem::path& studyPath); | ||
|
||
std::vector<Study::SystemModel::Library> loadLibraries(const std::filesystem::path& studyPath); | ||
|
||
Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath, | ||
const std::vector<Study::SystemModel::Library>& 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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 <https://opensource.org/license/mpl-2-0/>. | ||
*/ | ||
|
||
#include <yaml-cpp/yaml.h> | ||
|
||
#include <antares/io/file.h> | ||
#include <antares/logs/logs.h> | ||
#include <antares/solver/modelConverter/modelConverter.h> | ||
#include <antares/solver/modelParser/parser.h> | ||
#include "antares/solver/modeler/loadFiles/loadFiles.h" | ||
|
||
namespace fs = std::filesystem; | ||
|
||
namespace Antares::Solver::LoadFiles | ||
{ | ||
|
||
static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) | ||
{ | ||
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) | ||
{ | ||
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 ErrorLoadingYaml(e.what()); | ||
} | ||
catch (const std::runtime_error& e) | ||
{ | ||
logs.error() << "Error while parsing or converting this library yaml file:"; | ||
logs.error() << filePath; | ||
logs.error() << e.what(); | ||
|
||
throw ErrorLoadingYaml(e.what()); | ||
} | ||
} | ||
|
||
std::vector<Study::SystemModel::Library> loadLibraries(const fs::path& studyPath) | ||
{ | ||
std::vector<Study::SystemModel::Library> libraries; | ||
|
||
const fs::path directoryPath = studyPath / "input" / "model-libraries"; | ||
for (const auto& entry: fs::directory_iterator(directoryPath)) | ||
{ | ||
if (entry.path().extension() != ".yml") | ||
{ | ||
logs.info() << entry.path() | ||
<< " ignored, only files having the `.yml` extension are loaded"; | ||
continue; | ||
} | ||
|
||
libraries.push_back(loadSingleLibrary(entry.path())); | ||
} | ||
|
||
return libraries; | ||
} | ||
} // namespace Antares::Solver::LoadFiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://opensource.org/license/mpl-2-0/>. | ||
*/ | ||
|
||
#include <yaml-cpp/yaml.h> | ||
|
||
#include <antares/io/file.h> | ||
#include <antares/logs/logs.h> | ||
#include "antares/solver/modeler/loadFiles/loadFiles.h" | ||
#include "antares/solver/modeler/parameters/parseModelerParameters.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 ErrorLoadingYaml(e.what()); | ||
} | ||
catch (const std::runtime_error& e) | ||
{ | ||
logs.error() << "Error while parsing the yaml parameters file:"; | ||
logs.error() << e.what(); | ||
|
||
throw ErrorLoadingYaml(e.what()); | ||
} | ||
} | ||
|
||
} // namespace Antares::Solver::LoadFiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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 <https://opensource.org/license/mpl-2-0/>. | ||
*/ | ||
|
||
#include <yaml-cpp/yaml.h> | ||
|
||
#include <antares/io/file.h> | ||
#include <antares/logs/logs.h> | ||
#include <antares/solver/systemParser/converter.h> | ||
#include <antares/solver/systemParser/parser.h> | ||
#include "antares/solver/modeler/loadFiles/loadFiles.h" | ||
|
||
namespace fs = std::filesystem; | ||
|
||
namespace Antares::Solver::LoadFiles | ||
{ | ||
|
||
Study::SystemModel::System loadSystem(const fs::path& studyPath, | ||
const std::vector<Study::SystemModel::Library>& libraries) | ||
{ | ||
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) | ||
{ | ||
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 ErrorLoadingYaml(e.what()); | ||
} | ||
catch (const std::runtime_error& e) | ||
{ | ||
logs.error() << "Error while parsing or converting the system file:"; | ||
logs.error() << e.what(); | ||
|
||
throw ErrorLoadingYaml(e.what()); | ||
} | ||
} | ||
|
||
} // namespace Antares::Solver::LoadFiles |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.