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

Chart: Add init argument coord_restrictions, deprecate method add_restrictions #32102

Closed
mkoeppe opened this issue Jul 2, 2021 · 59 comments
Closed

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented Jul 2, 2021

(from #31901 comment:22)

This will remove the appearance of mutability of Charts.

Deprecated chart declaration:

            sage: M = Manifold(2, 'M', structure='topological')

            sage: X.<x,y> = M.chart()
            sage: X.add_restrictions(x^2+y^2<1)
            sage: X.add_restrictions(x>0)

Replacement 1 (implemented):

    sage: var("x y")
    sage: X.<x,y> = M.chart(coord_restrictions=[x^2+y^2<1, x>0])

Replacement 2:

    sage: x, y = M.var()
    sage: X.<x,y> = M.chart(coord_restrictions=[x^2+y^2<1, x>0])

(x, y defined in the first line would be some temporary placeholder variables.)

Replacement 3 (implemented):

    sage: in_disk(x,y) = x^2+y^2<1
    sage: on_right(x,y) = x>0
    sage: X.<x,y> = M.chart(coord_restrictions=[in_disk, on_right])

Replacement 4:

   sage: X.<x,y> = M.chart(coord_restrictions=[lambda x,y: x^2+y^2<1, lambda x,y: x>0])

(chart initialization calls the lambdas on the symbolic variables x, y to get the symbolic relations)

Replacement 5 (implemented):

   sage: X.<x,y> = M.chart(coord_restrictions=lambda x,y: [x^2+y^2<1, x>0])

(chart initialization calls the lambda on the symbolic variables x, y to get the list of symbolic relations)

Depends on #32116
Depends on #32009

CC: @egourgoulhon @mjungmath @tscrim @vbraun

Component: manifolds

Author: Matthias Koeppe

Branch/Commit: u/mkoeppe/chart__add_init_argument_coord_restrictions__deprecate_method_add_restrictions @ c218828

Reviewer: Eric Gourgoulhon

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

@mkoeppe mkoeppe added this to the sage-9.4 milestone Jul 2, 2021
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

Dependencies: #32089

@mkoeppe

This comment has been minimized.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

Changed dependencies from #32089 to #32089, #32103

@egourgoulhon
Copy link
Member

comment:4

I like very much replacements 4 and 5. Using lambda function is a good idea! Why is this not immediately applicable? i.e. why #32089 and #32103 have been set as dependencies?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

comment:5

OK, converting a lambda to a callable symbolic expression is in #32103, but I guess for this ticket one could just call the lambda on the chart variables, so it's not really needed.

I was expecting trouble with UniqueRepresentation because the mixture of lists and tuples in your format of coordinate restrictions is not hashable. My suggestion was to convert this to a ConditionSet (#32089); but I suppose simpler solutions are possible too

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

comment:6

The lambda in the init args will unfortunately also create trouble with the pickling tests - lambdas cannot be pickled. So it will have to be transformed to the list/tuple format already in the __classcall__ method - triggering the trouble with UniqueRepresentation...

So we can either go through #32089, or get rid of UniqueRepresentation for Charts.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

Commit: d9520ae

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

comment:8

In the branch of #31894 I have a change from def _init_coordinates to @classmethod def _parse_coordinates that would be useful to implement __classcall__.


New commits:

d9520aeChart: Add coord_restrictions init arg

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

comment:9

Replying to @mkoeppe:

In the branch of #31894 I have a change from def _init_coordinates to @classmethod def _parse_coordinates that would be useful to implement __classcall__.

That's now on #32116.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

Changed dependencies from #32089, #32103 to #32116, #32089, #32103

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

Changed commit from d9520ae to ce76586

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

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

8ba174cEliminate direct use of Chart._domain
21297f3Merge #32009
deace83Chart: Replace _init_coordinates by _parse_coordinates
4db4995Chart: Fix up `__classcall__` and _parse_coordinates by avoiding unhashable things
fc59c9dChart.__classcall__: Add doctest
ce76586Merge #32116

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

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

c31fb4bChart: Make coord restrictions hashable by using frozenset in place of list

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

Changed commit from ce76586 to c31fb4b

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

Changed dependencies from #32116, #32089, #32103 to #32116, #32103

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

comment:13

Replying to @mkoeppe:

I was expecting trouble with UniqueRepresentation because the mixture of lists and tuples in your format of coordinate restrictions is not hashable. My suggestion was to convert this to a ConditionSet (#32089); but I suppose simpler solutions are possible too

I have implemented a simpler solution

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

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

91c4c98TopologicalManifold.chart: Add keyword arg coord_restrictions
30bc60dChart: Handle lambda-quoted coord_restrictions

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

Changed commit from c31fb4b to 30bc60d

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

comment:15

Replacements 1, 2, 3, and 5 should work now. For simplicity, let's skip 4.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 3, 2021

Changed dependencies from #32116, #32103 to #32116

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

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

b5820a9Remove most uses of Chart.add_restrictions in doctests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

Changed commit from 30bc60d to b5820a9

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

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

1e48230RealChart._tighten_bounds: Factor out from RealChart.add_restrictions, call it from `__init__` too

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

Changed commit from b5820a9 to 1e48230

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2021

Changed commit from 1e48230 to 939dcd5

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 8, 2021

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

f85e710Chart: in the description of the argument coord_restrictions, replace all instances of 'restrictions' by 'coord_restrictions'
80f6195Chart, RealChart: In class docstring, order arguments as they appear in __classcall__/__init__
a39e6fcDiffChart, RealDiffChart: In class docstring, order arguments as they appear in __classcall__/__init__; add description of argument coord_restrictions

@egourgoulhon
Copy link
Member

comment:30

Replying to @mkoeppe:

Replying to @egourgoulhon:

  1. In the INPUT section of the docstring of class Chart:
  • the argument coordinates is described as having a default value, which is no longer true
    [...]
  • the argument names should removed

Actually, coordinates and names still have the same behavior as before -- it is implemented by __classcall__

Yes I understand this; the question is rather about the consistency of the INPUT field with the class declaration as it appears in the reference manual:

class sage.manifolds.chart.Chart(domain, coordinates, calc_method, periods=None,
coord_restrictions=None)

This is because Sphinx constructs the above from the __init__ method, not taking into account __classcall__. If one looks at the html output of the reference manual, the INPUT field arrives just after the class declaration. But I agree with you that this does not reflect the way the class should be invoked. I don't know what is the policy here. Possibly, this issue appears in other parts of Sage as well.


New commits:

f85e710Chart: in the description of the argument coord_restrictions, replace all instances of 'restrictions' by 'coord_restrictions'
80f6195Chart, RealChart: In class docstring, order arguments as they appear in __classcall__/__init__
a39e6fcDiffChart, RealDiffChart: In class docstring, order arguments as they appear in __classcall__/__init__; add description of argument coord_restrictions

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 8, 2021

Changed commit from a39e6fc to cdf20b0

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 8, 2021

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

cdf20b0TopologicalManifold.chart: Add description of argument coord_restrictions

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 8, 2021

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

741fd2eTopologicalManifold.chart: Add an example of using coord_restrictions

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 8, 2021

Changed commit from cdf20b0 to 741fd2e

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 8, 2021

comment:33

Replying to @egourgoulhon:

Replying to @mkoeppe:

Replying to @egourgoulhon:

  1. In the INPUT section of the docstring of class Chart:
  • the argument coordinates is described as having a default value, which is no longer true
    [...]
  • the argument names should removed

Actually, coordinates and names still have the same behavior as before -- it is implemented by __classcall__

Yes I understand this; the question is rather about the consistency of the INPUT field with the class declaration as it appears in the reference manual:

class sage.manifolds.chart.Chart(domain, coordinates, calc_method, periods=None,
coord_restrictions=None)

This is because Sphinx constructs the above from the __init__ method, not taking into account __classcall__. If one looks at the html output of the reference manual, the INPUT field arrives just after the class declaration. But I agree with you that this does not reflect the way the class should be invoked. I don't know what is the policy here. Possibly, this issue appears in other parts of Sage as well.

Great point; I have opened #32163 for this general issue.

@egourgoulhon
Copy link
Member

comment:34

Replying to @mkoeppe:

Great point; I have opened #32163 for this general issue.

OK thanks. Meanwhile, let us leave things as they are, i.e. have the INPUT section of Chart and RealChart docstrings describe __classcall__.

@egourgoulhon
Copy link
Member

Reviewer: Eric Gourgoulhon

@egourgoulhon
Copy link
Member

comment:35

Thanks for this improvement!

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 9, 2021

comment:36

Thanks for reviewing!

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 12, 2021

Changed commit from 741fd2e to 141ccb5

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 12, 2021

Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. Last 10 new commits:

0f60232ConditionSet: Do not sort the conditions, just use _stable_uniq
69d045aConditionSet: In doctests, do not rename ZZ^2 etc.
daeb91esrc/sage/sets/set.py: Fix docstring markup
2cf2199Merge #32015
1eb270asrc/sage/docs/conf.py: Add more \ensuremath to \DeclareUnicodeCharacter
2682469src/sage/interfaces/sympy_wrapper.py: Use Family, not Set, in doctests to make sure that the SageSet wrapper is actually used
753babbSet_object_enumerated._sympy_: Translate empty sets to EmptySet
141ecdeMerge #32015
bf62543Merge branch 't/32089/conditionset__conditionset_callable_symbolic_expression' into t/32009/eliminate_direct_use_of_the_chart__domain_attribute
141ccb5Merge #32009

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 12, 2021

comment:38

Merged updated #32009

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 19, 2021

Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. New commits:

ea08261Merge #32009
3d1c44dMerge tag '9.4.beta5' into t/32116/chart__parse_coordinates
c218828Merge #32116

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 19, 2021

Changed commit from 141ccb5 to c218828

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 24, 2021

comment:41

Apparently this has been merged as part of #32089.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants