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.geometry: Update # needs, use block-scoped tags #36033

Merged
merged 9 commits into from
Aug 13, 2023

Conversation

mkoeppe
Copy link
Member

@mkoeppe mkoeppe commented Aug 4, 2023

Cherry-picked from

📝 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

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 4, 2023

For instance, sage.geometry.riemannian_manifolds is not included in the distribution sagemath-polyhedra. Then you should not use the distribution to -fixdoctests the files under src/sage/geometry/riemannian_manifolds. Did you care about this?

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 4, 2023

--if-installed takes care of this automatically

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 4, 2023

OK.

There are a few warnings

File "src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx", line 38, in sage.geometry.polyhedron.combinatorial_polyhedron.conversions
Warning: Variable 'incidence_matrix_to_bit_rep_of_Vrep' referenced here was set only in doctest marked '# needs sage.combinat'
    face_list = incidence_matrix_to_bit_rep_of_Vrep(P.incidence_matrix())
    [62 tests, 0.40 s]
sage -t --random-seed=66710805610626010854933516970900481595 src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pyx
    [228 tests, 0.82 s]
sage -t --random-seed=66710805610626010854933516970900481595 src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx
**********************************************************************
File "src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx", line 46, in sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces
Warning: Variable 'incidence_matrix_to_bit_rep_of_Vrep' referenced here was set only in doctest marked '# needs sage.combinat'
    face_list = incidence_matrix_to_bit_rep_of_Vrep(P.incidence_matrix())
    [71 tests, 0.36 s]

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 4, 2023

How did they escape from the scrutiny of sage -fixdoctests?

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 4, 2023

These are false warnings from the doctester. I'll investigate what's going wrong there.
The tags are correct in the file (and the doctest fixer correctly refuses to fix them)

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 4, 2023

Yes, it's a bug in the doctest parser that affects blocks with continuation lines:

    sage: # needs sage.combinat
    sage: from sage.geometry.polyhedron.combinatorial_polyhedron.conversions \
    ....:         import incidence_matrix_to_bit_rep_of_Vrep
    sage: P = polytopes.associahedron(['A',3])

The block tag is forgotten immediately after the from line.

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 4, 2023

This is probably from the lines

        # Hack for non-standard backslash line escapes accepted by the current
        # doctest system.

in src/sage/doctest/parsing.py:1092.

I'll try to fix this tomorrow.

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 4, 2023

OK.

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 4, 2023

I investigated this issue.

The "hack" implements the line continuation backslash. See #12415.

So the "hack" removes the line continuation backslash so that the doctester accepts the doctest. In doing this, it inserts a newline character \n.

The added newline character effectively inserts a blank line between two doctest lines, so that the doctester cancels the persistent needs tag. That is why we get the warning message.

Then what should be a cure? It seems that we have two choices.

(1) We can just remove the "hack". Some new doctest failures may appear, but we can just fix them.

(2) We "fix" the "hack" by

--- a/src/sage/doctest/parsing.py
+++ b/src/sage/doctest/parsing.py
@@ -1087,13 +1087,8 @@ class SageDocTestParser(doctest.DocTestParser):
         # doctest system.
         m = backslash_replacer.search(string)
         while m is not None:
-            next_prompt = find_sage_prompt.search(string, m.end())
             g = m.groups()
-            if next_prompt:
-                future = string[m.end():next_prompt.start()] + '\n' + string[next_prompt.start():]
-            else:
-                future = string[m.end():]
-            string = string[:m.start()] + g[0] + "sage:" + g[1] + future
+            string = string[:m.start()] + g[0] + "sage:" + g[1] + string[m.end():]
             m = backslash_replacer.search(string, m.start())
 
         replace_ellipsis = not python_prompt.search(string)

Thus we prevent spurious new lines from being added.

I think we should choose one that has less side effects.

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 4, 2023

By some experiments, it seems that (1) is not an option. Line continuation backslash doesn't work at all without the "hack"...

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 4, 2023

(2) looks like a good solution to me

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 4, 2023

I agree. There are just three(two) doctests to fix then.

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 4, 2023

OK, found them and fixed them in #36034.

@@ -132,7 +132,7 @@ def integral_points_count(self, verbose=False, use_Hrepresentation=False,
sage: Q = P*(8/9)
sage: Q.integral_points_count()
1
sage: Q.integral_points_count(explicit_enumeration_threshold=0) # optional - latte_int
sage: Q.integral_points_count(explicit_enumeration_threshold=0)
1
Copy link
Collaborator

@kwankyu kwankyu Aug 5, 2023

Choose a reason for hiding this comment

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

This is a removal of a tag. Is this correct? Was it a misplaced tag or something has changed meanwhile?

Copy link
Member Author

Choose a reason for hiding this comment

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

This should not have been removed. I'll investigate.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the change is actually correct. This example is handled by preprocessing and does not need latte_int.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK.

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 5, 2023

I looked through the changes, which were made by, I guess, sage -fixdoctests automatically. So perhaps they are all correct. Then the purpose of my questions is to assure that sage -fixdoctests is reliable.

If sage -fixdoctests is reliable, then later PRs of the same nature may not need scanning of human eyes, which is mostly tedious.

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 5, 2023

I looked through the changes, which were made by, I guess, sage -fixdoctests automatically. So perhaps they are all correct. Then the purpose of my questions is to assure that sage -fixdoctests is reliable.

I am creating these PRs by:

If sage -fixdoctests is reliable, then later PRs of the same nature may not need scanning of human eyes, which is mostly tedious.

I'd say it's very reliable now -- within its specifications:

  • Free-form comments mixed with tags are sometimes removed (also tags such as # abs tol, mixed with # optional tags, are at risk)
  • Removal of tags by feature probing sometimes removes too many tags when variables in doctests are being reused. (The result always passes tags, but with the tags removed the doctests can be misleading.)

So eyeballing the changes is still necessary. I do this when I look for opportunities for using more block tags, but it's easy to miss a few bad changes.

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 5, 2023

Thanks for the summary of how you prepared the PR. All reasonable.

I'd say it's very reliable now -- within its specifications:

It seems so to me too.

So eyeballing the changes is still necessary. I do this when I look for opportunities for using more block tags, but it's easy to miss a few bad changes.

I see. I am expecting too much if I think that an automation could go without supervision.

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.

LGTM.

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 5, 2023

Thank you!

@github-actions
Copy link

github-actions bot commented Aug 5, 2023

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

vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 11, 2023
… tags

    
<!-- ^^^^^
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 -->

<!-- Why is this change required? What problem does it solve? -->
Cherry-picked from
- sagemath#35095
Part of
- sagemath#29705
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- 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.
- [ ] The description explains in detail what this PR is about.
- [x] 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: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36033
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee, Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 12, 2023
…ations

    
<!-- ^^^^^
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 -->

<!-- Why is this change required? What problem does it solve? -->
Fixes
sagemath#36033 (comment)
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- 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.
- [ ] The description explains in detail what this PR is about.
- [x] 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#36025 (merged here)

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36034
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee, Matthias Köppe
@vbraun vbraun merged commit e8453e1 into sagemath:develop Aug 13, 2023
16 of 18 checks passed
@mkoeppe mkoeppe added this to the sage-10.1 milestone Aug 13, 2023
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.

None yet

3 participants