Fix NameError crash in beta_bound_examples2 - #197
Open
Chessing234 wants to merge 2 commits into
Open
Conversation
exp_pairs and bounds were referenced before assignment, so this example (invoked at module load) always crashed with NameError. Capture the exponent pairs from beta_bounds_to_exponent_pairs and recompute bounds before the final display call, mirroring the working pattern in the sibling beta_bound_examples().
examples.py ends with a bare beta_bound_examples2() call, left behind in "Add some usage examples to readme". Importing the module - which the README tells readers to do - therefore runs that example, so a reader following the README waits minutes for output they did not ask for, and before the previous commit crashed outright. The other entry points are called from all_examples(), which is left commented out; drop the stray call.
Contributor
Author
|
also dropped the stray beta_bound_examples2() call at the bottom of the file — it made importing examples run that example, which is what surfaced this crash in the first place |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
blueprint/src/python/examples.py:beta_bound_examples2() has always crashed with a NameError, since this function is called unconditionally at module load (examples.py bottom), running
python3 examples.pyfails immediately.Two undefined-variable bugs:
beta_bounds_to_exponent_pairs(hs)and added the result to the hypothesis set, but discarded the return value instead of binding it toexp_pairs. Line 224 then referencedexp_pairs, which was never assigned, raisingNameError: name 'exp_pairs' is not defined.display_two_sets_of_beta_bounds(old_bounds, bounds)call becauseboundswas never assigned in this function (a commented-out line above suggests it was meant to be computed but the line was lost/never added).Fixed by capturing
exp_pairs = beta_bounds_to_exponent_pairs(hs)before use, and computingbounds = compute_best_beta_bounds(hs)before the display call — mirroring the working pattern already used in the sibling functionbeta_bound_examples()in the same file.Verified:
python3 examples.pypreviously raisedNameErrorat examples.py:224 immediately. After the fix, it runs through the full computation (prints the beta bound hull, etc.) with no exception, reaching the finalplt.show()plotting call as expected.