Skip to content
Draft
Show file tree
Hide file tree
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 Dec 17, 2025
d43761d
Merge remote-tracking branch 'origin/main' into feature/pgm-cli
TonyXiang8787 Dec 17, 2025
e6805a1
add cli11
TonyXiang8787 Dec 17, 2025
ca03120
try to define options
TonyXiang8787 Dec 17, 2025
8c85d81
path does not work
TonyXiang8787 Dec 17, 2025
caefe3f
add custom validator
TonyXiang8787 Dec 17, 2025
76d6da2
add type and method
TonyXiang8787 Dec 17, 2025
25cb9f7
almost all options
TonyXiang8787 Dec 17, 2025
be83d85
callback to set default
TonyXiang8787 Dec 17, 2025
68cae24
add callback
TonyXiang8787 Dec 17, 2025
42e237d
add seperate callback
TonyXiang8787 Dec 17, 2025
ef61137
add msgpack checker
TonyXiang8787 Dec 17, 2025
6d511a9
add parser
TonyXiang8787 Dec 17, 2025
7551d28
try attribute buffers
TonyXiang8787 Dec 18, 2025
feab93d
add attribute indications, not complete
TonyXiang8787 Dec 18, 2025
f51afe2
reproduce error
TonyXiang8787 Dec 18, 2025
2a7c959
attribute ptr not working yet
TonyXiang8787 Dec 18, 2025
6a95741
attribute buffer works
TonyXiang8787 Dec 18, 2025
31fcdf6
Merge remote-tracking branch 'origin/fix/remove-clang-analyzer-hack' …
TonyXiang8787 Dec 18, 2025
cdeb453
revert to false in columnar default
TonyXiang8787 Dec 18, 2025
c9b7cc1
Merge remote-tracking branch 'origin/main' into feature/pgm-cli
TonyXiang8787 Dec 19, 2025
597ffbf
move onwning dataset
TonyXiang8787 Dec 19, 2025
22c2c95
re-locate
TonyXiang8787 Dec 19, 2025
3e2b608
move create result dataset
TonyXiang8787 Dec 19, 2025
e4d5552
use constructor
TonyXiang8787 Dec 19, 2025
41ea15b
add ctype
TonyXiang8787 Dec 19, 2025
682ff3e
add filter
TonyXiang8787 Dec 19, 2025
c87f79e
const reference
TonyXiang8787 Dec 19, 2025
11eef1d
get c_string
TonyXiang8787 Dec 19, 2025
382f52d
load dataset
TonyXiang8787 Dec 19, 2025
33d4fc0
save dataset
TonyXiang8787 Dec 19, 2025
5aa7b19
add calculate
TonyXiang8787 Dec 19, 2025
f5e10b0
is batch
TonyXiang8787 Dec 19, 2025
e3f4191
first run succeeds
TonyXiang8787 Dec 19, 2025
9db1688
add frequency
TonyXiang8787 Dec 19, 2025
4561799
use enum
TonyXiang8787 Dec 19, 2025
90810bd
fix a bug
TonyXiang8787 Dec 19, 2025
c407dfa
Merge remote-tracking branch 'origin/main' into feature/pgm-cli
TonyXiang8787 Dec 29, 2025
ba2b4d9
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Dec 30, 2025
e357e1f
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Jan 14, 2026
6d08c1b
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Jan 20, 2026
b7df949
down merge
TonyXiang8787 Jan 27, 2026
187f614
modify version
TonyXiang8787 Jan 27, 2026
4284e02
MD batch
TonyXiang8787 Jan 27, 2026
91587ac
no lint
TonyXiang8787 Jan 27, 2026
fdf672f
add version to c-api
TonyXiang8787 Jan 27, 2026
2365392
test version
TonyXiang8787 Jan 27, 2026
e1711ec
add version
TonyXiang8787 Jan 27, 2026
6f07857
add version to cli
TonyXiang8787 Jan 27, 2026
b32df34
add version in python
TonyXiang8787 Jan 27, 2026
8f4db9c
east const
TonyXiang8787 Jan 27, 2026
5ffa53e
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Jan 28, 2026
88c1f9e
add cli python shim
TonyXiang8787 Jan 28, 2026
33a51a9
add script
TonyXiang8787 Jan 28, 2026
6143364
modify names
TonyXiang8787 Jan 28, 2026
b2c02c3
add cli version check
TonyXiang8787 Jan 29, 2026
b393199
add three part
TonyXiang8787 Jan 29, 2026
f71abcd
add cli tests
TonyXiang8787 Jan 29, 2026
0b90c9b
start cli test
TonyXiang8787 Jan 29, 2026
072ea20
test version
TonyXiang8787 Jan 29, 2026
0d961ac
add input data
TonyXiang8787 Jan 29, 2026
e8ff08b
save names
TonyXiang8787 Jan 29, 2026
0d8e7fc
save data
TonyXiang8787 Jan 30, 2026
9a9e110
binary mode
TonyXiang8787 Jan 30, 2026
8ec1cdf
use const expr
TonyXiang8787 Jan 30, 2026
c078bcc
have address issue
TonyXiang8787 Jan 30, 2026
9da03d0
fix a bug on read-after-free
TonyXiang8787 Jan 30, 2026
2594919
use ref
TonyXiang8787 Jan 30, 2026
c72e169
add command
TonyXiang8787 Feb 2, 2026
a5f3f0c
start run command
TonyXiang8787 Feb 2, 2026
30be936
fix typo
TonyXiang8787 Feb 2, 2026
f0cf8f8
start check result
TonyXiang8787 Feb 2, 2026
4261575
add prepare data
TonyXiang8787 Feb 2, 2026
158ff7f
check stdout
TonyXiang8787 Feb 2, 2026
d87c6ed
calculate i source
TonyXiang8787 Feb 2, 2026
8ce3ac0
get batch results
TonyXiang8787 Feb 2, 2026
3b8900f
get buffer
TonyXiang8787 Feb 2, 2026
a6525e3
test still fails. cli seems to work
TonyXiang8787 Feb 2, 2026
96177aa
test work
TonyXiang8787 Feb 2, 2026
fc37ebe
fix test
TonyXiang8787 Feb 2, 2026
6f30f2a
re-order include
TonyXiang8787 Feb 2, 2026
051c14f
fix clang tidy
TonyXiang8787 Feb 2, 2026
8fa7799
fix const correctness
TonyXiang8787 Feb 2, 2026
e01fc60
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Feb 3, 2026
f855724
fix some errors'
TonyXiang8787 Feb 3, 2026
a10710f
fix return code
TonyXiang8787 Feb 3, 2026
f606ccd
fix coverage
TonyXiang8787 Feb 3, 2026
ccf7d1e
[skip ci] start conda
TonyXiang8787 Feb 3, 2026
d536a22
add conda prepare
TonyXiang8787 Feb 3, 2026
743b366
fix conda build in PGM CI
TonyXiang8787 Feb 3, 2026
98ac9d9
fix clang-tidy
TonyXiang8787 Feb 3, 2026
3798741
clang-tidy
TonyXiang8787 Feb 3, 2026
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
3 changes: 2 additions & 1 deletion .github/conda_pgm_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name: conda-pgm-env
dependencies:
# build env
- python=3.12
- python=3.14
- pip
- scikit-build-core
# build deps
Expand All @@ -16,6 +16,7 @@ dependencies:
- numpy
- cmake
- ninja
- cli11
# test deps
- pytest
- pytest-cov
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,15 @@ jobs:
cmake --install build/

- name: Build python
run: python -m pip install . --no-build-isolation --no-deps -C wheel.cmake=false
run: |
python conda_build_preparation.py
python -m pip install . --no-build-isolation --no-deps -C wheel.cmake=false

- name: Test
run: pytest
run: |
pytest
power-grid-model --help
power-grid-model --version

github-release:
name: Create and release assets to GitHub
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ find_package(Boost REQUIRED)
find_package(Eigen3 CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(msgpack-cxx REQUIRED)
find_package(CLI11 CONFIG REQUIRED)

if(NOT WIN32)
# thread
Expand Down
7 changes: 7 additions & 0 deletions cmake/pgm_version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ string(
PGM_VERSION
"${_PGM_VERSION_STRIPPED}"
)
string(
REGEX REPLACE
"^([0-9]+)\\.[0-9]+(\\.[0-9]+)?.*"
"\\1"
PGM_VERSION_MAJOR
"${PGM_VERSION}"
)
31 changes: 31 additions & 0 deletions conda_build_preparation.py
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)
1 change: 1 addition & 0 deletions power_grid_model_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
add_subdirectory("power_grid_model")
add_subdirectory("power_grid_model_c")
add_subdirectory("power_grid_model_cpp")
add_subdirectory("power_grid_model_cli")
4 changes: 3 additions & 1 deletion power_grid_model_c/power_grid_model_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ file(

target_link_libraries(power_grid_model_c PRIVATE power_grid_model)

target_compile_definitions(power_grid_model_c PRIVATE PGM_VERSION="${PGM_VERSION}")

target_sources(
power_grid_model_c
PUBLIC
Expand All @@ -44,7 +46,7 @@ set_target_properties(
power_grid_model_c
PROPERTIES
VERSION ${PGM_VERSION}
SOVERSION ${PGM_VERSION}
SOVERSION ${PGM_VERSION_MAJOR}
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ PGM_API char const** PGM_batch_errors(PGM_Handle const* handle);
*/
PGM_API void PGM_clear_error(PGM_Handle* handle);

/**
* @brief Get the version of the Power Grid Model library.
*
* @return A pointer to a zero-terminated string representing the version.
*/
PGM_API char const* PGM_version(void);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions power_grid_model_c/power_grid_model_c/src/handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ using namespace power_grid_model;

using power_grid_model_c::clear_error;
using power_grid_model_c::compile_time_safe_cast;

constexpr char const* version = PGM_VERSION;
} // namespace

// create and destroy handle
Expand Down Expand Up @@ -52,3 +54,4 @@ char const** PGM_batch_errors(PGM_Handle const* handle) {
return handle_ref.batch_errs_c_str.data();
}
void PGM_clear_error(PGM_Handle* handle) { clear_error(handle); }
char const* PGM_version(void) { return version; }
33 changes: 33 additions & 0 deletions power_grid_model_c/power_grid_model_cli/CMakeLists.txt
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
)
59 changes: 59 additions & 0 deletions power_grid_model_c/power_grid_model_cli/cli_functions.hpp
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
Loading
Loading