Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: warn instead of raise violated rules #224

Merged
merged 2 commits into from
Jul 8, 2023

Conversation

redeboer
Copy link
Member

@redeboer redeboer commented Jul 8, 2023

So far, when there are violated rules and/or non-executed rules, find_solutions() raises these as a RuntimeWarning. This is an incorrect use of this exception class that also prevents the user from inspecting the execution info. The RuntimeWarning is therefore now passed through warnings.warn(). The warnings can then be switch off with:

import warnings
warnings.simplefilter("ignore", category=RuntimeWarning)

Still, if there are violated rules, there are no solutions, so an exception is still raised (now as a RuntimeError instead of a ValueError. ExecutionInfo is now passed on to this exception, so that it can be further inspected:

import qrules
try:
    reaction = qrules.generate_transitions(
        initial_state=["pi0"],
        final_state=["gamma", "gamma", "gamma"],
        allowed_interaction_types=["em"],
    )
except RuntimeError as e:
    msg, execution_info = e.args
execution_info.not_executed_node_rules

See also #174

@redeboer redeboer added the ⚙️ Enhancement Improvements and optimizations of existing features label Jul 8, 2023
@redeboer redeboer self-assigned this Jul 8, 2023
@redeboer redeboer marked this pull request as ready for review July 8, 2023 19:20
@redeboer redeboer merged commit bf968b1 into ComPWA:main Jul 8, 2023
@redeboer redeboer deleted the warn-violated-rules branch July 8, 2023 19:21
@redeboer redeboer added the ⚠️ Interface Breaking changes to the API label Jul 8, 2023
redeboer added a commit that referenced this pull request Jul 8, 2023
* ENH: pass execution info through `RuntimeError`
@redeboer redeboer added this to the 0.10.1 milestone Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ Enhancement Improvements and optimizations of existing features ⚠️ Interface Breaking changes to the API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant