galgebra icon indicating copy to clipboard operation
galgebra copied to clipboard

Sync updates from upstream

Open utensil opened this issue 10 months ago • 16 comments

Addresses #505 .

This PR aims to:

  • incorporate the files from upstream, as is when possible, but avoid breaking compatibilities within this PR
  • lint the code
  • add the notebooks from upstream and use them as tests
  • markers like GSG code starts/ends will be kept to make it easier to identify the added code and distinguish it with other changes between 0.5.0 and 0.5.1, as well as GSG's other proposed changes
  • raise discussions about the changes the break previous tests
  • add documentations for new APIs

The goal here is to make it a foundation for merging other people's work, and avoid accidentally rolling back previous work (check https://github.com/pygae/galgebra/compare/v0.5.0...v0.5.1 to decide what to keep when there is code conflict).

The strategy is to add them and fix them file by file.

TODOs:

  • Add Python files
    • [x] Add mv
    • [x] Add lt
    • [x] Add gprinter
    • [x] Add GAlgebraInit (renamed to primer)
  • [x] Add notebooks (They are put into examples/primer, and GAlgebraOutput.ipynb is renamed to gprint.ipynb, and the rest are ensured to be in lowercase.)
  • [x] Ensure test coverage (with primer notebooks: -1.65%; with undual tests: -1.10%; with lt tests: -0.55%; with mv tests: +0.38%)
  • [x] Add change log
  • [ ] Add the migration guide for the readers of LAGA&VAGC
  • [ ] Check new API doc
  • [x] Investigate the diff of lin_tran_check
  • [ ] Investigate the diff of test_gsg_undual_etc.ipynb

utensil avatar Apr 01 '24 10:04 utensil

The new norm break the following test:

    def test_abs(self):
        ga, e_1, e_2, e_3 = Ga.build('e*1|2|3', g=[1, 1, 1])
        B = ga.mv('B', 'bivector')
        assert abs(B*B) == -(B*B).scalar()

Seems fixable by using metric.square_root_of_expr instead of sqrt

image

utensil avatar Apr 02 '24 01:04 utensil

Codecov Report

Attention: Patch coverage is 75.91623% with 92 lines in your changes are missing coverage. Please review.

Project coverage is 78.95%. Comparing base (d4d09bd) to head (0defe0c).

Files Patch % Lines
galgebra/lt.py 75.33% 37 Missing :warning:
galgebra/gprinter.py 74.16% 31 Missing :warning:
galgebra/primer.py 0.00% 15 Missing :warning:
galgebra/mv.py 89.74% 8 Missing :warning:
galgebra/metric.py 94.11% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #510      +/-   ##
==========================================
+ Coverage   78.05%   78.95%   +0.90%     
==========================================
  Files          17       19       +2     
  Lines        4196     4400     +204     
==========================================
+ Hits         3275     3474     +199     
- Misses        921      926       +5     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Apr 02 '24 02:04 codecov[bot]

CI is green for mv.py except dropped test coverage. https://github.com/pygae/galgebra/pull/510/commits/d853c70706757fcd03d3c11dcf4c7c02b0b39f40

utensil avatar Apr 02 '24 02:04 utensil

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

The changes to test outputs of simple_ga_test are just using covariant/contravariant notation instead of writing all indexes as subscripts, this was suggested in #475 .

image

The changes to test outputs of lin_tran_check is much significant and looks suspicious:

image

Will investigate later. The current green CI is a delusion for now. The visual diff is at: https://app.reviewnb.com/pygae/galgebra/commit/33a33fbefc67a480e7f0565273cc16b0e34f8d09/

utensil avatar Apr 02 '24 03:04 utensil

The diff of primer.ipynb is breaking the formulas into lines by parts:

image

Some default printing setting must be off.

EDIT: The extra [t] comes from \begin{aligned}[t] and KaTeX used by VSCode Jupyter notebook renderer can't render it properly.

utensil avatar Apr 02 '24 10:04 utensil

The line breaking behavior seems to be correct, they appear after Fmt(3) where 3 means one base per line rather than the default behavior One multivector per line.

We can compare regenerated with original to inspect the diff.

utensil avatar Apr 02 '24 13:04 utensil

I've checked that new APIs have basic docstrings, but more elaborative documentations are inside the zips from #472 and #478 . It remains an open question about how to incorporate them into the documentation, there are a few options:

  1. add them into the doc strings
  2. preserve these notebooks as is, and write a simple summary to introduce the background, and maybe link to these notebooks from the doc string
  3. start a grand plan rewriting a systematic documentation, introducing many methods/operations, and convert these into part of that document

1&3 is a lot of work and I don't have enough time to invest into them. Option 2 seems reasonable, but I've decided that's beyond the scope of this PR. I'll only write a change log, and guide the readers to the GAlgebra Primer, and these issues for details.

utensil avatar Apr 06 '24 13:04 utensil

These are clearly not ignorable issues:

examples/ipython/test_gsg_undual_etc.ipynb ...........F.F.FFFFFF                                                                                       [100%]

========================================================================== FAILURES ==========================================================================
____________________________________________________ examples/ipython/test_gsg_undual_etc.ipynb::Cell 11 _____________________________________________________
Notebook cell execution failed
Cell 11: Cell outputs differ

Input:
test_with(S1)

Traceback:
 mismatch 'text/latex'

 assert reference_output == test_output failed:

  "$\\qquad \\i...hint is '0'}$" == "$\\qquad \\i...hint is '0'}$"
  
  Skipping 45 identical leading characters in diff, use -v to show
  - _0\vert = S \quad \text{ when hint is '0'}$
  + _0\vert = \left|{S}\right| \quad \text{ when hint is '0'}$
  ?           +++++++ ++++++++


____________________________________________________ examples/ipython/test_gsg_undual_etc.ipynb::Cell 13 _____________________________________________________
Notebook cell execution failed
Cell 13: Cell outputs differ

Input:
test_with(S2)

Traceback:
 mismatch 'text/latex'

 assert reference_output == test_output failed:

  "$\\qquad \\i...hint is '0'}$" == "$\\qquad \\i...hint is '0'}$"
  
  Skipping 45 identical leading characters in diff, use -v to show
  - _0\vert = S \quad \text{ when hint is '0'}$
  + _0\vert = \left|{S}\right| \quad \text{ when hint is '0'}$
  ?           +++++++ ++++++++


____________________________________________________ examples/ipython/test_gsg_undual_etc.ipynb::Cell 15 _____________________________________________________
Notebook cell execution failed
Cell 15: Cell outputs differ

Input:
test_with(S3)

Traceback:
 mismatch 'text/latex'

 assert reference_output == test_output failed:

  '$\\qquad \\i...\right)}^{2}$' == '$\\qquad \\i...{2}}\\right|$'
  
  - $\qquad \implies \Vert\mathbf{S}\Vert^2 = \left|{S^{2} + {\left( S^{s} \right)}^{2} - {\left( S^{st} \right)}^{2} - {\left( S^{t} \right)}^{2}}\right|$
  ?                                           -------                                                                                             --------
  + $\qquad \implies \Vert\mathbf{S}\Vert^2 = S^{2} + {\left( S^{s} \right)}^{2} - {\left( S^{st} \right)}^{2} - {\left( S^{t} \right)}^{2}$


____________________________________________________ examples/ipython/test_gsg_undual_etc.ipynb::Cell 16 _____________________________________________________
Notebook cell execution failed
Cell 16: Cell outputs differ

Input:
test_with(N3)

Traceback:
 mismatch 'text/latex'

 assert reference_output == test_output failed:

  '$\\qquad \\i...Vert^2 = -25$' == '$\\qquad \\i...\Vert^2 = 25$'
  
  - $\qquad \implies \Vert\mathbf{N}\Vert^2 = 25$
  + $\qquad \implies \Vert\mathbf{N}\Vert^2 = -25$
  ?                                           +


____________________________________________________ examples/ipython/test_gsg_undual_etc.ipynb::Cell 17 _____________________________________________________
Notebook cell execution failed
Cell 17: Cell outputs differ

Input:
test_with(A3)
# Is `normsquared` nonnegative?  Show values of relational and 
# conditional in Case 3(a) of `norm`'s code:
gprint(r'\text{A3.norm2() >= 0}: \quad', A3.norm2() >= 0)
gprint(r'\text{(A3.norm2() >= 0) == 0}: \quad',
       (A3.norm2() >= 0) == True)
# Is `normsquared` nonpositive?  Show values of relational and 
# conditional in Case 3(b):
gprint(r'\text{A3.norm2() <= 0}: \quad', A3.norm2() <= 0)
gprint(r'\text{(A3.norm2() <= 0) == 0}: \quad',
       (A3.norm2() <= 0) == True)
# Is `normsquared` negative?  Show values of relational and 
# conditional complementary to Case 3(a):
gprint(r'\text{A3.norm2() < 0}: \quad', A3.norm2() < 0)
gprint(r'\text{(A3.norm2() < 0) == 0}: \quad',
       (A3.norm2() < 0) == True)

Traceback:
 mismatch 'text/latex'

 assert reference_output == test_output failed:

  '$\\qquad \\i...^{2}\\right)$' == '$\\qquad \\i...^{2}\\right)$'
  
  Skipping 39 identical leading characters in diff, use -v to show
  -  = t^{2} \cdot \left(2 s^{2} + t^{2}\right)$
  ?         ------
  +  = t^{2} \left(2 s^{2} + t^{2}\right)$


____________________________________________________ examples/ipython/test_gsg_undual_etc.ipynb::Cell 18 _____________________________________________________
Notebook cell execution failed
Cell 18: Cell outputs differ

Input:
test_with(S4)

Traceback:
 mismatch 'text/latex'

 assert reference_output == test_output failed:

  '$\\qquad \\i...} \\rho ^{2}$' == '$\\qquad \\i...{2}}\\right|$'
  
  - $\qquad \implies \Vert\mathbf{S}\Vert^2 = \left|{S^{2} - {\left( S^{\phi } \right)}^{2} \rho ^{2} + {\left( S^{\rho } \right)}^{2} - {\left( S^{\rho \phi } \right)}^{2} \rho ^{2}}\right|$
  ?                                           -------                                                                                                                                 --------
  + $\qquad \implies \Vert\mathbf{S}\Vert^2 = S^{2} - {\left( S^{\phi } \right)}^{2} \rho ^{2} + {\left( S^{\rho } \right)}^{2} - {\left( S^{\rho \phi } \right)}^{2} \rho ^{2}$


____________________________________________________ examples/ipython/test_gsg_undual_etc.ipynb::Cell 19 _____________________________________________________
Notebook cell execution failed
Cell 19: Cell outputs differ

Input:
test_with(N4)

Traceback:
 mismatch 'text/latex'

 assert reference_output == test_output failed:

  '$\\qquad \\i...Vert^2 = -25$' == '$\\qquad \\i...\Vert^2 = 25$'
  
  - $\qquad \implies \Vert\mathbf{N}\Vert^2 = 25$
  + $\qquad \implies \Vert\mathbf{N}\Vert^2 = -25$
  ?                                           +


____________________________________________________ examples/ipython/test_gsg_undual_etc.ipynb::Cell 20 _____________________________________________________
Notebook cell execution failed
Cell 20: Cell outputs differ

Input:
test_with(B4)
# Is `normsquared` nonnegative?  Show values of relational and 
# conditional in Case 3(a) of `norm`'s code:
gprint(r'\text{B4.norm2() >= 0}: \quad', B4.norm2() >= 0)
gprint(r'\text{(B4.norm2() >= 0) == 0}: \quad',
       (B4.norm2() >= 0) == True)
# Is `normsquared` nonpositive?  Show values of relational and 
# conditional in Case 3(b):
gprint(r'\text{B4.norm2() <= 0}: \quad', B4.norm2() <= 0)
gprint(r'\text{(B4.norm2() <= 0) == 0}: \quad',
       (B4.norm2() <= 0) == True)
# Is `normsquared` positive?  Show values of relational and 
# conditional complementary to Case 3(b):
gprint(r'\text{B4.norm2() > 0}: \quad', B4.norm2() > 0)
gprint(r'\text{(B4.norm2() > 0) == 0}: \quad',
       (B4.norm2() > 0) == True)

Traceback:
 mismatch 'text/latex'

 assert reference_output == test_output failed:

  '$\\qquad \\i...} \\rho ^{2}$' == '$\\qquad \\i...} \\rho ^{2}$'
  
  - $\qquad \implies \Vert\mathbf{B}\Vert^2 = \phi ^{2} \rho ^{2}$
  + $\qquad \implies \Vert\mathbf{B}\Vert^2 = - \phi ^{2} \rho ^{2}$
  ?                                          ++

utensil avatar Apr 06 '24 13:04 utensil

Inspecting https://app.codecov.io/gh/pygae/galgebra/pull/510?dropdown=coverage&src=pr&el=h1 indicates that we mostly need tests covering

  • matrices whose entries are symbolic functions
  • versor input for Mv
  • det
  • is_singular
  • mode Iinv

utensil avatar Apr 06 '24 14:04 utensil

OK, now we only miss some branches of project_in_blade, diff, odd, exp, inv due to historical reasons, except mag2.

utensil avatar Apr 07 '24 13:04 utensil

codecov/patch 70.22% of diff hit (target 78.05%) is primarily caused by not covering gxpdf in gprint. With test_gxpdf, now we have 76.66% of diff hit (target 78.05%).

utensil avatar Apr 11 '24 06:04 utensil

With diff-pdf, it can create a PDF diff uploaded as an artifact of the Github Actions job:

image image

which is pretty "read"-able, only that drastic changes will impact all the following formulas, but it can be mitigated by tweaking the test.

utensil avatar Apr 11 '24 07:04 utensil

I have written a POC test test_lt_pdf to use the PDF diff testing infrastructure to check the LaTeX output of lin_tran_check.py, it's heavily edited to be visually similar and gPrint_Function is added during the process. The generated diff is attached. Note that the "expected" output was generated by GAlgebra in pre-pygae/galgebra era, i.e. examples/LaTeX/lin_tran_check.pdf.

test_lt_pdf-diff.pdf

utensil avatar Apr 11 '24 14:04 utensil

There are 2 sources of issues in test_gsg_undual_etc.ipynb

  1. metric.square_root_of_expr is smart, but it always adds abs around the expr to be sqrted, which defeats the purpose of the logic in norm2 that are trying to determine sign of the value, now I have temporarily revert it until I write a smart but less absolute function.

  2. The original attached (see #472 ) test notebook somehow contains a few errors, opposite to claimed in the explanations in the notebooks, e.g.

test_with(S3)

image

test_with(N3)

image

test_with(S4)

image

test_with(N4)

image

test_with(B4)

image image image

They are now obvious after carefully reading the code, the explanations in the notebook, and some math intuition.

Note that qform might be negative (for non-Euclidean metric) but not norm2.

utensil avatar Apr 12 '24 08:04 utensil

The modifications to metric.square_root_of_expr are making GAs with norm=True very unhappy.

image image

utensil avatar Apr 12 '24 13:04 utensil

The remaining issues will be recorded here but ignored before merging this PR(left: expected, right: actual):

  1. test_with(S1): $\langle S \rangle_0$.norm() and $\langle S \rangle_2$.norm() (i.e. even grades) has no abs bars
image image
  1. test_with(S2): same as 1
image image
  1. test_with(S3): same as 1
image image
  1. test_with(S4): same as 1
image image

utensil avatar May 09 '24 14:05 utensil