Skip to content

sim.nr_pq fails to detect over-constrained systems when values are 0 (truthiness bug) #135

@marcostfermin

Description

@marcostfermin

Describe the bug

nr_pq() tries to detect an over-constrained bus using all((P_set[i], Q_set[i], V_set[i][0])), but this treats valid numeric zeros as “False”. So a bus with P=0.0, Q=0.0, and known voltage magnitude is still over-constrained, yet the function does not raise the intended ValueError("Over-Constrained System").

https://electricpy.readthedocs.io/en/latest/_modules/electricpy/sim.html

Reproduction Code

# Setup
import electricpy as ep

# Code which causes failure
# 2-bus minimal Ybus
Ybus = [[-10j, 10j],
        [ 10j,-10j]]

# Bus 1: known Vmag, and P/Q are specified as 0.0 (still "specified")
V_set = [[1.0, 0.0], [None, None]]
P_set = [0.0, None]
Q_set = [0.0, None]

# Should raise "Over-Constrained System" (but currently does not due to truthiness)
F = ep.sim.nr_pq(Ybus, V_set, P_set, Q_set)
print("nr_pq returned without raising; generated F:", F)

Expected behavior

Raise ValueError("Over-Constrained System") because specifying P, Q, and Vmag for the same bus is over-constrained, even when P and Q are 0.0.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. Linux]
  • Python Version [3.11.6]
  • Version [0.4.0]

Additional context

This is a classic “truthiness vs is not None” bug: 0.0 is a valid specified value and should count as present. The check should be something like:

if (P_set[i] is not None) and (Q_set[i] is not None) and (V_set[i][0] is not None): ...

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions