-
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 4.6: system import [ANT-2207] #2530
Merged
+916
−20
Merged
Changes from 49 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
57c3088
Base for system parser
payetvin 99026ca
library.h
payetvin 27fc0fc
format
payetvin 493a629
fix some compile err
payetvin 4b8cd4b
compile ok, start encoder
payetvin f440fac
encoder ok
payetvin 9a478db
system in parser
payetvin 0f8fb8a
system converter
payetvin 3df0a31
format
payetvin 963cbea
rename library.h into system.h
payetvin 168eb54
remove systemConverter
payetvin 0c073d8
add test system parser
payetvin 7380bbb
test empty ok
payetvin 5757d2c
more tests
payetvin 1507574
c
payetvin 3289a8d
test components
payetvin c884e8f
test parameters
payetvin 4d7767f
double for param value
payetvin 9f56e65
format
payetvin 38524e0
Create components model with a simple vector, add tests
payetvin 1942d6e
Add parameters to createComponent
payetvin 533f0d5
fix tests
payetvin 2e5a875
format
payetvin b58f119
add converter.cpp
payetvin 41cbd04
fix test system study
payetvin e9baf5e
add converter header
payetvin c410da8
format
payetvin 4654260
use convert function in unit tests
payetvin af95bc3
format
payetvin f70e7b6
split library and model
payetvin 157c83a
shared ptr for model
payetvin feed197
add test converter
payetvin 9cd5c38
pass libraries
payetvin ab7c2b0
add get model
payetvin 55fc259
fix test
payetvin 9ce46f8
test param not in model
payetvin a03866d
format
payetvin d976130
custom exceptions
payetvin c83e3e7
test those exceptions
payetvin 62c2b1c
no model found
payetvin 2456f69
error no model found
payetvin 1c9f0c6
Full unit test example
payetvin 3529109
Add component id in logs
payetvin 81771fb
logs and format
payetvin 3e55a6e
rename fixture
payetvin 39a4d40
simplify
payetvin a33570e
remove espace insecables
payetvin 7058d96
format
payetvin 6c14f79
add checks
payetvin e41a9a7
Merge branch 'develop' into feature/4.6-system-import
flomnes efb0bbb
correct log with id
payetvin d6fb19b
Merge branch 'feature/4.6-system-import' of https://github.com/Antare…
payetvin 5954300
comments
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
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,32 @@ | ||
find_package(yaml-cpp REQUIRED) | ||
|
||
set(SOURCES | ||
parser.cpp | ||
converter.cpp | ||
encoders.hxx | ||
include/antares/solver/systemParser/parser.h | ||
include/antares/solver/systemParser/converter.h | ||
include/antares/solver/systemParser/system.h | ||
) | ||
|
||
# Create the library | ||
add_library(systemParser STATIC ${SOURCES}) | ||
add_library(Antares::systemParser ALIAS systemParser) | ||
|
||
# Specify include directories | ||
target_include_directories(systemParser | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
) | ||
|
||
# Link dependencies (if any) | ||
target_link_libraries(systemParser | ||
PUBLIC | ||
Antares::antares-study-system-model | ||
PRIVATE | ||
yaml-cpp | ||
) | ||
|
||
install(DIRECTORY include/antares | ||
DESTINATION "include" | ||
) |
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,133 @@ | ||
/* | ||
* 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 "antares/solver/systemParser/converter.h" | ||
|
||
#include <algorithm> | ||
|
||
#include "antares/solver/systemParser/system.h" | ||
#include "antares/study/system-model/system.h" | ||
|
||
using namespace Antares::Study; | ||
|
||
namespace Antares::Solver::SystemConverter | ||
{ | ||
|
||
class ErrorWhileSplittingLibraryAndModel: public std::runtime_error | ||
{ | ||
public: | ||
explicit ErrorWhileSplittingLibraryAndModel(const std::string& s): | ||
runtime_error("'.' not found while splitting library and model: " + s) | ||
{ | ||
} | ||
}; | ||
|
||
class LibraryNotFound: public std::runtime_error | ||
{ | ||
public: | ||
explicit LibraryNotFound(const std::string& s): | ||
runtime_error("No library found with this name: " + s) | ||
{ | ||
} | ||
}; | ||
|
||
class ModelNotFound: public std::runtime_error | ||
{ | ||
public: | ||
explicit ModelNotFound(const std::string& s): | ||
runtime_error("No model found with this name: " + s) | ||
{ | ||
} | ||
}; | ||
|
||
static std::pair<std::string, std::string> splitLibraryModelString(const std::string& s) | ||
{ | ||
size_t pos = s.find('.'); | ||
if (pos == std::string::npos) | ||
{ | ||
throw ErrorWhileSplittingLibraryAndModel(s); | ||
} | ||
|
||
std::string library = s.substr(0, pos); | ||
std::string model = s.substr(pos + 1); | ||
return {library, model}; | ||
} | ||
|
||
static const SystemModel::Model* getModel(const std::vector<SystemModel::Library>& libraries, | ||
payetvin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const std::string& libraryId, | ||
const std::string& modelId) | ||
{ | ||
auto lib = std::ranges::find_if(libraries, | ||
[&libraryId](const auto& l) { return l.Id() == libraryId; }); | ||
if (lib == libraries.end()) | ||
{ | ||
throw LibraryNotFound(libraryId); | ||
} | ||
|
||
try | ||
{ | ||
auto& model = lib->Models().at(modelId); | ||
return &model; | ||
} | ||
catch (const std::out_of_range&) | ||
{ | ||
throw ModelNotFound(modelId); | ||
} | ||
payetvin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
static SystemModel::Component createComponent(const SystemParser::Component& c, | ||
const std::vector<SystemModel::Library>& libraries) | ||
{ | ||
const auto [libraryId, modelId] = splitLibraryModelString(c.model); | ||
SystemModel::ModelBuilder model_builder; | ||
|
||
const SystemModel::Model* model = getModel(libraries, libraryId, modelId); | ||
|
||
SystemModel::ComponentBuilder component_builder; | ||
|
||
std::map<std::string, double> parameters; | ||
for (const auto& p: c.parameters) | ||
{ | ||
parameters.try_emplace(p.id, p.value); | ||
} | ||
|
||
auto component = component_builder.withId(c.id) | ||
.withModel(model) | ||
.withScenarioGroupId(c.scenarioGroup) | ||
.withParameterValues(parameters) | ||
.build(); | ||
return component; | ||
} | ||
|
||
SystemModel::System convert(const SystemParser::System& parserSystem, | ||
const std::vector<SystemModel::Library>& libraries) | ||
{ | ||
std::vector<SystemModel::Component> components; | ||
for (const auto& c: parserSystem.components) | ||
{ | ||
components.push_back(createComponent(c, libraries)); | ||
} | ||
|
||
SystemModel::SystemBuilder builder; | ||
return builder.withId(parserSystem.id).withComponents(components).build(); | ||
} | ||
|
||
} // namespace Antares::Solver::SystemConverter |
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,95 @@ | ||
/* | ||
* 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 "antares/solver/systemParser/system.h" | ||
|
||
#include "yaml-cpp/yaml.h" | ||
|
||
// Implement convert specializations | ||
namespace YAML | ||
{ | ||
|
||
/** | ||
* @brief shortend to default construct a value when node is null | ||
* @tparam T Type to convert the node to | ||
* @param n node | ||
* @return Object of type T | ||
* It's just to simplify repertitve and verbose lines | ||
* as_fallback_default<std::vector<Antares::Solver::SystemParser::Parameter>>( | ||
node["parameters"]) is equivalent to | ||
node["parameters"].as<std::vector<Antares::Solver::SystemParser::Parameter>>(std::vector<Antares::Solver::SystemParser::Parameter>()) | ||
*/ | ||
template<typename T> | ||
inline T as_fallback_default(const Node& n) | ||
{ | ||
return n.as<T>(T()); | ||
} | ||
|
||
template<> | ||
struct convert<Antares::Solver::SystemParser::Parameter> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::SystemParser::Parameter& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.id = node["id"].as<std::string>(); | ||
rhs.type = node["type"].as<std::string>(); | ||
rhs.value = node["value"].as<double>(); | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
struct convert<Antares::Solver::SystemParser::Component> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::SystemParser::Component& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.id = node["id"].as<std::string>(); | ||
rhs.model = node["model"].as<std::string>(); | ||
rhs.scenarioGroup = node["scenario-group"].as<std::string>(); | ||
rhs.parameters = as_fallback_default<std::vector<Antares::Solver::SystemParser::Parameter>>( | ||
node["parameters"]); | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
struct convert<Antares::Solver::SystemParser::System> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::SystemParser::System& rhs) | ||
{ | ||
rhs.id = node["id"].as<std::string>(); | ||
rhs.libraries = as_fallback_default<std::vector<std::string>>(node["model-libraries"]); | ||
rhs.components = as_fallback_default<std::vector<Antares::Solver::SystemParser::Component>>( | ||
node["components"]); | ||
return true; | ||
} | ||
}; | ||
|
||
} // namespace YAML |
35 changes: 35 additions & 0 deletions
35
src/solver/systemParser/include/antares/solver/systemParser/converter.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,35 @@ | ||
/* | ||
* 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 <antares/study/system-model/library.h> | ||
#include <antares/study/system-model/system.h> | ||
|
||
#include "parser.h" | ||
|
||
namespace Antares::Solver::SystemConverter | ||
{ | ||
|
||
Study::SystemModel::System convert(const SystemParser::System& parserSystem, | ||
const std::vector<Study::SystemModel::Library>& libraries); | ||
|
||
} // namespace Antares::Solver::SystemConverter |
32 changes: 32 additions & 0 deletions
32
src/solver/systemParser/include/antares/solver/systemParser/parser.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,32 @@ | ||
/* | ||
* 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 "antares/solver/systemParser/system.h" | ||
|
||
namespace Antares::Solver::SystemParser | ||
{ | ||
class Parser | ||
{ | ||
public: | ||
System parse(const std::string& content); | ||
}; | ||
} // namespace Antares::Solver::SystemParser |
55 changes: 55 additions & 0 deletions
55
src/solver/systemParser/include/antares/solver/systemParser/system.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,55 @@ | ||
/* | ||
* 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 <string> | ||
#include <vector> | ||
|
||
namespace Antares::Solver::SystemParser | ||
{ | ||
|
||
struct Parameter | ||
{ | ||
std::string id; | ||
std::string type; | ||
double value; | ||
}; | ||
|
||
struct Component | ||
{ | ||
std::string id; | ||
std::string model; | ||
std::string scenarioGroup; | ||
std::vector<Parameter> parameters; | ||
}; | ||
|
||
struct System | ||
{ | ||
std::string id; | ||
std::vector<std::string> libraries; | ||
std::vector<Component> components; | ||
|
||
// will be implemented later | ||
// std::vector<Connections> connections; | ||
}; | ||
|
||
} // namespace Antares::Solver::SystemParser |
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.
Use a dedicated
struct
for the return typeThere 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.
I think it's fine to use a pair and get var like this in this context
const auto [libraryId, modelId] = getSplit...