-
Notifications
You must be signed in to change notification settings - Fork 53
[Experimental] PGM CLI implementation #1297
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
Draft
TonyXiang8787
wants to merge
92
commits into
main
Choose a base branch
from
feature/pgm-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,160
−8
Draft
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
3fb4339
try to see cli
TonyXiang8787 d43761d
Merge remote-tracking branch 'origin/main' into feature/pgm-cli
TonyXiang8787 e6805a1
add cli11
TonyXiang8787 ca03120
try to define options
TonyXiang8787 8c85d81
path does not work
TonyXiang8787 caefe3f
add custom validator
TonyXiang8787 76d6da2
add type and method
TonyXiang8787 25cb9f7
almost all options
TonyXiang8787 be83d85
callback to set default
TonyXiang8787 68cae24
add callback
TonyXiang8787 42e237d
add seperate callback
TonyXiang8787 ef61137
add msgpack checker
TonyXiang8787 6d511a9
add parser
TonyXiang8787 7551d28
try attribute buffers
TonyXiang8787 feab93d
add attribute indications, not complete
TonyXiang8787 f51afe2
reproduce error
TonyXiang8787 2a7c959
attribute ptr not working yet
TonyXiang8787 6a95741
attribute buffer works
TonyXiang8787 31fcdf6
Merge remote-tracking branch 'origin/fix/remove-clang-analyzer-hack' …
TonyXiang8787 cdeb453
revert to false in columnar default
TonyXiang8787 c9b7cc1
Merge remote-tracking branch 'origin/main' into feature/pgm-cli
TonyXiang8787 597ffbf
move onwning dataset
TonyXiang8787 22c2c95
re-locate
TonyXiang8787 3e2b608
move create result dataset
TonyXiang8787 e4d5552
use constructor
TonyXiang8787 41ea15b
add ctype
TonyXiang8787 682ff3e
add filter
TonyXiang8787 c87f79e
const reference
TonyXiang8787 11eef1d
get c_string
TonyXiang8787 382f52d
load dataset
TonyXiang8787 33d4fc0
save dataset
TonyXiang8787 5aa7b19
add calculate
TonyXiang8787 f5e10b0
is batch
TonyXiang8787 e3f4191
first run succeeds
TonyXiang8787 9db1688
add frequency
TonyXiang8787 4561799
use enum
TonyXiang8787 90810bd
fix a bug
TonyXiang8787 c407dfa
Merge remote-tracking branch 'origin/main' into feature/pgm-cli
TonyXiang8787 ba2b4d9
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 e357e1f
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 6d08c1b
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 b7df949
down merge
TonyXiang8787 187f614
modify version
TonyXiang8787 4284e02
MD batch
TonyXiang8787 91587ac
no lint
TonyXiang8787 fdf672f
add version to c-api
TonyXiang8787 2365392
test version
TonyXiang8787 e1711ec
add version
TonyXiang8787 6f07857
add version to cli
TonyXiang8787 b32df34
add version in python
TonyXiang8787 8f4db9c
east const
TonyXiang8787 5ffa53e
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 88c1f9e
add cli python shim
TonyXiang8787 33a51a9
add script
TonyXiang8787 6143364
modify names
TonyXiang8787 b2c02c3
add cli version check
TonyXiang8787 b393199
add three part
TonyXiang8787 f71abcd
add cli tests
TonyXiang8787 0b90c9b
start cli test
TonyXiang8787 072ea20
test version
TonyXiang8787 0d961ac
add input data
TonyXiang8787 e8ff08b
save names
TonyXiang8787 0d8e7fc
save data
TonyXiang8787 9a9e110
binary mode
TonyXiang8787 8ec1cdf
use const expr
TonyXiang8787 c078bcc
have address issue
TonyXiang8787 9da03d0
fix a bug on read-after-free
TonyXiang8787 2594919
use ref
TonyXiang8787 c72e169
add command
TonyXiang8787 a5f3f0c
start run command
TonyXiang8787 30be936
fix typo
TonyXiang8787 f0cf8f8
start check result
TonyXiang8787 4261575
add prepare data
TonyXiang8787 158ff7f
check stdout
TonyXiang8787 d87c6ed
calculate i source
TonyXiang8787 8ce3ac0
get batch results
TonyXiang8787 3b8900f
get buffer
TonyXiang8787 a6525e3
test still fails. cli seems to work
TonyXiang8787 96177aa
test work
TonyXiang8787 fc37ebe
fix test
TonyXiang8787 6f30f2a
re-order include
TonyXiang8787 051c14f
fix clang tidy
TonyXiang8787 8fa7799
fix const correctness
TonyXiang8787 e01fc60
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 f855724
fix some errors'
TonyXiang8787 a10710f
fix return code
TonyXiang8787 f606ccd
fix coverage
TonyXiang8787 ccf7d1e
[skip ci] start conda
TonyXiang8787 d536a22
add conda prepare
TonyXiang8787 743b366
fix conda build in PGM CI
TonyXiang8787 98ac9d9
fix clang-tidy
TonyXiang8787 3798741
clang-tidy
TonyXiang8787 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,31 @@ | ||
| # SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org> | ||
| # | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| # This script modifies the pyproject.toml file to remove specific sections | ||
| # [project.entry-points."cmake.root"] and [project.scripts] | ||
| # and deletes the run_pgm_cli.py file from the source directory. | ||
| # It is intended to be run as part of the conda build preparation process. | ||
| # So that conda environment will not be confused with PyPI style Python shim and entry points. | ||
|
|
||
| import re | ||
| from pathlib import Path | ||
|
|
||
| # Read the root pyproject.toml | ||
| pyproject_path = Path(__file__).parent / "pyproject.toml" | ||
| content = pyproject_path.read_text() | ||
|
|
||
| # Remove [project.entry-points."cmake.root"] section | ||
| content = re.sub(r'\n\[project\.entry-points\."cmake\.root"\].*?(?=\n\[|\Z)', "", content, flags=re.DOTALL) | ||
|
|
||
| # Remove [project.scripts] section | ||
| content = re.sub(r"\n\[project\.scripts\].*?(?=\n\[|\Z)", "", content, flags=re.DOTALL) | ||
|
|
||
| # Write back to pyproject.toml | ||
| pyproject_path.write_text(content) | ||
|
|
||
| # Remove run_pgm_cli.py file | ||
| run_pgm_cli_path = ( | ||
| Path(__file__).parent / "src" / "power_grid_model" / "_core" / "power_grid_model_c" / "run_pgm_cli.py" | ||
| ) | ||
| run_pgm_cli_path.unlink(missing_ok=True) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| # SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org> | ||
| # | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| add_executable(power_grid_model_cli | ||
| main.cpp | ||
| cli_options.cpp | ||
| pgm_calculation.cpp | ||
| ) | ||
|
|
||
| target_link_libraries(power_grid_model_cli PRIVATE power_grid_model_c) | ||
| target_link_libraries(power_grid_model_cli PRIVATE power_grid_model_cpp) | ||
| target_link_libraries(power_grid_model_cli PRIVATE CLI11::CLI11) | ||
|
|
||
| set_property(TARGET power_grid_model_cli PROPERTY INSTALL_RPATH_USE_LINK_PATH FALSE) | ||
| set_property(TARGET power_grid_model_cli PROPERTY OUTPUT_NAME "power-grid-model") | ||
| if(APPLE) | ||
| set_property(TARGET power_grid_model_cli PROPERTY INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}") | ||
| elseif(UNIX) # Linux, BSD (not Windows/macOS) | ||
| set_property(TARGET power_grid_model_cli PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}") | ||
| endif() | ||
|
|
||
|
|
||
| target_compile_definitions( | ||
| power_grid_model_cli | ||
| PRIVATE PGM_ENABLE_EXPERIMENTAL | ||
| ) | ||
|
|
||
| install( | ||
| TARGETS power_grid_model_cli | ||
| EXPORT power_grid_modelTargets | ||
| COMPONENT power_grid_model | ||
| ) |
This file contains hidden or 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,59 @@ | ||
| // SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org> | ||
| // | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| #include <power_grid_model_cpp.hpp> | ||
|
|
||
| #include <filesystem> | ||
| #include <map> | ||
| #include <ostream> | ||
| #include <set> | ||
| #include <vector> | ||
|
|
||
| namespace power_grid_model_cpp { | ||
|
|
||
| struct CLIResult { | ||
| int exit_code; | ||
| bool should_exit; | ||
|
|
||
| operator bool() const { return should_exit || exit_code != 0; } | ||
| }; | ||
|
|
||
| // NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding) | ||
| struct ClIOptions { | ||
| std::filesystem::path input_file; | ||
| std::vector<std::filesystem::path> batch_update_file; | ||
| std::filesystem::path output_file; | ||
| PGM_SerializationFormat input_serialization_format{PGM_json}; | ||
| std::vector<PGM_SerializationFormat> batch_update_serialization_format; | ||
| bool is_batch{false}; | ||
|
|
||
| double system_frequency{50.0}; | ||
|
|
||
| Idx calculation_type{PGM_power_flow}; | ||
| Idx calculation_method{PGM_default_method}; | ||
| bool symmetric_calculation{static_cast<bool>(PGM_symmetric)}; | ||
| double error_tolerance{1e-8}; | ||
| Idx max_iterations{20}; | ||
| Idx threading{-1}; | ||
| Idx short_circuit_voltage_scaling{PGM_short_circuit_voltage_scaling_maximum}; | ||
| Idx tap_changing_strategy{PGM_tap_changing_strategy_disabled}; | ||
|
|
||
| bool use_msgpack_output_serialization{false}; | ||
| Idx output_json_indent{2}; | ||
| bool use_compact_serialization{false}; | ||
|
|
||
| std::string output_dataset_name; | ||
| MetaDataset const* output_dataset{nullptr}; | ||
| std::map<MetaComponent const*, std::set<MetaAttribute const*>> output_component_attribute_filters; | ||
|
|
||
| bool verbose{false}; | ||
|
|
||
| friend std::ostream& operator<<(std::ostream& os, ClIOptions const& options); | ||
| }; | ||
|
|
||
| CLIResult parse_cli_options(int argc, char** argv, ClIOptions& options); | ||
|
|
||
| void pgm_calculation(ClIOptions const& cli_options); | ||
|
|
||
| } // namespace power_grid_model_cpp |
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.
Uh oh!
There was an error while loading. Please reload this page.