sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.44k stars 480 forks source link

Immutability of chart functions #30310

Closed mjungmath closed 3 years ago

mjungmath commented 4 years ago

Immutability of chart functions, see #30261.

Depends on #31181 Depends on #31182

CC: @egourgoulhon @tscrim @mkoeppe

Component: manifolds

Keywords: immutability

Author: Michael Jung

Branch/Commit: e855ebc

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/30310

mjungmath commented 4 years ago

Branch: u/gh-mjungmath/immutability_of_chart_functions

mjungmath commented 4 years ago

Description changed:

--- 
+++ 
@@ -1 +1 @@
-
+Immutability of chart functions, see #30261.
mjungmath commented 4 years ago

Author: Michael Jung

mjungmath commented 4 years ago

New commits:

286d3c6FreeModuleTensor, Vector: Subclass a new class ModuleElementWithMutability
9df3d22sage.tensor.modules: Make all zero() and one() elements immutable
4373ea2FreeModuleTensor: Replace special casing of the immutable zero by is_immutable
a2ee8beModuleElementWithMutability.is_immutable, is_mutable: Change def to cpdef
8600c2dMerge branch 't/30181/immutable_elements_of_freemoduletensor' into t/30310/immutability_of_chart_functions
76229bdTrac #30310: immutability of chart functions
mjungmath commented 4 years ago

Commit: 76229bd

mjungmath commented 4 years ago

Changed keywords from none to immutability

mjungmath commented 4 years ago

Dependencies: #30181

egourgoulhon commented 4 years ago
comment:4

Why is #30181 a dependency of this ticket? A priori chart functions are totally independent from tensor fields. They even exist on pure topological manifolds.

mjungmath commented 4 years ago
comment:5

It is because of

-from sage.structure.element import AlgebraElement
+from sage.structure.element import AlgebraElement, ModuleElementWithMutability
...
-class ChartFunction(AlgebraElement):
+class ChartFunction(AlgebraElement, ModuleElementWithMutability):
mjungmath commented 4 years ago
comment:6

ModuleElementWithMutability is first introduced in #30181.

tscrim commented 4 years ago
comment:7

I feel like the MultiCoordFunction should inherit from Mutability rather than copy the same code.

mjungmath commented 4 years ago
comment:8

It'd be the same issue like we had for affine connections (#30280): __reduce__ (#30281).

tscrim commented 4 years ago
comment:9

I know, but as a stop-gap, you could instead implement a __reduce__. I don't really like this duplication. Hopefully this week I can get around to properly doing #30281...

egourgoulhon commented 4 years ago
comment:10

Replying to @mjungmath:

It is because of

-from sage.structure.element import AlgebraElement
+from sage.structure.element import AlgebraElement, ModuleElementWithMutability
...
-class ChartFunction(AlgebraElement):
+class ChartFunction(AlgebraElement, ModuleElementWithMutability):

Ah yes, thanks.

mjungmath commented 3 years ago
comment:12

I tried to remove the redundant code and inherit from Mutability after #30281. For some reason, I still get a pickling error during doctest.

Furthermore, the code seems broken: is_immutable does not return anything:

    def is_immutable(self):
        """
        ...
        """
        self._is_immutable

When did that happen?

mjungmath commented 3 years ago
comment:14

I opened a ticket for the missing return: #31181.

Furthermore, I've opened a ticket for the still remaining pickling test error: #31182.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 3 years ago

Changed commit from 76229bd to 09086cf

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 3 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

09086cfTrac #30310: inherit from Mutability
mjungmath commented 3 years ago

Changed dependencies from #30181 to #31181, #31182

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 3 years ago

Changed commit from 09086cf to 6c76b66

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 3 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

6c76b66Trac #30310: AssertionError -> ValueError
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 3 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

7247620Merge branch 'develop' into t/30310/immutability_of_chart_functions
5ecbf3aTrac #31181: return added
8b20fc4Merge branch 't/31181/mutability_class_does_not_return_is_immutable' into t/30310/immutability_of_chart_functions
4c33935Trac #31196: minor code improvements, py3 compatibility, documentation improved
e5228d3Trac #31196: cpdef require methods + example added
d957f73Trac #31196: unnecessary line in docstring removed
d6d6ba4Trac #31182: `__getstate__` and __setstate__
6cbd1fdTrac #31182: doctests added for `__setstate__` and __getstate__
848e96bMerge branch 't/31182/mutability_class_and_pickling' into t/30310/immutability_of_chart_functions
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 3 years ago

Changed commit from 6c76b66 to 848e96b

mjungmath commented 3 years ago
comment:19

Green patchbot.

tscrim commented 3 years ago
comment:20

I think you are better off explicitly calling

ModuleElementWithMutability.__init__(self, parent)
mjungmath commented 3 years ago
comment:21

Yes thanks, this should be better.

mjungmath commented 3 years ago
comment:22

Pushed.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 3 years ago

Changed commit from 848e96b to e855ebc

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 3 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

e855ebcTrac #30310: init ModuleElementWithMutability directly
tscrim commented 3 years ago

Reviewer: Travis Scrimshaw

tscrim commented 3 years ago
comment:24

Green bot => positive review.

mjungmath commented 3 years ago
comment:26

Thank you.

vbraun commented 3 years ago

Changed branch from u/gh-mjungmath/immutability_of_chart_functions to e855ebc