fix(notebooks): refresh outputs for SymPy 1.13 printing changes (#568)#570
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
Updated with two additions:
The
Covers: version policy, tracking issue pattern, local testing setup, known compat issues (Python 3.12 + SymPy 1.13), and the full notebook refresh + validation workflow including how to extend the script with new cosmetic normalizers. Added to the docs index under a new "Developer guides" toctree section. |
utensil
left a comment
There was a problem hiding this comment.
Thanks for the PR — the validation script and the dev guide are both great additions.
CI fails on gr_metrics cells 16/19/21/23 and Old Format cells 4/8/14. The notebooks were refreshed against SymPy 1.13.3 locally, but CI still installs sympy == 1.12 from test_requirements.txt. The fix is to bump test_requirements.txt to sympy == 1.13.3 in this PR — the notebook refresh and the pin bump should land together.
One concern with validate_nb_refresh.py: normalize_plaintext strips all whitespace, which is too broad. text/plain outputs aren't always matrix art — a sign change like - x to -x or a dropped space between terms would be silently masked. Better to only collapse whitespace in lines that contain box-drawing characters.
The pytest command in bumping-sympy.md should match the actual CI command — please update it to match .github/workflows/ci.yml and add a note pointing readers there for the latest version.
- Bump test_requirements.txt to sympy == 1.13.3 so CI matches the refreshed notebook outputs (root cause of CI failure) - Tighten normalize_plaintext: only strip whitespace in lines that contain unicode box-drawing characters (U+2500-U+257F), leaving other text/plain lines verbatim so sign changes aren't masked - Update pytest command in bumping-sympy.md to match .github/workflows/ ci.yml; add note pointing to CI for the authoritative command Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Addressed review feedback:
|
- Bump test_requirements.txt to sympy == 1.13.3 so CI matches the refreshed notebook outputs (root cause of CI failure) - Tighten normalize_plaintext: only strip whitespace in lines that contain unicode box-drawing characters (U+2500-U+257F), leaving other text/plain lines verbatim so sign changes aren't masked - Update pytest command in bumping-sympy.md to match .github/workflows/ ci.yml; add note pointing to CI for the authoritative command
3eb2b01 to
fc4daf0
Compare
- Bump test_requirements.txt to sympy == 1.13.3 so CI matches the refreshed notebook outputs (root cause of CI failure) - Tighten normalize_plaintext: only strip whitespace in lines that contain unicode box-drawing characters (U+2500-U+257F), leaving other text/plain lines verbatim so sign changes aren't masked - Update pytest command in bumping-sympy.md to match .github/workflows/ ci.yml; add note pointing to CI for the authoritative command Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fc4daf0 to
61c1111
Compare
…ssion SymPy 1.13's trigsimp raises ZeroDivisionError on certain trig expressions (e.g. prolate spheroidal coordinates). Since simplification in _latex is best-effort for display purposes, catch any exception and fall back to the expanded form. Also refreshes LaTeX.ipynb and test_gsg_undual_etc.ipynb outputs for SymPy 1.13.3 printing changes (Mul now renders with \cdot before \left).
utensil
left a comment
There was a problem hiding this comment.
Thanks for pushing through all the iterations.
The try/except Exception: pass around Simp.apply in mv._latex is too broad. That catch will silently swallow any future exception from the simplifier. A galgebra bug causing a TypeError, a memory error, anything would just display unsimplified LaTeX with no warning. The intent is to handle a specific SymPy 1.13 trigsimp regression, so it should catch only that: except ZeroDivisionError to be precise, or except (ZeroDivisionError, ArithmeticError) if you want a bit more room.
Also a small doc fix: bumping-sympy.md has the column spec change described backwards. SymPy 1.13 adds column specs (\begin{array}{} to \begin{array}{ccc}), not removes them.
|
Also closes #566 — this PR contains both of the changes that were blocking that tracker: the notebook output refresh (sub-issue #568) and the |
* docs: add 0.6.1 changelog entries Covers: Mlt component-expression constructor (#578/#580), is_blade null fix (#537), Macdonald PDF update (#577), dev guides (#572/#574), SymPy 1.13 notebook refresh (#570), Lt ImmutableDenseMatrix fix (#569), Python 3.10-3.12 CI (#565). * docs(changelog): fix is_blade entry reference from issue to PR The is_blade entry incorrectly referenced issue 537 but should reference PR 582 to match the convention used in other entries. --------- Co-authored-by: utiberious <utiberious@users.noreply.github.com>
Closes #568.
Closes #566.
Problem
SymPy 1.13 changed several aspects of output rendering, causing nbval to fail on stored outputs:
\begin{array}{cccc}<->\begin{array}{}(column format spec added/removed)\cdot \left(<->\left((explicit\cdotadded/removed when multiplying a radical by a parenthesized expression)Affected:
examples/ipython/gr_metrics.ipynb(Cells 16/19/21/23),examples/ipython/Old Format.ipynb(Cells 4/8/14).The computed values are identical — these are purely cosmetic rendering differences.
Fix
Re-executed both notebooks against SymPy 1.13.3 to refresh the stored outputs. Verified with nbval: 40 passed.
Also fixes a SymPy 1.13 regression where
trigsimpraisesZeroDivisionErroron certain trig expressions (e.g. prolate spheroidal coordinates) during LaTeX printing inMv._latex. The catch is narrowed toZeroDivisionErroronly, falling back to the expanded form for display.Bumps
test_requirements.txtpin fromsympy == 1.12tosympy == 1.13.3.Verification script
Added
scripts/validate_nb_refresh.py— a reusable tool that mechanically confirms a notebook re-execution introduced only cosmetic changes. It normalizes all known cosmetic patterns (array specs,\cdot, whitespace, stream outputs) and fails on any unexpected diff.Usage:
Both notebooks pass: