Skip to content

Merge links into nodes: link registration dual code path - #1550

Open
Jerry-Jinfeng-Guo wants to merge 19 commits into
mainfrom
feature/link-registration-dual-code-path
Open

Merge links into nodes: link registration dual code path#1550
Jerry-Jinfeng-Guo wants to merge 19 commits into
mainfrom
feature/link-registration-dual-code-path

Conversation

@Jerry-Jinfeng-Guo

@Jerry-Jinfeng-Guo Jerry-Jinfeng-Guo commented Aug 25, 2026

Copy link
Copy Markdown
Member

Based on the presence of node injection sensors, this PR adds two Link registration path:

  • Link component will be registered as is and sit next to Branch if there is no node injection sensors;
  • Else Link component will be registered as Branch and sit withinin branch index.

Whether this will go forward depends on the outcome of offline discussion.

  • Logic
  • Tests

dependabot Bot and others added 2 commits August 25, 2026 10:06
Bumps the all-dependencies group with 1 update: [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv).


Updates `astral-sh/setup-uv` from 9.0.0 to 10.0.1
- [Release notes](https://github.com/astral-sh/setup-uv/releases)
- [Commits](astral-sh/setup-uv@c771a70...20cfd1b)

---
updated-dependencies:
- dependency-name: astral-sh/setup-uv
  dependency-version: 10.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: all-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
@Jerry-Jinfeng-Guo Jerry-Jinfeng-Guo self-assigned this Aug 25, 2026
@Jerry-Jinfeng-Guo Jerry-Jinfeng-Guo added feature New feature or request do-not-merge This should not be merged labels Aug 25, 2026
@Jerry-Jinfeng-Guo
Jerry-Jinfeng-Guo changed the base branch from main to pgm/feature/register-links-for-merging August 25, 2026 08:28
Base automatically changed from pgm/feature/register-links-for-merging to main August 25, 2026 10:54
@Jerry-Jinfeng-Guo

Copy link
Copy Markdown
Member Author

This PR is blocked by #1545 due to the link output being necessary in produce_output

@Jerry-Jinfeng-Guo
Jerry-Jinfeng-Guo changed the base branch from main to pgm/feature/link-supernode-output-enabled August 27, 2026 09:49
@figueroa1395

Copy link
Copy Markdown
Member

This PR is blocked by #1545 due to the link output being necessary in produce_output

@Jerry-Jinfeng-Guo #1545 is now in merge queue. That should get you unblocked.

Base automatically changed from pgm/feature/link-supernode-output-enabled to main August 31, 2026 16:05
Jerry-Jinfeng-Guo and others added 8 commits September 1, 2026 10:15
Signed-off-by: Jerry Guo <guojinfeng8621@gmail.com>
…iling

Signed-off-by: Jerry Guo <guojinfeng8621@gmail.com>
Signed-off-by: Jerry Guo <6221579+Jerry-Jinfeng-Guo@users.noreply.github.com>
Signed-off-by: Jerry Guo <guojinfeng8621@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <santiago.figueroa.manrique@alliander.com>
Signed-off-by: Santiago Figueroa Manrique <santiago.figueroa.manrique@alliander.com>
Signed-off-by: Nitish Bharambe <nitish.bharambe@alliander.com>
Signed-off-by: Santiago Figueroa Manrique <santiago.figueroa.manrique@alliander.com>
Comment on lines 141 to +165
@@ -154,9 +158,14 @@ inline TopologicalNodesAndCoupling create_topological_nodes(ComponentTopology co
return Idx2D{.group = disconnected, .pos = disconnected};
}

// early out if either is disconnected since the link solver doesn't consume semi-disconnected links
if (from_conn == disconnected || to_conn == disconnected) {
return Idx2D{.group = topo_node, .pos = disconnected};
}

@figueroa1395 figueroa1395 Sep 3, 2026

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.

Two bugs are in here. This is consumed by the link solver algorithm, but it doesn't understand disconnected sides of a link, and that breaks its premise. In addition, the "enumeration" that was coming from the user nodes (i.e. links per supernode being numbered [{{0, 1},{2, 3}}, {4, 5}] instead of [{{0, 1},{2, 3}}, {0, 1}]), was not suitable either.

This is a bit of a hacky fix, as now user_links doesn't really contain the user links indexed by the user nodes, but rather it's own indexing per super node. That said, I added it here to attempt the fix. Since this works, it's probably a better idea to put it where the link solver algorithm consumes user links or elsewhere; this only works because currently user_links isn't consumed elsewhere besides for the link solver algorithm (we can probably delete it in the final clean up for v2).

Comment on lines +129 to +168
@@ -165,7 +165,7 @@ TEST_CASE("Test Supernodes") {
CHECK(std::ranges::equal(
topo_nodes.topo_nodes |
std::views::transform([](TopologicalNode const& node) -> auto& { return node.user_links; }),
std::vector<std::vector<BranchIdx>>{{{0, disconnected}}, {{disconnected, 1}}, {{2, 4}}, {}, {}}));
std::vector<std::vector<BranchIdx>>{{{0, disconnected}}, {{disconnected, 0}}, {{0, 1}}, {}, {}}));

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.

These result from https://github.com/PowerGridModel/power-grid-model/pull/1550/changes#r3921543997, hence you can see here it's hacky.

Comment on lines +287 to +290
auto const user_node_idx = state.components.template get_seq<Node>(fault.get_fault_object());
auto const topo_node_idx =
state.reduced_topology->topo_node_coup.coupling.user_nodes_to_topo_nodes[user_node_idx].group;
auto const topo_bus_idx = state.topo_comp_coup->node[topo_node_idx];

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.

This is the SC bug. Wrong mapping was used.

Comment on lines 139 to +151
@@ -146,9 +146,9 @@ constexpr auto output_result(Component const& link, MainModelState<ComponentCont
}
template <std::same_as<Link> Component, class ComponentContainer, short_circuit_solver_output_type SolverOutputType>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline auto output_result(Component const& link, MainModelState<ComponentContainer> const& /* state */,
inline auto output_result(Component const& link, MainModelState<ComponentContainer> const& state,
MathOutput<std::vector<SolverOutputType>> const& math_output, Idx2D const& topo_id) {
if (topo_id.group == disconnected) {
if (topo_id.group == disconnected || state.topo_comp_coup->node[topo_id.group].group == disconnected) {

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.

This was another bug. The output didn't understand that a link was not energized if it's statuses where on but it wasn't connected to a source.

Comment on lines +101 to +112
template <std::same_as<Link> Component, class ComponentContainer>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
constexpr auto comp_base_sequence_cbegin(MainModelState<ComponentContainer> const& state) {
auto const& link_topo_ids = state.reduced_topology->topo_node_coup.coupling.user_links_to_topo_nodes;

if (std::ranges::ssize(link_topo_ids) == get_component_size<Link>(state.components)) {
// new path: links are not branches
return link_topo_ids.cbegin();
} else {
// legacy path: links are branches
return state.topo_comp_coup->branch.cbegin() + get_component_sequence_offset<Edge, Link>(state.components);
}

@figueroa1395 figueroa1395 Sep 3, 2026

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.

The rest of the issues so far, were related to the "two-path dispatch", similar to this. Where in the old path Branches included links, so the offset was different to the new path (or the container to use was different), where branches and links are separated.

I think it's good that we spam TODOs in every such two-code-path place introduced here, so we can easily pinpoint for the cleanup after v2.

Jerry-Jinfeng-Guo and others added 5 commits September 4, 2026 11:53
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
…e-after-merging

Merge links into nodes: update pf and sc tests
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Test changes are from #1569

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Test changes are from #1569

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Test changes are from #1569

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Test changes are from #1569

@Jerry-Jinfeng-Guo
Jerry-Jinfeng-Guo marked this pull request as ready for review September 4, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge This should not be merged feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants