Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diff and pdiff method of class Mv throws exception when differentiate by a coordinate symbol #513

Closed
mammalwong opened this issue Apr 23, 2024 · 4 comments
Assignees
Labels
bug component: differential operators Dop, Pdop, Sdop, grad, rgrad, etc
Milestone

Comments

@mammalwong
Copy link

mammalwong commented Apr 23, 2024

x is a coordinate symbol (a plain sympy Symbol object) and ex is a Mv instance of a Ga basis symbol. I tried to invoke (x*ex).diff(x) and the method throws exception. From the exception stack frame below, it looks like Mv.diff passed self.obj to Ga.pDiff and pDiff try to resolve .obj again from obj.


AttributeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 (x*ex).diff(x)

1 frames
/usr/local/lib/python3.10/dist-packages/galgebra/mv.py in diff(self, coord)
1070 obj += tmp1 * tmp2
1071 else:
-> 1072 obj = self.Ga.pDiff(self.obj, coord)
1073 return Mv(obj, ga=self.Ga)
1074

/usr/local/lib/python3.10/dist-packages/galgebra/ga.py in pDiff(self, A, coord)
2050 # variable, but including case of non-constant basis vectors
2051
-> 2052 dA = self.mv(expand(diff(A.obj, coord)))
2053
2054 if self.connect_flg and self.dslot == -1 and not A.is_scalar(): # Basis blades are function of coordinates

AttributeError: 'Mul' object has no attribute 'obj'

@mammalwong mammalwong changed the title diff method of class Mv throws exception when differentiate to a coordinate symbol diff method of class Mv throws exception when differentiate by a coordinate symbol Apr 23, 2024
@mammalwong mammalwong changed the title diff method of class Mv throws exception when differentiate by a coordinate symbol diff and pdiff method of class Mv throws exception when differentiate by a coordinate symbol Apr 24, 2024
@mammalwong
Copy link
Author

pdiff method of Mv class also throws the same exception when invoking (x*ex).pdiff(x).


AttributeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 (x*ex).pdiff(x)

1 frames
/usr/local/lib/python3.10/dist-packages/galgebra/ga.py in pDiff(self, A, coord)
2050 # variable, but including case of non-constant basis vectors
2051
-> 2052 dA = self.mv(expand(diff(A.obj, coord)))
2053
2054 if self.connect_flg and self.dslot == -1 and not A.is_scalar(): # Basis blades are function of coordinates

AttributeError: 'Mul' object has no attribute 'obj'

@utensil utensil added the bug label May 9, 2024
@utensil utensil added this to the 0.5.3 milestone May 9, 2024
@utensil
Copy link
Member

utensil commented May 9, 2024

@mammalwong Can you also post minimal working example for this issue? Thanks!

@mammalwong
Copy link
Author

mammalwong commented May 9, 2024

In version 0.5.1

x,y,z = coords = S.symbols('x y z', real=True)
ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)
ex,ey,ez = ga.mv()
(x*ex).diff(x)

raise exception:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-9-4979ad157f80>](https://localhost:8080/#) in <cell line: 4>()
      2 ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)
      3 ex,ey,ez = ga.mv()
----> 4 (x*ex).diff(x)

1 frames
[/usr/local/lib/python3.10/dist-packages/galgebra/mv.py](https://localhost:8080/#) in diff(self, coord)
   1070                         obj += tmp1 * tmp2
   1071         else:
-> 1072             obj = self.Ga.pDiff(self.obj, coord)
   1073         return Mv(obj, ga=self.Ga)
   1074 

[/usr/local/lib/python3.10/dist-packages/galgebra/ga.py](https://localhost:8080/#) in pDiff(self, A, coord)
   2050         # variable, but including case of non-constant basis vectors
   2051 
-> 2052         dA = self.mv(expand(diff(A.obj, coord)))
   2053 
   2054         if self.connect_flg and self.dslot == -1 and not A.is_scalar():  # Basis blades are function of coordinates

AttributeError: 'Mul' object has no attribute 'obj'

Another related issue:

x,y,z = coords = S.symbols('x y z', real=True)
ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)
ex,ey,ez = ga.mv()
(x*ex).pdiff(x) # notice this is pdiff() not diff() this time

raise exception:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-10-5767979f98eb>](https://localhost:8080/#) in <cell line: 4>()
      2 ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)
      3 ex,ey,ez = ga.mv()
----> 4 (x*ex).pdiff(x)

1 frames
[/usr/local/lib/python3.10/dist-packages/galgebra/mv.py](https://localhost:8080/#) in pdiff(self, var)
   1074 
   1075     def pdiff(self, var) -> 'Mv':
-> 1076         return Mv(self.Ga.pDiff(self.obj, var), ga=self.Ga)
   1077 
   1078     def Grad(self, coords, mode: str = '*', left: bool = True) -> 'Mv':

[/usr/local/lib/python3.10/dist-packages/galgebra/ga.py](https://localhost:8080/#) in pDiff(self, A, coord)
   2050         # variable, but including case of non-constant basis vectors
   2051 
-> 2052         dA = self.mv(expand(diff(A.obj, coord)))
   2053 
   2054         if self.connect_flg and self.dslot == -1 and not A.is_scalar():  # Basis blades are function of coordinates

AttributeError: 'Mul' object has no attribute 'obj'

utensil added a commit that referenced this issue May 10, 2024
@utensil utensil added the component: differential operators Dop, Pdop, Sdop, grad, rgrad, etc label May 10, 2024
@utensil utensil self-assigned this May 10, 2024
utensil added a commit that referenced this issue May 10, 2024
@utensil
Copy link
Member

utensil commented May 15, 2024

Thank you, @mammalwong , the fix should be in master now as #510 is now merged.

@utensil utensil closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug component: differential operators Dop, Pdop, Sdop, grad, rgrad, etc
Projects
None yet
Development

No branches or pull requests

2 participants