Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ venv.bak/
.pytest_cache

# backup files from 2to3
**/*.bak
**/*.bak

# Sphinx
doc/_build
doc/python/*.tex
doc/python/*.aux
doc/python/*.bak.pdf
13 changes: 5 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then lsb_release -a ; fi

install:
- pip install -e .
- pip install pytest-cov
- pip install .

script:
# Run tests and generate coverage report
- pytest --cov=galgebra test
# Validate Jupyter notebooks and generate coverage report
- if [[ "$TRAVIS_PYTHON_VERSION" == 2.7 ]]; then pip install ipython==5.8.0 ; fi
- pip install nbval
- pytest --nbval examples/ipython/ --current-env
- pytest --nbval doc/ipython/ --current-env

script:
# Run tests, validate Jupyter notebooks and generate coverage report
- pytest --cov=galgebra --nbval examples/ipython/ --nbval doc/ipython/ --nbval doc/python/ --current-env test
Copy link
Member Author

Choose a reason for hiding this comment

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

Tests covers more forms of tests and collects the coverage stat data in one go.

Copy link
Member

Choose a reason for hiding this comment

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

Thats neat


after_success:
- pip install codecov
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ Installing Galgebra

### Dependencies

- [Python](https://www.python.org/) 2.7
- with experimental Python 3 support
- [Python](https://www.python.org/) 2.7 & 3
- tests pass under both Python 2.7 & 3.6
- [SymPy](https://www.sympy.org)

### Installing Galgebra From PyPI

```bash
pip install galgebra
```

### Installing Galgebra From Source

To install from local source code, run from the repository root:
Expand All @@ -31,8 +36,6 @@ To install from local source code, run from the repository root:
pip install .
```

We are also working towards a PyPI release based on pygae/galgebra.

### Running tests to verify the installation

Run from the repository root:
Expand All @@ -51,10 +54,6 @@ pytest test
TODO
-----

Get compatible with python 3

Get Travis set up with some good tests

Copy link
Member Author

Choose a reason for hiding this comment

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

These 2 TODOs are done. 😄

Get the docs on read the docs

Ensure functions are documented
Expand Down
40 changes: 20 additions & 20 deletions doc/python/BACCAB.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from printer import Format,xpdf
from ga import Ga
from mv import Com
from __future__ import absolute_import, division
from __future__ import print_function
from galgebra.printer import Format, xpdf
from galgebra.ga import Ga
Copy link
Member Author

@utensil utensil Feb 14, 2019

Choose a reason for hiding this comment

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

If the users install galgebra from pip, the way of importing the modules has to conform to the standard "namespaced" way instead of just importing modules from a global namespace. This might break some old code but it's a necessary transition process.

Copy link
Member

Choose a reason for hiding this comment

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

agreed


Format()
g4d = Ga('a b c d')
(a,b,c,d) = g4d.mv()

print 'g_{ij} =',g4d.g
print '\\bm{a|(b*c)} =',a|(b*c)
print '\\bm{a|(b^c)} =',a|(b^c)
print '\\bm{a|(b^c^d)} =',a|(b^c^d)
print '\\bm{a|(b^c)+c|(a^b)+b|(c^a)} =',(a|(b^c))+(c|(a^b))+(b|(c^a))
print '\\bm{a*(b^c)-b*(a^c)+c*(a^b)} =',a*(b^c)-b*(a^c)+c*(a^b)
print '\\bm{a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)} =',\
a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)
print '\\bm{(a^b)|(c^d)} =',(a^b)|(c^d)
print '\\bm{((a^b)|c)|d} =',((a^b)|c)|d
print '\\bm{(a^b)\\times (c^d)} =',Com(a^b,c^d)
xpdf(paper='letter',prog=True)



(a, b, c, d) = g4d.mv()

print('g_{ij} =', g4d.g)
print('\\bm{a|(b*c)} =', a | (b * c))
print('\\bm{a|(b^c)} =', a | (b ^ c))
print('\\bm{a|(b^c^d)} =', a | (b ^ c ^ d))
# FIXME:FIXED this should print 0, got blank
print('\\bm{a|(b^c)+c|(a^b)+b|(c^a)} =',
(a | (b ^ c)) + (c | (a ^ b)) + (b | (c ^ a)))
print('\\bm{a*(b^c)-b*(a^c)+c*(a^b)} =',
a * (b ^ c) - b * (a ^ c) + c * (a ^ b))
print('\\bm{a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)} =',
a * (b ^ c ^ d) - b * (a ^ c ^ d) + c * (a ^ b ^ d) - d * (a ^ b ^ c))
print('\\bm{(a^b)|(c^d)} =', (a ^ b) | (c ^ d))
print('\\bm{((a^b)|c)|d} =', ((a ^ b) | c) | d)
print('\\bm{(a^b)\\times (c^d)} =', Ga.com(a ^ b, c ^ d))
xpdf(paper='letter', prog=True)
35 changes: 19 additions & 16 deletions doc/python/Dirac.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@

from __future__ import absolute_import, division
from __future__ import print_function
import sys
from sympy import symbols,sin,cos
from printer import Format,xpdf,Get_Program,Print_Function
from ga import Ga
from sympy import symbols, sin, cos
from galgebra.printer import Format, xpdf, Get_Program, Print_Function
from galgebra.ga import Ga

Format()
coords = symbols('t x y z',real=True)
(st4d,g0,g1,g2,g3) = Ga.build('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords)
coords = symbols('t x y z', real=True)
(st4d, g0, g1, g2, g3) = Ga.build(
'gamma*t|x|y|z', g=[1, -1, -1, -1], coords=coords)
I = st4d.i

(m,e) = symbols('m e')
(m, e) = symbols('m e')

psi = st4d.mv('psi','spinor',f=True)
A = st4d.mv('A','vector',f=True)
sig_z = g3*g0
psi = st4d.mv('psi', 'spinor', f=True)
A = st4d.mv('A', 'vector', f=True)
sig_z = g3 * g0

print '\\text{4-Vector Potential\\;\\;}\\bm{A} =',A
print '\\text{8-component real spinor\\;\\;}\\bm{\\psi} =',psi
print('\\text{4-Vector Potential\\;\\;}\\bm{A} =', A)
print('\\text{8-component real spinor\\;\\;}\\bm{\\psi} =', psi)

dirac_eq = (st4d.grad*psi)*I*sig_z-e*A*psi-m*psi*g0
dirac_eq = (st4d.grad * psi) * I * sig_z - e * A * psi - m * psi * g0
dirac_eq = dirac_eq.simplify()

dirac_eq.Fmt(3,r'%\text{Dirac Equation\;\;}\nabla \bm{\psi}'+\
r' I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0')
xpdf(paper='landscape',prog=True)
# FIXME terms of \psi^{ty} are not grouped together
print(dirac_eq.Fmt(3, r'%\text{Dirac Equation\;\;}\nabla \bm{\psi}' +
r' I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0'))
xpdf(paper='landscape', prog=True)
74 changes: 40 additions & 34 deletions doc/python/Dop.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
from __future__ import absolute_import, division
from __future__ import print_function
from sympy import symbols, sin
from printer import Format,xpdf
from ga import Ga
from galgebra.printer import Format, xpdf
from galgebra.ga import Ga

Format()
coords = (x,y,z) = symbols('x y z',real=True)
(o3d,ex,ey,ez) = Ga.build('e*x|y|z',g=[1,1,1],coords=coords)
X = x*ex+y*ey+z*ez
coords = (x, y, z) = symbols('x y z', real=True)
(o3d, ex, ey, ez) = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)
X = x * ex + y * ey + z * ez
I = o3d.i
v = o3d.mv('v','vector')
f = o3d.mv('f','scalar',f=True)
A = o3d.mv('A','vector',f=True)
dd = v|o3d.grad
lap = o3d.grad*o3d.grad
print r'\bm{X} =',X
print r'\bm{v} =',v
print r'\bm{A} =', A
print r'%\bm{v}\cdot\nabla =', dd
print r'%\nabla^{2} =',lap
print r'%\bm{v}\cdot\nabla f =',dd*f
print r'%\nabla^{2} f =',lap*f
print r'%\nabla^{2} \bm{A} =',lap*A
print r'%\bar{\nabla}\cdot v =', o3d.rgrad|v
Xgrad = X|o3d.grad
rgradX = o3d.rgrad|X
print r'%\bm{X}\cdot \nabla =', Xgrad
print r'%\bar{\nabla}\cdot \bm{X} =', rgradX
com = Xgrad - rgradX
print r'%\bm{X}\cdot \nabla - \bar{\nabla}\cdot \bm{X} =', com
sph_coords = (r,th,phi) = symbols('r theta phi',real=True)
(sp3d,er,eth,ephi) = Ga.build('e',g=[1,r**2,r**2*sin(th)**2],\
coords=sph_coords,norm=True)
f = sp3d.mv('f','scalar',f=True)
lap = sp3d.grad*sp3d.grad
print r'%\nabla^{2} = \nabla\cdot\nabla =', lap
print r'%\lp\nabla^{2}\rp f =', lap*f
print r'%\nabla\cdot\lp\nabla f\rp =',sp3d.grad|(sp3d.grad*f)
xpdf(paper='landscape',crop=True)
v = o3d.mv('v', 'vector')
f = o3d.mv('f', 'scalar', f=True)
A = o3d.mv('A', 'vector', f=True)
dd = v | o3d.grad
lap = o3d.grad * o3d.grad
print(r'\bm{X} =', X)
print(r'\bm{v} =', v)
print(r'\bm{A} =', A)
print(r'%\bm{v}\cdot\nabla =', dd)
print(r'%\nabla^{2} =', lap)
print(r'%\bm{v}\cdot\nabla f =', dd * f)
print(r'%\nabla^{2} f =', lap * f)
print(r'%\nabla^{2} \bm{A} =', lap * A)
print(r'%\bar{\nabla}\cdot v =', o3d.rgrad | v)
Xgrad = X | o3d.grad
rgradX = o3d.rgrad | X
print(r'%\bm{X}\cdot \nabla =', Xgrad)
# FIXME This outputs incorrectly, the scalar part 3 is missing
print(r'%\bar{\nabla}\cdot \bm{X} =', rgradX)
# FIXME The following code complains:
# ValueError: In Dop.Add complement flags have different values: False vs. True
# com = Xgrad - rgradX
# print(r'%\bm{X}\cdot \nabla - \bar{\nabla}\cdot \bm{X} =', com)
sph_coords = (r, th, phi) = symbols('r theta phi', real=True)
(sp3d, er, eth, ephi) = Ga.build('e', g=[1, r**2, r**2 * sin(th)**2],
coords=sph_coords, norm=True)
f = sp3d.mv('f', 'scalar', f=True)
lap = sp3d.grad * sp3d.grad
print(r'%\nabla^{2} = \nabla\cdot\nabla =', lap)
print(r'%\lp\nabla^{2}\rp f =', lap * f)
print(r'%\nabla\cdot\lp\nabla f\rp =', sp3d.grad | (sp3d.grad * f))
# FIXME crop didn't work, but pdf can be generated with TexLive 2017 installed
xpdf(paper='landscape', crop=True)
Loading