Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bcedee0
CLI experiment with singed commit
TonyXiang8787 Jul 1, 2026
1b0d2f6
Merge branch 'main' into feature/pgm-cli
mgovers Jul 9, 2026
ce329a6
down merge
TonyXiang8787 Jul 17, 2026
9f0e593
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Jul 20, 2026
63b2c0e
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Jul 21, 2026
13e1f18
Remove GitHub release job from workflow
TonyXiang8787 Jul 21, 2026
3b2548f
help cli
TonyXiang8787 Jul 22, 2026
d9b2015
try sign
TonyXiang8787 Jul 22, 2026
10ae34f
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Jul 22, 2026
aaa70c0
try to split
TonyXiang8787 Jul 22, 2026
417b17b
reuse python shim
TonyXiang8787 Jul 22, 2026
fc99c28
add mutex
TonyXiang8787 Jul 22, 2026
532316a
call back
TonyXiang8787 Jul 22, 2026
21fd9c3
message call back
TonyXiang8787 Jul 22, 2026
bccf944
get cli test
TonyXiang8787 Jul 22, 2026
0e090a4
cli test
TonyXiang8787 Jul 22, 2026
dd4c74a
test more
TonyXiang8787 Jul 22, 2026
b919bac
use c
TonyXiang8787 Jul 22, 2026
42eb6ce
test shim
TonyXiang8787 Jul 22, 2026
0899a7d
Update test target file path for PGMCLI
TonyXiang8787 Jul 23, 2026
d282788
Fix CLI linker language for GCC sanitizer builds
Copilot Jul 23, 2026
b8be263
sonar
TonyXiang8787 Jul 23, 2026
534bc34
clang tidy
TonyXiang8787 Jul 23, 2026
45c9338
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Jul 24, 2026
72a8be0
cmake
TonyXiang8787 Jul 26, 2026
f6215fe
cpp cli
TonyXiang8787 Jul 26, 2026
3c26909
cli
TonyXiang8787 Jul 26, 2026
5767dce
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Jul 27, 2026
b763826
use ranges transform
TonyXiang8787 Jul 27, 2026
f35a02e
test more
TonyXiang8787 Jul 27, 2026
e5c16fe
fix clang tidy
TonyXiang8787 Aug 2, 2026
104c70e
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Aug 19, 2026
bd7f158
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Aug 25, 2026
2fea14d
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Aug 28, 2026
47f4a86
trigger ci
TonyXiang8787 Aug 30, 2026
2c17bd2
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Sep 6, 2026
9a689eb
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Sep 15, 2026
966b155
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Sep 18, 2026
fc934dd
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Oct 1, 2026
05d0cac
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Oct 5, 2026
3e9b45c
start docs
TonyXiang8787 Oct 5, 2026
eb3291a
docs
TonyXiang8787 Oct 5, 2026
1812083
fix name
TonyXiang8787 Oct 5, 2026
5250946
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Oct 6, 2026
6f55d49
Merge branch 'main' into feature/pgm-cli
TonyXiang8787 Oct 12, 2026
1bf768d
use std format
TonyXiang8787 Oct 12, 2026
ec0695b
msgpack check comment
TonyXiang8787 Oct 12, 2026
2444fc2
add user doc
TonyXiang8787 Oct 12, 2026
12f6e7c
add build guide
TonyXiang8787 Oct 12, 2026
41aae17
remove shorthand for many options
TonyXiang8787 Oct 12, 2026
9934062
explain mutex:'
TonyXiang8787 Oct 12, 2026
0e3a08d
add initialization
TonyXiang8787 Oct 12, 2026
e7cc31f
more explanation
TonyXiang8787 Oct 12, 2026
24114ad
fix typo
TonyXiang8787 Oct 13, 2026
7e4a73b
typo
TonyXiang8787 Oct 16, 2026
6e8ab9a
typo cli option
TonyXiang8787 Oct 16, 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 @@ -274,7 +274,12 @@ 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ bld/
# Visual Studio 2017 auto generated files
Generated\ Files/

# Generated during the Read the Docs build
/docs/api_reference/cli-help.txt

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
Expand Down
2 changes: 2 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ build:
- find power_grid_model_c/power_grid_model_c/include -name *.h -exec sed -i -r "s/ PGM_NOEXCEPT//g" {} \;
# build doxygen for C header
- cd docs/doxygen && doxygen && cd ../..
# capture CLI help for the reference page
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}" uv run power-grid-model --help > docs/api_reference/cli-help.txt

# build class and package diagrams
- pyreverse --no-standalone -o dot src/power_grid_model
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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)
Comment thread
TonyXiang8787 marked this conversation as resolved.

if(NOT WIN32)
# thread
Expand Down
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)
5 changes: 5 additions & 0 deletions docs/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
.wy-table-responsive table td, .wy-table-responsive table th {
white-space: inherit;
}

.cli-help pre {
white-space: pre-wrap;
overflow-wrap: anywhere;
}
12 changes: 9 additions & 3 deletions docs/advanced_documentation/build-guide.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to add cli-11 to the MacOS build guide on the package installation part.

Also, should we mention somewhere that after uv sync one can just do uv run power-grid-model -h for the CLI? Or is it obvious?

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ In this repository there are three builds:
* A dynamic library (`.dll` on Windows, `.so` on Linux, or `.dylib` on macOS) with a stable pure C API/ABI which can
be used by any application (enabled by default).
* An install target that installs the package containing the dynamic library (enabled by default).
* Native C++ unit tests.
* A shared library that provides the command-line interface backend.
* A command-line interface executable.
* Native C++ unit tests, including tests for the command-line interface.
* C API tests.
* A performance benchmark program.
* An example C program to call the shared library.
Expand Down Expand Up @@ -111,6 +113,7 @@ Manual installation is only required for standalone CMake builds.
| [eigen3](https://eigen.tuxfamily.org/) | Installed automatically | CMake needs to be able find `eigen3` | header-only | [Mozilla Public License, version 2.0](https://www.mozilla.org/en-US/MPL/2.0/) |
| [nlohmann-json](https://github.com/nlohmann/json) | Installed automatically | CMake needs to be able find `nlohmann_json` | header-only | [MIT](https://github.com/nlohmann/json/blob/develop/LICENSE.MIT) |
| [msgpack-cxx](https://github.com/msgpack/msgpack-c/tree/cpp_master) | Installed automatically | CMake needs to be able find `msgpack-cxx` | header-only | [Boost Software License - Version 1.0](https://github.com/msgpack/msgpack-c/blob/cpp_master/LICENSE_1_0.txt) |
| [CLI11](https://github.com/CLIUtils/CLI11) | Installed automatically | CMake needs to be able find `CLI11` | header-only | [BSD 3-Clause](https://github.com/CLIUtils/CLI11/blob/main/LICENSE) |
| [doctest](https://github.com/doctest/doctest) | None | CMake needs to be able find `doctest` | header-only | [MIT](https://github.com/doctest/doctest/blob/master/LICENSE.txt) |
<!-- pyml enable line-length-->

Expand Down Expand Up @@ -209,8 +212,11 @@ In the developer build the following build targets (directories) are enabled:

* `power_grid_model_c`: a dynamic library (`.so` on Linux, `.dylib` on macOS, `.dll` on Windows) with stable pure
C API/ABI which can be used by any application.
* `power_grid_model_cli_backend`: a shared library that provides the command-line interface backend.
* `power_grid_model_cli`: the command-line interface executable (`power-grid-model`).
* `tests/cpp_unit_tests_*`: (including subdirectories) the different unit test targets for the C++ core using the
`doctest` framework.
* `tests/cpp_cli_tests`: the command-line interface test target using the `doctest` framework.
* `tests/cpp_validation_tests`: the validation test target using the `doctest` framework.
* `tests/native_api_tests`: the C API test target using the `doctest` framework.
* `tests/benchmark_cpp`: the C++ benchmark target for performance measure.
Expand Down Expand Up @@ -275,7 +281,7 @@ The recommended way to get the [C++ packages](#c) and `uv` is via [Homebrew](htt
```shell
brew install \
gdb gcovr lcov lld cmake ninja \
boost eigen nlohmann-json msgpack-cxx doctest uv
boost eigen nlohmann-json msgpack-cxx cli11 doctest uv
```

Append the following lines into the file `${HOME}/.bashrc` (required for `scikit-build` for the Python installation):
Expand Down Expand Up @@ -357,7 +363,7 @@ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | ie
The recommended way to get [C++ packages](#c) is via `conda`. Open a miniforge console.

```shell
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge libboost-headers eigen nlohmann_json msgpack-cxx doctest
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge libboost-headers eigen nlohmann_json msgpack-cxx cli11 doctest
```

### Environment variables
Expand Down
19 changes: 19 additions & 0 deletions docs/api_reference/cli-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>

SPDX-License-Identifier: MPL-2.0
-->

# Power Grid Model CLI Reference

This is the CLI reference for the `power-grid-model`.

**The Power Grid Model CLI is still experimental. We offer no guarantee on stability of CLI arguments!**

See below the CLI Reference, you can also run `power-grid-model --help` to get them:

```{literalinclude} cli-help.txt
:language: text
:class: cli-help
```

1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ user_manual/serialization
:maxdepth: 2
api_reference/python-api-reference
api_reference/power-grid-model-c-api-reference
api_reference/cli-reference
```

```{toctree}
Expand Down
4 changes: 4 additions & 0 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,7 @@ This is what makes Power Grid Model a powerful calculation engine.
You need to create a batch update dataset and put it in the `update_data` argument of `calculate_power_flow`.
Please refer to [Power Flow Example](examples/Power%20Flow%20Example.ipynb) for a detailed tutorial about how to execute
batch calculations.

## Power Grid Model Command Line Interface (CLI)

Power Grid Model also provides an experimental CLI. See [CLI API Reference](api_reference/cli-reference.md) for more details.
2 changes: 2 additions & 0 deletions power_grid_model_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
add_subdirectory("power_grid_model")
add_subdirectory("power_grid_model_c")
add_subdirectory("power_grid_model_cpp")
add_subdirectory("power_grid_model_cli_backend")
add_subdirectory("power_grid_model_cli")
Comment thread
TonyXiang8787 marked this conversation as resolved.
21 changes: 21 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,21 @@
# 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)

target_link_libraries(power_grid_model_cli PRIVATE power_grid_model_cli_backend)

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

install(
TARGETS power_grid_model_cli
EXPORT power_grid_modelTargets
COMPONENT power_grid_model
)
7 changes: 7 additions & 0 deletions power_grid_model_c/power_grid_model_cli/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
//
// SPDX-License-Identifier: MPL-2.0

#include <power_grid_model_cli_backend/cli_main.h>

int main(int argc, char** argv) { return PGM_cli_main(argc, argv, nullptr, nullptr, nullptr); }
73 changes: 73 additions & 0 deletions power_grid_model_c/power_grid_model_cli_backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
#
# SPDX-License-Identifier: MPL-2.0

add_library(
power_grid_model_cli_backend
SHARED
"src/cli_main.cpp"
"src/cli_options.cpp"
"src/pgm_calculation.cpp"
)

target_include_directories(
power_grid_model_cli_backend
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)

file(
GLOB_RECURSE pgm_cli_backend_public_headers
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.h"
)

target_link_libraries(power_grid_model_cli_backend PRIVATE power_grid_model_c)
target_link_libraries(power_grid_model_cli_backend PRIVATE power_grid_model_cpp)
target_link_libraries(power_grid_model_cli_backend PRIVATE CLI11::CLI11)

target_compile_definitions(
power_grid_model_cli_backend
PRIVATE
PGM_CLI_BACKEND_EXPORTS
PGM_ENABLE_EXPERIMENTAL
)

target_sources(
power_grid_model_cli_backend
PUBLIC
FILE_SET pgm_cli_backend_public_headers
TYPE HEADERS
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include/"
FILES "${pgm_cli_backend_public_headers}"
)

set_target_properties(
power_grid_model_cli_backend
PROPERTIES VERSION ${PGM_VERSION} SOVERSION ${PGM_VERSION_MAJOR}
)

set_property(TARGET power_grid_model_cli_backend PROPERTY INSTALL_RPATH_USE_LINK_PATH FALSE)
if(APPLE)
set_property(TARGET power_grid_model_cli_backend PROPERTY INSTALL_RPATH "@loader_path")
elseif(UNIX) # Linux, BSD (not Windows/macOS)
set_property(TARGET power_grid_model_cli_backend PROPERTY INSTALL_RPATH "$ORIGIN")
endif()

if(NOT PGM_MSVC_REPRODUCIBLE_BUILD)
set_target_properties(
power_grid_model_cli_backend
PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE
)
endif()

install(
TARGETS power_grid_model_cli_backend
EXPORT power_grid_modelTargets
COMPONENT power_grid_model
FILE_SET pgm_cli_backend_public_headers
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
//
// SPDX-License-Identifier: MPL-2.0

#pragma once
#ifndef POWER_GRID_MODEL_CLI_BACKEND_CLI_MAIN_H
#define POWER_GRID_MODEL_CLI_BACKEND_CLI_MAIN_H

#ifdef _WIN32
#define PGM_CLI_HELPER_DLL_IMPORT __declspec(dllimport)
#define PGM_CLI_HELPER_DLL_EXPORT __declspec(dllexport)
#define PGM_CLI_HELPER_DLL_LOCAL
#else
#if __GNUC__ >= 4
#define PGM_CLI_HELPER_DLL_IMPORT __attribute__((visibility("default")))
#define PGM_CLI_HELPER_DLL_EXPORT __attribute__((visibility("default")))
#define PGM_CLI_HELPER_DLL_LOCAL __attribute__((visibility("hidden")))
#else
#define PGM_CLI_HELPER_DLL_IMPORT
#define PGM_CLI_HELPER_DLL_EXPORT
#define PGM_CLI_HELPER_DLL_LOCAL
#endif
#endif

#ifdef PGM_CLI_BACKEND_EXPORTS
#define PGM_CLI_API PGM_CLI_HELPER_DLL_EXPORT
#else
#define PGM_CLI_API PGM_CLI_HELPER_DLL_IMPORT
#endif
#define PGM_CLI_LOCAL PGM_CLI_HELPER_DLL_LOCAL

#ifdef __cplusplus
#define PGM_CLI_NOEXCEPT noexcept
#else
#define PGM_CLI_NOEXCEPT
#endif

#ifdef __cplusplus
extern "C" {
#endif

// NOLINTNEXTLINE(modernize-use-using)
typedef void (*PGM_CLIMessageCallback)(char const* msg, void* user_data);

/**
* @brief CLI entry point for the Power Grid Model command line interface.
*
* @param argc Number of command line arguments.
* @param argv Command line arguments.
* @param cout_callback Callback used for standard output. When null, std::cout is used.
* @param cerr_callback Callback used for standard error. When null, std::cerr is used.
* @param user_data Opaque user data forwarded to the callbacks.
* @return Process exit code.
*/
PGM_CLI_API int PGM_cli_main(int argc, char** argv, PGM_CLIMessageCallback cout_callback,
PGM_CLIMessageCallback cerr_callback, void* user_data) PGM_CLI_NOEXCEPT;

#ifdef __cplusplus
}
#endif

#endif // POWER_GRID_MODEL_CLI_BACKEND_CLI_MAIN_H
Loading
Loading