Skip to content

Commit 1e991e1

Browse files
Saelyosalihamdan
andauthored
Improve singular matrix error (#301)
Improve error message when there is a NaN in the jacobian, by identifying the problematic element Closes #299 --------- Co-authored-by: Ali Hamdan <[email protected]>
1 parent 3e44152 commit 1e991e1

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

doc/Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ og:description: See what's new in the latest release of Roseau Load Flow !
1717

1818
# Changelog
1919

20+
## Unreleased
21+
22+
- {gh-pr}`301` {gh-issue}`299` Improve the error message when the Jacobian matrix contains infinite
23+
or NaN values.
24+
2025
## Version 0.11.0
2126

2227
This release adds official support for Python 3.13 and adds a new experimental backward-forward solver.

roseau/load_flow/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class RoseauLoadFlowExceptionCode(StrEnum):
105105
LOAD_FLOW_NOT_RUN = auto()
106106
SEVERAL_NETWORKS = auto()
107107
BAD_JACOBIAN = auto()
108+
NAN_VALUE = auto()
108109

109110
# Solver
110111
BAD_SOLVER_NAME = auto()

roseau/load_flow/network.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -609,20 +609,31 @@ def _handle_error(self, e: RuntimeError) -> NoReturn:
609609
elif msg.startswith("1 "):
610610
msg = msg[2:]
611611
zero_elements_index, inf_elements_index = self._solver._cy_solver.analyse_jacobian()
612-
if zero_elements_index:
612+
if inf_elements_index:
613+
inf_elements = [self._elements[i] for i in inf_elements_index]
614+
printable_elements = ", ".join(f"{type(e).__name__}({e.id!r})" for e in inf_elements)
615+
msg += (
616+
f"The problem seems to come from the elements [{printable_elements}] that induce infinite values."
617+
)
618+
power_load = False
619+
flexible_load = False
620+
for inf_element in inf_elements:
621+
if isinstance(inf_element, PowerLoad):
622+
power_load = True
623+
if inf_element.is_flexible:
624+
flexible_load = True
625+
if power_load:
626+
msg += " This might be caused by a bad potential initialization of a power load"
627+
if flexible_load:
628+
msg += ", or by flexible loads with very high alpha or incorrect flexible parameters voltages."
629+
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.NAN_VALUE)
630+
elif zero_elements_index:
613631
zero_elements = [self._elements[i] for i in zero_elements_index]
614632
printable_elements = ", ".join(f"{type(e).__name__}({e.id!r})" for e in zero_elements)
615633
msg += (
616634
f"The problem seems to come from the elements [{printable_elements}] that have at least one "
617635
f"disconnected phase. "
618636
)
619-
if inf_elements_index:
620-
inf_elements = [self._elements[i] for i in inf_elements_index]
621-
printable_elements = ", ".join(f"{type(e).__name__}({e.id!r})" for e in inf_elements)
622-
msg += (
623-
f"The problem seems to come from the elements [{printable_elements}] that induce infinite "
624-
f"values. This might be caused by flexible loads with very high alpha."
625-
)
626637
logger.error(msg)
627638
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.BAD_JACOBIAN) from e
628639
else:

0 commit comments

Comments
 (0)