Skip to content

[Experimental] PGM CLI implementation - #1297

Open
TonyXiang8787 wants to merge 56 commits into
mainfrom
feature/pgm-cli
Open

TonyXiang8787 wants to merge 56 commits into
mainfrom
feature/pgm-cli

Conversation

@TonyXiang8787

@TonyXiang8787 TonyXiang8787 commented Feb 2, 2026 •

Copy link
Copy Markdown
Member

This PR attempts to implement a PGM command line interface as native executable which links to the C-API. The executable can be invoked in Python as a Python shim.

Check list

Local test guide

Test install

Run the following at any working folder

uv tool install git+https://github.com/PowerGridModel/power-grid-model.git@feature/pgm-cli
power-grid-model --help
power-grid-model --version
uv tool uninstall power-grid-model

Test editable

Checkout this branch, then do a round of build and test.

uv sync --reinstall
uv run pytest
uv run power-grid-model --help
uv run power-grid-model --version

@TonyXiang8787 TonyXiang8787 self-assigned this Feb 2, 2026
@TonyXiang8787 TonyXiang8787 added feature New feature or request do-not-merge This should not be merged temporarily labels Feb 2, 2026

@mgovers mgovers left a comment

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.

i don't have time to do a full review but this is at least some input

Comment thread power_grid_model_c/power_grid_model_c/CMakeLists.txt Outdated
Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp
Comment thread power_grid_model_c/power_grid_model_cli/main.cpp Outdated
Comment thread power_grid_model_c/CMakeLists.txt
Comment thread src/power_grid_model/_core/power_grid_model_c/run_pgm_cli.py Outdated
Comment thread src/power_grid_model/_core/power_grid_model_c/run_pgm_cli.py
Comment thread src/power_grid_model/_core/power_grid_model_c/run_pgm_cli.py Outdated
Comment thread CMakeLists.txt
@sonarqubecloud

sonarqubecloud Bot commented May 4, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
78.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
77.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Comment thread src/power_grid_model/_core/power_grid_model_c/run_pgm_cli.py Fixed
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
mgovers and others added 16 commits July 9, 2026 12:56
Signed-off-by: Martijn Govers <martijn.govers@alliander.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Removed the GitHub release job from the CI workflow.

Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
@TonyXiang8787 TonyXiang8787 removed the do-not-merge This should not be merged temporarily label Sep 15, 2026
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>

@figueroa1395 figueroa1395 left a comment

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.

Some initial comments/questions

Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_main.cpp
Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_main.cpp
Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_main.cpp Outdated
Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp
Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp
Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp
Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp Outdated
Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp
Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
@TonyXiang8787
TonyXiang8787 marked this pull request as ready for review October 12, 2026 10:52
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>

@figueroa1395 figueroa1395 left a comment

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.

Some additional things:

  • I tested the CLI locally on Mac and it works for me.
  • Should we consider running the validation tests cases via the CLI in the nightly (or weekly or whatever)? Probably as a follow up if yes.

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?

Comment on lines +195 to +196
{"minimum", PGM_short_circuit_voltage_scaling_minimum},
{"maximum", PGM_short_circuit_voltage_scaling_maximum},

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.

"min" and "max" instead?

Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp
Comment on lines +231 to +234
app.add_option("--oc,--output-component", output_components,
"Filter output to only include specified components (can be specified multiple times)");
std::vector<std::string> output_attributes;
app.add_option("--oa,--output-attribute", output_attributes,

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.

"--oa" and "--oc" maybe a bit much?

Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp Outdated
app.add_option("-i,--input", options.input_file, "Input file path")->required()->check(CLI::ExistingFile);
app.add_option("-b,--batch-update", options.batch_update_file,
"Batch update file path. Can be specified multiple times.\n"
"If multiple files are specified, the core will intepret them as the cartesian product of all "

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.

"core" is jargon

Suggested change
"If multiple files are specified, the core will intepret them as the cartesian product of all "
"If multiple files are specified, it will interpret them as the cartesian product of all "

},
CLI::ignore_case));
app.add_flag("--sym,--symmetric-calculation,!--asym,!--asymmetric-calculation", options.symmetric_calculation,
"Use symmetric calculation (1) or not (0)");

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.

What does the 0 and 1 explanation mean? It's confusing.

CLI::ignore_case));
app.add_flag("--sym,--symmetric-calculation,!--asym,!--asymmetric-calculation", options.symmetric_calculation,
"Use symmetric calculation (1) or not (0)");
app.add_option("--error-tolerance", options.error_tolerance, "Error tolerance for iterative calculations");

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.

Mention that the tolerance is in p.u.?

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.

In https://power-grid-model--1297.org.readthedocs.build/en/1297/api_reference/cli-reference.html, the numbers referring to the options aren't organized, we should probably organize them so the should like

--calculation-method ENUM:value in {default->-128,iec60909->newton_raphson->1,iterative_linear->2,iterative_current->3,,linear_current->4,iec60909->5} OR {-128,1,2,3,4,5}

instead of

--calculation-method ENUM:value in {default->-128,iec60909->5,iterative_current->3,iterative_linear->2,linear_current->4,newton_raphson->1} OR {-128,5,3,2,4,1}

This is just one example but something similar happens with most.

Comment thread power_grid_model_c/power_grid_model_cli_backend/src/cli_options.cpp
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants