Skip to content

fix(notebooks): refresh outputs for SymPy 1.13 printing changes (#568)#570

Merged
utensil merged 7 commits intopygae:masterfrom
utiberious:fix/issue-568-notebook-outputs
Apr 2, 2026
Merged

fix(notebooks): refresh outputs for SymPy 1.13 printing changes (#568)#570
utensil merged 7 commits intopygae:masterfrom
utiberious:fix/issue-568-notebook-outputs

Conversation

@utiberious
Copy link
Copy Markdown
Contributor

@utiberious utiberious commented Apr 1, 2026

Closes #568.
Closes #566.

Problem

SymPy 1.13 changed several aspects of output rendering, causing nbval to fail on stored outputs:

  1. LaTeX array column specs: \begin{array}{cccc} <-> \begin{array}{} (column format spec added/removed)
  2. LaTeX multiplication dot: \cdot \left( <-> \left( (explicit \cdot added/removed when multiplying a radical by a parenthesized expression)
  3. Plain-text whitespace: unicode matrix art alignment shifts by 1 space in some rows
  4. Stream outputs: mpmath DeprecationWarnings appearing in one environment but not another

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 trigsimp raises ZeroDivisionError on certain trig expressions (e.g. prolate spheroidal coordinates) during LaTeX printing in Mv._latex. The catch is narrowed to ZeroDivisionError only, falling back to the expanded form for display.

Bumps test_requirements.txt pin from sympy == 1.12 to sympy == 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:

# Compare against git ref directly:
python scripts/validate_nb_refresh.py --git HEAD^ examples/ipython/gr_metrics.ipynb

# Or with explicit old/new files:
python scripts/validate_nb_refresh.py old.ipynb new.ipynb

Both notebooks pass:

OK   gr_metrics.ipynb: all output diffs are cosmetic
OK   Old Format.ipynb: all output diffs are cosmetic

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@utiberious
Copy link
Copy Markdown
Contributor Author

Updated with two additions:

scripts/validate_nb_refresh.py — improved CLI help

The --git flag now has explicit usage examples explaining which commit it compares against:

# Compare the version at the previous commit (HEAD^) against the current working copy:
python scripts/validate_nb_refresh.py --git HEAD^ examples/ipython/gr_metrics.ipynb

# Compare the version on master against the current branch:
python scripts/validate_nb_refresh.py --git master examples/ipython/gr_metrics.ipynb

doc/dev/bumping-sympy.rst — new developer guide

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.

Copy link
Copy Markdown
Member

@utensil utensil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

utiberious added a commit to utiberious/galgebra that referenced this pull request Apr 2, 2026
- 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>
@utiberious
Copy link
Copy Markdown
Contributor Author

Addressed review feedback:

  • test_requirements.txt bumped to sympy == 1.13.3 — the notebook refresh and the pin bump now land together, which fixes the CI failure
  • normalize_plaintext tightened: whitespace stripping now applies only to lines containing unicode box-drawing characters (U+2500–U+257F), so other text/plain content (LaTeX strings, math expressions) is compared verbatim. Both target notebooks still pass the validator.
  • bumping-sympy.md pytest command updated to match .github/workflows/ci.yml, with a note pointing there for the authoritative command.

validate_nb_refresh.py --git HEAD passes for both gr_metrics.ipynb and Old Format.ipynb with the new normalizer.

- 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
@utiberious utiberious force-pushed the fix/issue-568-notebook-outputs branch from 3eb2b01 to fc4daf0 Compare April 2, 2026 04:37
utiberious added a commit to utiberious/galgebra that referenced this pull request Apr 2, 2026
- 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>
@utiberious utiberious force-pushed the fix/issue-568-notebook-outputs branch from fc4daf0 to 61c1111 Compare April 2, 2026 04:54
…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).
Copy link
Copy Markdown
Member

@utensil utensil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@utensil utensil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good now.

@utensil utensil merged commit 7b4e085 into pygae:master Apr 2, 2026
5 checks passed
@utiberious
Copy link
Copy Markdown
Contributor Author

Also closes #566 — this PR contains both of the changes that were blocking that tracker: the notebook output refresh (sub-issue #568) and the test_requirements.txt pin bump (sympy == 1.12sympy == 1.13.3). With #569 already merged for the ImmutableDenseMatrix fix (#567), this PR completes everything #566 was tracking.

utiberious added a commit to utiberious/galgebra that referenced this pull request Apr 2, 2026
Covers: Mlt component-expression constructor (pygae#578/pygae#580),
is_blade null fix (pygae#537), Macdonald PDF update (pygae#577),
dev guides (pygae#572/pygae#574), SymPy 1.13 notebook refresh (pygae#570),
Lt ImmutableDenseMatrix fix (pygae#569), Python 3.10-3.12 CI (pygae#565).
utensil pushed a commit that referenced this pull request Apr 3, 2026
* 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>
@utensil utensil mentioned this pull request Apr 3, 2026
2 tasks
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.

Update notebook outputs for SymPy 1.13 printing changes Bump SymPy to 1.13

2 participants