-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Refactor Components into parent & element #30307
Comments
comment:2
Help with implementing this would be very welcome! |
comment:3
That's a nice idea, +1!
I think it would be a good idea to cache results from The most annoying thing with this ticket will most likely be the docstring that has to be adapted...is there a good way to use search&replace? |
comment:4
Currently, the index generators and manipulators take (mostly) lists and can therefore not be cached. To use the caching most efficiently, I suggest we switch entirely to tuples. |
Branch: public/30307 |
Commit: |
comment:7
Before I go on with this ticket, could you please take a look whether this meets your rough idea? Is anyone willing to work on the docstrings...? Perhaps there's an efficient way to do this? |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:9
Replying to @mjungmath:
Yes, this is going in the direction that I had in mind. Some more of the normalization happening in |
comment:10
What would be a proper category for the parent? |
comment:11
Replying to @mkoeppe:
For example? |
comment:12
For example the order of the component indices does not matter |
comment:13
Replying to @mjungmath:
Take the following with a grain of salt (this is just a rough/naive thought): It seems to me that the current proposal is a kind of abuse of Sage's parent/element scheme, for |
comment:14
Just use the category of sets. I don't think this is an abuse. Think of an instance of By using the parent/element framework, you will get coercion for free - so elements with a coarser symmetry will be |
comment:15
Replying to @mkoeppe:
Right! Replying to @mkoeppe:
For me, it doesn't feel like an abuse either. Besides, I am sure you can make that notion of compontents mathematically rigorous. But I am not sure whether this becomes a well-defined set then... What about the category of objects? |
comment:16
Alright, I make progress here. I changed only the backend such that most doctests should still pass, and the module can be used exactly as before. The elementary examples already passed. I'll push my branch tomorrow. I am looking forward to some benchmarks as soon as this branch is ready. :) |
comment:17
I can understand why this might seem like an abuse because it is a set of objects, but by extension, all of the combinatorial objects would be an abuse as well. So even though we will not be putting an extra mathematical structure on the components, this is still a valid use of the framework because there is a set of objects (the parent) and the individual objects (the elements). Something to consider, however, is a potential speed penalty for the extra levels of initialization. This can be somewhat mitigated by using Cython, but performance regression testing is warranted here. |
comment:18
Replying to @tscrim:
How so? |
comment:19
Replying to @mjungmath:
Because Cython is faster than Python, including potential benefits from direct C-level function calls. |
comment:20
Yes, that's clear. I meant, how to implement? Make Would Since this involves only integers, i.e. struct types, one could even try to Cythonize these completely. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:22
Replying to @tscrim:
Thank you Matthias, Michael and Travis for your replies. I'm convinced now that parent/element is a good approach here (I was bothered by the lack of algebraic structure of the parent), especially for symmetry-based coercions.
Certainly! New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:91
There are still various errors in
Help in spotting where these errors are coming from would be welcome |
comment:92
For some reason, the
But it should return
|
comment:93
Okay, I spotted the error. It's caused by these lines: + self._sym = tuple(self._sym)
+ self._antisym = tuple(self._antisym) When a tensor field is displayed, it must be restricted to a parallelizable subset first. If that restriction does not exists, it's constructed from scratch. This is done by the elif tensor_type[0] > 1 and tensor_type[1] == 0 and antisym:
if isinstance(antisym[0], (int, Integer)):
# a single antisymmetry is provided as a tuple or a
# range object; it is converted to a 1-item list:
antisym = [tuple(antisym)]
if isinstance(antisym, list):
antisym0 = antisym[0]
else:
antisym0 = antisym
if len(antisym0) == tensor_type[0]:
return self.alternating_contravariant_tensor(
tensor_type[0], name=name,
latex_name=latex_name) With the above change, however, |
comment:94
One way to solve this could be to adapt the preprocessing of |
comment:95
Thanks for spotting this! |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:97
With these changes, only failures that look like this remain:
|
comment:98
This is likely not the final form of this ticket. The goals of this ticket -- one-time precomputation of data related to the symmetries -- have not been fully achieved yet because the parent class is now a module over a base ring. This is fine for numerical tensors that are all over the same ring ( But for now it was more important to me to have separate parents for separate base rings, as this will allow us to dispatch to different implementation backends (= element classes) - as part of @honglizhaobob's project (#31991). My solution for allowing more shared precomputation would be to introduce another class, similar to https://docs.sympy.org/latest/modules/tensor/tensor.html#sympy.tensor.tensor.TensorSymmetry, which only captures the symmetry group (with action). Apart from this, there is still some code that should be pushed from element to parent, for example the symmetries from tensor contraction. And there are branches in the code that can no longer be reached because the coercion system, via Also, I have not done any time measurements. |
This comment has been minimized.
This comment has been minimized.
comment:100
Further refactoring will go through #32029 (Action of a sympy |
comment:101
Looks good so far! What about the idea with the morphisms in comment:28? |
comment:102
Replying to @mjungmath:
The next step into this direction should be to fix/complete the existing code for coercions.
Help with this is welcome! |
comment:107
Restarting this effort with a smaller step in #34497. |
Currently every
Components
object has lots of metadata attributes in addition to the actual data dictionary in._comp
.If one has many different
Components
objects with the same symmetry metadata, we can reduce storage space as follows.We create new classes
CompParent
,CompParentWithSym
, ..., whichstore the symmetry attributes and become
UniqueRepresentation
. We makeComponents
objects elements of these parents.The parents will also have index iterator methods.
Data associated with symmetries and dimensions, computed currently each time for each
CompWithSym
object in methods such as__init__
,__add__
,trace
, ... can be precomputed and cached in the parent using@cached_method
in the parent class).This will make the code in #30229 (subspaces of tensor with symmetries) more elegant because it no longer needs a dummy
Components
object to represent the symmetry but rather aCompParent
object.See also:
TensorSymmetry
Depends on #31904
Depends on #29619
CC: @mjungmath @egourgoulhon @tscrim @honglizhaobob
Component: linear algebra
Author: Michael Jung, Matthias Koeppe
Branch/Commit: public/30307 @
e5a81f2
Issue created by migration from https://trac.sagemath.org/ticket/30307
The text was updated successfully, but these errors were encountered: