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.rings.function_field: Modularization fixes #35230

Merged
merged 60 commits into from
Apr 1, 2023

Conversation

mkoeppe
Copy link
Contributor

@mkoeppe mkoeppe commented Mar 5, 2023

📚 Description

  • We split out .derivations (which uses modules) from .maps (which doesn't).
  • We separate the implementation of rational function fields (which do not need Singular for Gröbner basis calculations) from the implementation of more complicated function fields (which do).
  • We move some imports into methods.

This is for modularization purposes:

📝 Checklist

  • I have made sure that the title is self-explanatory and the description concisely explains the PR.
  • I have linked an issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

⌛ Dependencies

@codecov-commenter
Copy link

codecov-commenter commented Mar 5, 2023

Codecov Report

Patch coverage: 91.76% and project coverage change: -0.07 ⚠️

Comparison is base (f449b14) 88.62% compared to head (63be8bf) 88.56%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #35230      +/-   ##
===========================================
- Coverage    88.62%   88.56%   -0.07%     
===========================================
  Files         2148     2161      +13     
  Lines       398653   398744      +91     
===========================================
- Hits        353308   353129     -179     
- Misses       45345    45615     +270     
Impacted Files Coverage Δ
src/sage/categories/function_fields.py 87.50% <ø> (ø)
src/sage/features/__init__.py 95.18% <ø> (ø)
src/sage/features/all.py 100.00% <ø> (ø)
src/sage/features/bliss.py 100.00% <ø> (ø)
src/sage/features/cddlib.py 100.00% <ø> (ø)
src/sage/features/csdp.py 40.74% <ø> (ø)
src/sage/features/cython.py 100.00% <ø> (ø)
src/sage/features/databases.py 96.15% <ø> (-0.15%) ⬇️
src/sage/features/dvipng.py 100.00% <ø> (ø)
src/sage/features/ffmpeg.py 22.58% <ø> (-2.42%) ⬇️
... and 92 more

... and 23 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 10, 2023

This PR makes me think whether the direction and the level of the modularization efforts is reasonable.

The branch adds one of # optional - M tags to every doctests depending on the base fields over which function fields are defined, where M is one of sage.libs.singular, sage.libs.pari, and sage.rings.number_field, and also sage.modules for derivations. In the future, no doctest in the function fields module will go without one of these tags since a function field needs a base field. This is very fine modularization that I didn't expect.

If the function fields module is dependent on all of these Ms, we do not need these tags, and one can add a new doctest without worrying which one of those tags should be added to the doctest.

So a basic question is whether some users of the function fields module will need only, say, finite fields as their base fields and want to install only sage.libs.singular along with the function fields module, and thus he/she can save some of disk space and install time. I guess there can be such users for some critical mission, but most users (including me) will be satisfied with time and space saved by much coarse modularization like, say, sage with full function fields module but without manifolds and optimization modules.

If we can still choose the level of the whole modularization efforts, I think we need to decide this on sage-devel, once and for all, before proceeding.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 10, 2023

In the future, no doctest in the function fields module will go without one of these tags since a function field needs a base field.

No, that's not true. The basic rings ZZ and QQ are always available.

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 10, 2023

Ah, I see. If the function field is an extension of rational function field over QQ, the doctest needs sage.libs.singular. So to know which tag is needed, one needs to know the implementation detail.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 10, 2023

Yes, these dependencies are not always obvious. To some extent these optional tags provide the necessary information for users who need to deploy the modularized distributions.
I would also expect that there may be a few ways how the hard dependencies on some of the libraries can be avoided. For example, Singular is involved whenever a Gröbner basis must be computed. But it's called even for very very simple inputs.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 10, 2023

For modules where all doctests depend on a feature, I have been using the file-level annotation. # sage.doctest: optional - M.
But most modules mix tests that require no additional features with some that do require additional features.

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 10, 2023

All function fields, which are not simple rational function fields, use multivariate polynomial rings, which is provided by Singular. For a user of the function fields module, Singular is a prerequisite, not an additional feature.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 10, 2023

That's true, currently; but soon we will be able to provide multivariate polynomials using FLINT instead.

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 10, 2023

Then those optional tags will need to be updated? This is a drawback of technical dependency added to doctests?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 10, 2023

Yes, when the underlying library for a functionality changes, some of these annotations will need updating.

Currently for example, the tag sage.libs.pari is on all tests that construct a finite field; but it is also on all tests that require factoring & prime number ranges. I haven't attempted to distinguish these two cases [there are probably more] using semantically higher level tags.

On the other hand, a tag like sage.rings.number_field will not need to be updated when we reimplement number fields.

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 10, 2023

Back to my main point: We can just make the distribution package that installs the function fields module dependent on those technical features. Why not? The same question will be raised for every high level mathematical module when most of its doctests would be laced with lots of repetitive optional tags.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 10, 2023

Why not?

Because the ordinary rational functions also go through the same code, and they are a crucial part of setting up the categories for the basic rings.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 10, 2023

In some cases, after a mild reorganization it may be possible to replace lots of # optional tags with a file-level annotation.
For example FunctionFieldMaximalOrderInfinite_polymod currently only has doctests using finite fields, not rationals [I have not checked whether that's by design]. So if this were moved to a separate file, we would have much fewer tags.

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 10, 2023

It would be possible to separate rational functions code from the extensions (of rational function fields) code. Then rational functions module could be included in a small distribution, and the extensions module would go into a bigger distribution.

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 19, 2023

I added missing titles to new files in the PR to your branch

@github-actions
Copy link

Documentation preview for this PR is ready! 🎉
Built with commit: 63be8bf

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 19, 2023

Nice. Thanks.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 19, 2023

Thank you!

@vbraun
Copy link
Member

vbraun commented Mar 26, 2023

merge conflict

SageMath version 10.0.beta6, Release Date: 2023-03-26
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 26, 2023

Trivial merge, back to positive

@vbraun
Copy link
Member

vbraun commented Mar 29, 2023

sage -t --long --warn-long 73.8 --random-seed=123 src/sage/interfaces/r.py  # 3 doctests failed

@vbraun vbraun merged commit c1a0323 into sagemath:develop Apr 1, 2023
@mkoeppe mkoeppe added this to the sage-10.0 milestone Apr 1, 2023
vbraun pushed a commit that referenced this pull request Apr 6, 2023
gh-35314: `sage.schemes`: Reformat doctests, add `# optional` annotations
    
<!-- ^^^^^
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 #1234" use "Introduce new method to
calculate 1+1"
-->
### 📚 Description

<!-- Describe your changes here in detail -->
Adding doctest tags `# optional - sage.rings.finite_rings`,
`...number_field`, `...padics`.

While going through the doctests line by line, I also made the following
changes:
- some coding style fixes in the doctests (such as adding spaces around
some operators and after commas, following PEP 8) - improved the
readability of them in the HTML format by breaking long lines to avoid
having to scroll horizontally
- improved indentation of input and output, in particular when morphisms
are displayed
- made better use of the horizontal space in the doctests of some
modules in `sage.schemes.toric`, which were formatted for a very narrow
layout
- improved the sphinx markup of some docstrings.

<!-- Why is this change required? What problem does it solve? -->
The doctest tags are preparation for being able to test parts of
`sage.schemes` in a modularized setting, in which not all rings are
available. See https://doc.sagemath.org/html/en/developer/packaging_sage
_library.html#doctest-only-dependencies

<!-- If it resolves an open issue, please link to the issue here. For
example "Closes #1337" -->
Part of:
- #29705

### 📝 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! -->

- [x] I have made sure that the title is self-explanatory and the
description concisely explains the PR.
- [x] I have linked an issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies
<!-- List all open pull requests that this PR logically depends on -->
<!--
- #xyz: short description why this is a dependency
- #abc: ...
-->
- Depends on #35230 (not merged here) for the definition of the feature
`sage.rings.finite_rings`.

The mass edits adding `# optional` tags were made using the following
Emacs macro.
```elisp
(defun sage-copy-optional-annotation ()
  "In a 'sage: ' line of a docstring, copy '# optional' from a previous
line and
advance to the end of the next 'sage: ' line or to the end of the
current docstring.
If invoked elsewhere, just advance to the end of the next 'sage: '
line."
  (interactive)
  (if (save-excursion (beginning-of-line)
                      (looking-at " *sage:"))
      (let ((tab-stop-list
             (list (save-excursion
                     (previous-line)
                     (end-of-line)
                     (re-search-backward "# *optional.*$")
                     (- (match-beginning 0)
                        (save-excursion
                          (beginning-of-line) (point)))))))
        (end-of-line)
        (just-one-space)
        (tab-to-tab-stop)
        (insert (match-string-no-properties 0))
        (re-search-forward "sage: \\|\"\"\"")
        (end-of-line))
    (re-search-forward "sage:")
    (end-of-line)))

(with-eval-after-load "python-mode"
  (define-key python-mode-map (kbd "C-M-;") 'sage-copy-optional-
annotation))
```
    
URL: #35314
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee, Matthias Köppe
@saraedum
Copy link
Member

@kwankyu many of the copyright headers here now only mention you as the copyright holder. I think that's not accurate and all the authors of the files from which the code has been copied should be mentioned.

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 18, 2023

Right. Sorry about that. I prepared a PR to fix the mistakes.

@mkoeppe mkoeppe deleted the refactor_function_field branch June 18, 2023 23:09
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 18, 2023

Also apologies from me – apparently I didn't catch it when I reviewed @kwankyu's contributions to this PR

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.

5 participants