galgebra
galgebra copied to clipboard
Sync updates from upstream
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 toprimer
)
- [x] Add
- [x] Add notebooks (They are put into examples/primer, and
GAlgebraOutput.ipynb
is renamed togprint.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
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
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.
CI is green for mv.py
except dropped test coverage. https://github.com/pygae/galgebra/pull/510/commits/d853c70706757fcd03d3c11dcf4c7c02b0b39f40
Check out this pull request on
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 .
The changes to test outputs of lin_tran_check
is much significant and looks suspicious:
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/
The diff of primer.ipynb is breaking the formulas into lines by parts:
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.
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.
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:
- add them into the doc strings
- preserve these notebooks as is, and write a simple summary to introduce the background, and maybe link to these notebooks from the doc string
- 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.
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}$
? ++
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
OK, now we only miss some branches of project_in_blade
, diff
, odd
, exp
, inv
due to historical reasons, except mag2
.
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%)
.
With diff-pdf
, it can create a PDF diff uploaded as an artifact of the Github Actions job:
which is pretty "read"-able, only that drastic changes will impact all the following formulas, but it can be mitigated by tweaking the test.
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
.
There are 2 sources of issues in test_gsg_undual_etc.ipynb
-
metric.square_root_of_expr
is smart, but it always addsabs
around theexpr
to besqrt
ed, which defeats the purpose of the logic innorm2
that are trying to determine sign of the value, now I have temporarily revert it until I write a smart but less absolute function. -
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)
test_with(N3)
test_with(S4)
test_with(N4)
test_with(B4)
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
.
The modifications to metric.square_root_of_expr
are making GAs with norm=True
very unhappy.