Skip to content

Fix NameError crash in beta_bound_examples2 - #197

Open
Chessing234 wants to merge 2 commits into
teorth:mainfrom
Chessing234:fix-beta-bound-examples2-nameerror
Open

Fix NameError crash in beta_bound_examples2#197
Chessing234 wants to merge 2 commits into
teorth:mainfrom
Chessing234:fix-beta-bound-examples2-nameerror

Conversation

@Chessing234

Copy link
Copy Markdown
Contributor

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.py fails immediately.

Two undefined-variable bugs:

  1. Line 215 called beta_bounds_to_exponent_pairs(hs) and added the result to the hypothesis set, but discarded the return value instead of binding it to exp_pairs. Line 224 then referenced exp_pairs, which was never assigned, raising NameError: name 'exp_pairs' is not defined.
  2. After fixing (1), the function still crashed at the final display_two_sets_of_beta_bounds(old_bounds, bounds) call because bounds was 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 computing bounds = compute_best_beta_bounds(hs) before the display call — mirroring the working pattern already used in the sibling function beta_bound_examples() in the same file.

Verified: python3 examples.py previously raised NameError at examples.py:224 immediately. After the fix, it runs through the full computation (prints the beta bound hull, etc.) with no exception, reaching the final plt.show() plotting call as expected.

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.
@Chessing234

Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant