Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Modeler 2.5a: Read models and system yaml files [ANT-2306] #2540

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
96c13d7
Add dir loadfile/ , add readSystem
payetvin Dec 19, 2024
ffe1554
format
payetvin Dec 19, 2024
e8da375
add readLibraries.cpp
payetvin Dec 19, 2024
b4a2a74
add function to read one lib file
payetvin Dec 19, 2024
478b087
add a loadLibraries func
payetvin Dec 19, 2024
67c3754
format
payetvin Dec 19, 2024
2fb43d6
Add unit test folder
payetvin Dec 19, 2024
ad4ca2d
First test case
payetvin Dec 19, 2024
cba7b31
several libs
payetvin Dec 19, 2024
78e083f
comments
payetvin Dec 19, 2024
4978046
merge develop, conflicts
payetvin Dec 19, 2024
385f53a
test load system
payetvin Dec 19, 2024
6f89696
comments
payetvin Dec 19, 2024
67cd455
add headers
payetvin Dec 19, 2024
a807358
add a main
payetvin Dec 19, 2024
0b3794a
fill main
payetvin Dec 19, 2024
b5a44c7
parameters.yml in class, correct extension: yml and not yaml
payetvin Dec 20, 2024
beb7339
test file not yml
payetvin Dec 20, 2024
869a67a
handle invalid directory for the study
payetvin Dec 20, 2024
7d8c306
fix test
payetvin Dec 20, 2024
02f366f
use namespace loadFiles for parameters
payetvin Dec 20, 2024
d429081
error handling for libraries loading
payetvin Dec 20, 2024
f8c3d70
error handling for system
payetvin Dec 20, 2024
9d93c9d
catch yaml exception, use mark if available
payetvin Dec 23, 2024
557edaf
Merge branch 'develop' into feature/2.5-read-input-files
payetvin Dec 24, 2024
5bda772
Add loadParameters.cpp
payetvin Dec 24, 2024
0dc1f63
Remove windows related lines in modeler main cmake
payetvin Dec 24, 2024
20df9eb
format
payetvin Dec 24, 2024
d74f595
fix tests
payetvin Dec 24, 2024
732b0ef
try fix windows unit tests
payetvin Dec 24, 2024
b39407f
try fix windows unit tests 2
payetvin Dec 24, 2024
663b786
catch specific error in main
payetvin Dec 24, 2024
4c42da5
catch generic exception in main
payetvin Dec 24, 2024
4dd06fa
change tests layout
payetvin Dec 24, 2024
58e1148
test parameter missing
payetvin Dec 24, 2024
511dc7e
format
payetvin Dec 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/solver/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(api)
add_subdirectory(ortoolsImpl)
add_subdirectory(loadFiles)
31 changes: 31 additions & 0 deletions src/solver/modeler/loadFiles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
set(SOURCES
readSystem.cpp
readLibraries.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
io
payetvin marked this conversation as resolved.
Show resolved Hide resolved
Antares::systemParser
Antares::modelParser
Antares::modelConverter
)

install(DIRECTORY include/antares
DESTINATION "include"
)
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 <filesystem>

#include <antares/study/system-model/library.h>
#include <antares/study/system-model/system.h>

namespace Antares::Solver::LoadFiles
{

Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath,
const std::vector<Study::SystemModel::Library>& libraries);

} // namespace Antares::Solver::LoadFiles
60 changes: 60 additions & 0 deletions src/solver/modeler/loadFiles/readLibraries.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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/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)
{
const std::string libraryStr = IO::readFile(filePath);

ModelParser::Parser parser;
ModelParser::Library libraryObj = parser.parse(libraryStr);
return ModelConverter::convert(libraryObj);
}

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() << "File ignored because of wrong extension: " << entry.path();
payetvin marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

libraries.push_back(loadSingleLibrary(entry.path()));
}

return libraries;
}
} // namespace Antares::Solver::LoadFiles
43 changes: 43 additions & 0 deletions src/solver/modeler/loadFiles/readSystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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/io/file.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)
{
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
1 change: 1 addition & 0 deletions src/tests/src/solver/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(api)
add_subdirectory(loadFiles)
14 changes: 14 additions & 0 deletions src/tests/src/solver/modeler/loadFiles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
54 changes: 54 additions & 0 deletions src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/license/mpl-2-0/>.
*/
#define WIN32_LEAN_AND_MEAN

#include <fstream>
#define BOOST_TEST_MODULE load modeler files

#include <boost/test/unit_test.hpp>

#include <antares/solver/modeler/loadFiles/loadFiles.h>

#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()
Loading