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

sage.{modular,schemes}: Modularization fixes for imports; update sage -fiximports, add relint pattern #35884

Merged
merged 26 commits into from
Aug 13, 2023

Conversation

mkoeppe
Copy link
Contributor

@mkoeppe mkoeppe commented Jul 2, 2023

📚 Description

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

⌛ Dependencies

@mkoeppe mkoeppe self-assigned this Jul 2, 2023
@mkoeppe mkoeppe changed the title sage.modular: Modularization fixes for imports; update sage -fiximports, add relint pattern sage.{modular,schemes}: Modularization fixes for imports; update sage -fiximports, add relint pattern Jul 2, 2023
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 21, 2023

The Linter failure is unrelated and fixed in #35974

@mkoeppe mkoeppe requested a review from kwankyu July 21, 2023 20:35
@@ -61,7 +61,7 @@
# https://www.gnu.org/licenses/
######################################################################

import sage.matrix.all as matrix
from sage.matrix.constructor import Matrix as matrix
import sage.schemes.hyperelliptic_curves.monsky_washnitzer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just from sage.matrix.constructor import matrix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done (in all places)

from sage.rings.padics.precision_error import PrecisionError
from sage.rings.power_series_ring import PowerSeriesRing
from sage.rings.rational_field import QQ
from sage.structure.sage_object import SageObject

lazy_import('sage.rings.padics.factory', 'Qp', as_='pAdicField')

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only this is lazy-imported while PrecisionError from sage.rings.padics.precision_error is just imported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sage.rings.padics.precision_error is shipped by sagemath-categories

One cannot do try: ... except ... with a LazyImport

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 22, 2023

I think each file should be annotated with the distribution which the file belongs to (is installed by). Do we already have a standard style for the annotation?

Yes, that's # sage_setup: distribution = sagemath-bliss, which is currently only used for the few modules depending on optional packages. #35663 is adding many more such directives.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 22, 2023

For file.py, the annotated distribution would be used as xxx in sage -t --distribution=xxx file.py. Right?

Yes, that's for sure one of the tests to run, but sometimes one also may want to test with extras added to enable more tests.

I think that the future incremental test workflow should run sage -t --distribution=xxx file.py for each modified file.py.

Right.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 22, 2023

As more files of the sage library get included to newly born distributions, the work practice of a sage developer should change much, albeit there has been little change in the practice up to now. A developer would modify a file such that the file does not break in the distribution it belongs to. If doctests that need other distributions are added, then he needs to test the doctests in another sage install where the additional distributions are available as well.

If the above is right, perhaps we should also update the developer manual to reflect the changing work practice.

Yes, that's a great point. While #35749 is adding a detailed description of how to test in a modularized setting, something has yet to be added to the tutorials that describe the development workflow.

In the worst, a developer would feel like that he/she is expelled from their paradise (where one can import anything from anywhere), after they were scared by the huge flood of optional tags to doctests.

There is certainly a potential for developer frustration after we make failures of the modularized distributions hard errors. This is something to watch out for and mitigate.

@kwankyu
Copy link
Collaborator

kwankyu commented Jul 22, 2023

I think each file should be annotated with the distribution which the file belongs to (is installed by). Do we already have a standard style for the annotation?

Yes, that's # sage_setup: distribution = sagemath-bliss, which is currently only used for the few modules depending on optional packages. #35663 is adding many more such directives.

Certainly adding those annotations is a huge task and error-prone, and it is good that there is a one source of truth. That one source of truth should be MANIFEST.in.

Hence it would be nice that we can add the annotations automatically from the manifest files, perhaps as part of the bootstrap. I asked chatGPT how to do that. It answered

python setup.py sdist --manifest-only

But this does not work with me. Its second answer is

python setup.py check --metadata --restructuredtext --strict && python setup.py sdist --formats=zip,gztar

This seems to work. I ran the command in pkgs/sagemath-objects, and got the file pkgs/sagemath-objects/sagemath_objects.egg-info/SOURCES.txt, which list the included files. We may use this file to add the annotations automatically.

Does this make sense?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 22, 2023

that's # sage_setup: distribution = sagemath-bliss, which is currently only used for the few modules depending on optional packages. #35663 is adding many more such directives.

Certainly adding those annotations is a huge task and error-prone, and it is good that there is a one source of truth. That one source of truth should be MANIFEST.in.

Right now, this is true to some extent, but it's a bit more complicated actually. Some of the setup.py files also do source filtering using the # sage_setup: distribution directives, in addition to the filtering that MANIFEST does.

I'm hoping to unify and simplify this soon; not sure if I really want to keep the MANIFEST mechanism.
Using the # sage_setup: distribution directives as the one source of truth would have the benefit that distributions are guaranteed to be disjoint.

Hence it would be nice that we can add the annotations automatically from the manifest files, perhaps as part of the bootstrap.

This can't be part of the bootstrap because it would need to modify source files that are under version control.

But it would be indeed be very useful as a developer tool when making changes to the contents of the distributions. I'm currently doing this with very primitive tools.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 22, 2023

I ran the command in pkgs/sagemath-objects, and got the file pkgs/sagemath-objects/sagemath_objects.egg-info/SOURCES.txt, which list the included files. We may use this file to add the annotations automatically.

A better command is ./sage -sh -c '(cd pkgs/sagemath-objects && python3 setup.py egg_info)'

@kwankyu
Copy link
Collaborator

kwankyu commented Jul 23, 2023

Certainly adding those annotations is a huge task and error-prone, and it is good that there is a one source of truth. That one source of truth should be MANIFEST.in.

Right now, this is true to some extent, but it's a bit more complicated actually. Some of the setup.py files also do source filtering using the # sage_setup: distribution directives, in addition to the filtering that MANIFEST does.

I'm hoping to unify and simplify this soon; not sure if I really want to keep the MANIFEST mechanism. Using the # sage_setup: distribution directives as the one source of truth would have the benefit that distributions are guaranteed to be disjoint.

We may use MANIFEST (or something renamed) as a tool to mass-add the file annotations, but use the file annotations as the one source of truth.

From developer's point of view, I think both mechanisms would be useful.


import sage.rings.all
from sage.modules.free_module import FreeModule, is_FreeModule
from sage.rings.integer import Integer

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we get rid of is_FreeModule on the way?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps not in this PR...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, separate PR

@kwankyu
Copy link
Collaborator

kwankyu commented Jul 23, 2023

Please soothe the linter. Otherwise, looks good to me.

Copy link
Collaborator

@kwankyu kwankyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 23, 2023

Thank you!

@vbraun
Copy link
Member

vbraun commented Jul 26, 2023

**********************************************************************
File "src/sage/schemes/elliptic_curves/hom.py", line 1163, in sage.schemes.elliptic_curves.hom.compute_trace_generic
Failed example:
    compute_trace_generic(-m7)
Exception raised:
    Traceback (most recent call last):
      File "/home/release/Sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/release/Sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.schemes.elliptic_curves.hom.compute_trace_generic[24]>", line 1, in <module>
        compute_trace_generic(-m7)
      File "/home/release/Sage/src/sage/schemes/elliptic_curves/hom.py", line 1191, in compute_trace_generic
        P = point_of_order(E, l)
            ^^^^^^^^^^^^^^^^^^^^
      File "/home/release/Sage/src/sage/schemes/elliptic_curves/ell_field.py", line 2083, in point_of_order
        l = rings.ZZ(l)
            ^^^^^
    NameError: name 'rings' is not defined
**********************************************************************
2 items had failures:
   2 of  10 in sage.schemes.elliptic_curves.hom.EllipticCurveHom.characteristic_polynomial
   5 of  26 in sage.schemes.elliptic_curves.hom.compute_trace_generic
    [282 tests, 7 failures, 1.27 s]
----------------------------------------------------------------------
sage -t --long --warn-long 35.9 --random-seed=123 src/sage/schemes/elliptic_curves/hom.py  # 7 doctests failed
----------------------------------------------------------------------

SageMath version 10.1.beta9, Release Date: 2023-08-05
@github-actions
Copy link

github-actions bot commented Aug 6, 2023

Documentation preview for this PR (built with commit bcd1d6e; changes) is ready! 🎉

vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 11, 2023
…imports; update `sage -fiximports`, add relint pattern

    
<!-- Please provide a concise, informative and self-explanatory title.
-->
<!-- Don't put issue numbers in the title. Put it in the Description
below. -->
<!-- For example, instead of "Fixes sagemath#12345", use "Add a new method to
multiply two integers" -->

### 📚 Description

<!-- Describe your changes here in detail. -->
<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->

- Part of: sagemath#29705
- Cherry-picked from: sagemath#35095

<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x
]`. -->

- [x] The title is concise, informative, and self-explanatory.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->
- Depends on sagemath#35974 (to soothe the linter)

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#35884
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee, Matthias Köppe
@vbraun vbraun merged commit d5a3fd1 into sagemath:develop Aug 13, 2023
6 of 8 checks passed
@mkoeppe mkoeppe added this to the sage-10.1 milestone Aug 13, 2023
@mkoeppe mkoeppe deleted the sage_modular_modularization branch August 21, 2023 06:13
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 4, 2023
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
This is a new maintenance command for adding/updating `# sage_setup:
distribution` directives at the top of source files.

Based on a discussion in
sagemath#35884 (comment)

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
- Part of: sagemath#29705
- Cherry-picked from: sagemath#35095
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->
- Depends on sagemath#36533 (CI fix)

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36135
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee, Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 5, 2023
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
This is a new maintenance command for adding/updating `# sage_setup:
distribution` directives at the top of source files.

Based on a discussion in
sagemath#35884 (comment)

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
- Part of: sagemath#29705
- Cherry-picked from: sagemath#35095
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->
- Depends on sagemath#36533 (CI fix)

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36135
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee, Matthias Köppe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants