Skip to content

Commit

Permalink
ENH: warn instead of raise violated rules (#224)
Browse files Browse the repository at this point in the history
* ENH: pass execution info through `RuntimeError`
  • Loading branch information
redeboer committed Jul 8, 2023
1 parent b281bee commit fb1485a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/qrules/transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import re
import warnings
from collections import abc, defaultdict
from copy import copy, deepcopy
from enum import Enum, auto
Expand Down Expand Up @@ -613,10 +614,11 @@ def find_solutions( # noqa: C901, PLR0912
for rules in execution_info.violated_node_rules.values():
violated_rules |= rules
if violated_rules:
raise RuntimeError(
msg = (
"There were violated conservation rules: "
+ ", ".join(violated_rules)
f" {', '.join(violated_rules)}"
)
warnings.warn(msg, category=RuntimeWarning, stacklevel=1)
if (
final_result.execution_info.not_executed_edge_rules
or final_result.execution_info.not_executed_node_rules
Expand All @@ -626,13 +628,14 @@ def find_solutions( # noqa: C901, PLR0912
not_executed_rules |= rules
for rules in execution_info.not_executed_node_rules.values():
not_executed_rules |= rules
raise RuntimeWarning(
"There are conservation rules that were not executed: "
+ ", ".join(not_executed_rules)
msg = (
"There are conservation rules that were not executed:"
f" {', '.join(not_executed_rules)}"
)
warnings.warn(msg, category=RuntimeWarning, stacklevel=1)
if not final_solutions:
msg = "No solutions were found"
raise ValueError(msg)
raise RuntimeError(msg, execution_info)

match_external_edges(final_solutions)
final_solutions = [
Expand Down

0 comments on commit fb1485a

Please sign in to comment.