Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 30a5d0b

Browse files
author
Matthias Koeppe
committed
Chart: WIP getstate/setstate, no UniqueRepresentation
1 parent d7f9d17 commit 30a5d0b

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

src/sage/manifolds/chart.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@
4343
from sage.rings.infinity import Infinity
4444
from sage.misc.latex import latex
4545
from sage.misc.decorators import options
46+
from sage.misc.cachefunc import cached_method
47+
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
4648
from sage.manifolds.chart_func import ChartFunctionRing
4749
from sage.manifolds.calculus_method import CalculusMethod
4850
from sage.symbolic.expression import Expression
4951
from sage.ext.fast_callable import fast_callable
5052

5153

52-
class Chart(UniqueRepresentation, SageObject):
54+
class Chart(SageObject, metaclass=InheritComparisonClasscallMetaclass):
5355
r"""
5456
Chart on a topological manifold.
5557
@@ -288,8 +290,8 @@ def __classcall__(cls, domain, coordinates='',
288290
try:
289291
return domain._charts_by_coord[coord_string]
290292
except KeyError:
291-
self = super().__classcall__(cls, domain, coordinates,
292-
calc_method, **coordinate_options)
293+
self = type.__call__(cls, domain, coordinates,
294+
calc_method, **coordinate_options)
293295
domain._charts_by_coord[coord_string] = self
294296
return self
295297

@@ -441,6 +443,50 @@ def _parse_coordinates(cls, domain, coordinates):
441443
period_list.append(period)
442444
return tuple(xx_list), dict(periods=tuple(period_list))
443445

446+
def __hash__(self):
447+
try:
448+
return self._hash
449+
except AttributeError:
450+
# Do not hash the domain because it owns self
451+
# Do not hash sheafy attributes: _subcharts, _supercharts, _dom_restrict
452+
self._hash = hash((self._domain._name, self._sindex,
453+
## _calc_method is not hashable
454+
#self._calc_method,
455+
self._xx,
456+
tuple(self._periods.items()),
457+
repr(self._restrictions), # hash the string of the unhashable
458+
))
459+
return self._hash
460+
461+
def _non_sheafy_attributes(self):
462+
for key, value in self.__dict__.items():
463+
if key not in ('_subcharts', '_supercharts', '_dom_restrict',
464+
# also ignore these ones
465+
'_calc_method', 'simplify'):
466+
yield key, value
467+
468+
def __eq__(self, other):
469+
if self is other:
470+
return True
471+
if type(self) != type(other):
472+
return False
473+
if self._xx != other._xx:
474+
return False
475+
return dict(self._non_sheafy_attributes()) == dict(other._non_sheafy_attributes())
476+
477+
def __ne__(self, other):
478+
return not (self == other)
479+
480+
def __setstate__(self, d):
481+
self.__dict__.update(d)
482+
# Following is shared with __init__; could also go in a __new__ method
483+
self._subcharts = set([self])
484+
self._supercharts = set([self])
485+
486+
487+
def __getstate__(self):
488+
return dict(self._non_sheafy_attributes())
489+
444490
def _repr_(self):
445491
r"""
446492
String representation of the object.
@@ -1072,6 +1118,7 @@ def transition_map(self, other, transformations, intersection_name=None,
10721118
transformations = [transformations]
10731119
return CoordChange(chart1, chart2, *transformations)
10741120

1121+
@cached_method(key=id)
10751122
def function_ring(self):
10761123
"""
10771124
Return the ring of coordinate functions on ``self``.

src/sage/manifolds/chart_func.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
from sage.structure.element import AlgebraElement, ModuleElementWithMutability
3737
from sage.structure.parent import Parent
3838
from sage.structure.sage_object import SageObject
39-
from sage.structure.unique_representation import UniqueRepresentation
4039
from sage.categories.commutative_algebras import CommutativeAlgebras
4140
from sage.manifolds.utilities import ExpressionNice
4241
from sage.misc.cachefunc import cached_method
@@ -2641,7 +2640,7 @@ def collect_common_factors(self):
26412640
self._del_derived()
26422641
return self
26432642

2644-
class ChartFunctionRing(Parent, UniqueRepresentation):
2643+
class ChartFunctionRing(Parent):
26452644
"""
26462645
Ring of all chart functions on a chart.
26472646

src/sage/manifolds/differentiable/chart.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,22 @@ def __init__(self, domain, coordinates, calc_method=None, periods=None):
282282
self._frame = CoordFrame(self)
283283
self._coframe = self._frame._coframe
284284

285+
def __getstate__(self):
286+
d = super().__getstate__().copy()
287+
# These are keyed to self via UniqueRepresentation
288+
try:
289+
del d['_frame']
290+
except KeyError:
291+
pass
292+
del d['_coframe']
293+
return d
294+
295+
def __setstate__(self, d):
296+
super().__setstate__(d)
297+
# Reconstruct the coordinate frame associated to the chart:
298+
self._frame = CoordFrame(self)
299+
self._coframe = self._frame._coframe
300+
285301
def transition_map(self, other, transformations, intersection_name=None,
286302
restrictions1=None, restrictions2=None):
287303
r"""
@@ -1189,7 +1205,7 @@ def jacobian(self):
11891205
"""
11901206
return self._jacobian # has been computed in __init__
11911207

1192-
@cached_method
1208+
@cached_method(key=id, do_pickle=True)
11931209
def jacobian_det(self):
11941210
r"""
11951211
Return the Jacobian determinant of ``self``.

src/sage/manifolds/scalarfield_algebra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from sage.symbolic.ring import SR
4040
from sage.manifolds.scalarfield import ScalarField
4141

42-
class ScalarFieldAlgebra(UniqueRepresentation, Parent):
42+
class ScalarFieldAlgebra(Parent):
4343
r"""
4444
Commutative algebra of scalar fields on a topological manifold.
4545

0 commit comments

Comments
 (0)