Skip to content

[BugFix] fast_any_tap boundary handling boundary handling in binary search - #1632

Open
Jerry-Jinfeng-Guo wants to merge 3 commits into
mainfrom
pgm/bugfix/fast-any-tap-beyond-voltage-band-behavior
Open

Jerry-Jinfeng-Guo wants to merge 3 commits into
mainfrom
pgm/bugfix/fast-any-tap-beyond-voltage-band-behavior

Conversation

@Jerry-Jinfeng-Guo

Copy link
Copy Markdown
Member

Fixes #1215

The behaviour that lead to the original bug was due to us strictly limiting binary search to search between the upper bound and lower bounds. In cases where target voltage range lives outside such bounds, boundary taps should be considered.

Some other tests are also updated. Due to the nature of including a boundary, binary search will terminate at lower_bound == upper_bound and will not run all the way until max_iter reached. This will change the behaviour of the search wrt maximum iteration exceptions.

Arguably, if target range falls outside the achievable range, we return the closest tap without exception, the same should apply to small u_band.

Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
@Jerry-Jinfeng-Guo Jerry-Jinfeng-Guo self-assigned this Oct 8, 2026
@Jerry-Jinfeng-Guo Jerry-Jinfeng-Guo added the bug Something isn't working label Oct 8, 2026

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.

Pure binary search runs will not trigger max iteration error.

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.

so what does it return if there are 2 conflicting tap changers? Does it choose either of the settings? How does it choose which one is better?

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.

The built-in reset mechanism will handle that and the top layer optimization logic remains the same.

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.

Discussion needed wrt behaviour.

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.

We originally talked about 2 edge cases in which the boundary handling needs an explicit choice:

  • u_set + u_band too low for all tap positions, or u_set - u_band too high for all tap positions
  • small u_band: some tap positions result in a voltage below u_set - u_band and some tap positions result in a voltage above u_band + u_band (this case)
    • This case is ambiguous and we indeed should discuss now whether to hard error or allow it for binary search.
    • I believe that binary search setting on one or the other makes sense (I agree with your choice)
    • How does this work for max and min strategies, respectively? Are these edge cases handled correctly now?

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.

Indeed, we should have this discussion. As for min and max strategies, they are both 'unaffected' thanks to the explore_neighbourhood we put in place for the final wiggle.

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'm unresolving because I have a question that's likely related: The same test case for any strategy still fails with MaxIterationReached, shouldn't both behave the same in this case, or at least both have the same behaviour even if the final tap position isn't the same?

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.

I am in principle agreeing with your point. However, I would argue that we need to align the behavior of any strategy to that of the physical behavior. That is, if a ping-poinging behavior is detected during an any search, the search should terminate. This will eliminate the infinite loops we may have with ultra small u_band and return a tap pos that is close to said band.

In short, we should revisit the any strategy.

figueroa1395
figueroa1395 previously approved these changes Oct 16, 2026

@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.

Only small remarks made

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.

Side note: std::midpoint(10, 21) == 15 and std::midpoint(21, 10) == 16, so the description is wrong. It doesn't affect the current bug-fix, but nice to address it at once.

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.

See 80eea98

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.

and b15c322

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'm unresolving because I have a question that's likely related: The same test case for any strategy still fails with MaxIterationReached, shouldn't both behave the same in this case, or at least both have the same behaviour even if the final tap position isn't the same?

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 name of the folder suggests that this case would reach max-iterations, right? Can we change it so we don't get confused? Same for below.

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.

If we do intend to revisit the any strategy to unify the behavior, I would do the renaming in that follow-up. I will put some comment in the test so that this is clear.

Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] fast_any_tap incorrectly handles voltage bands outside the achievable voltage range

3 participants