Skip to content

Refactor degree sequence functions#41188

Merged
vbraun merged 24 commits intosagemath:developfrom
cxzhong:patch-3
Dec 29, 2025
Merged

Refactor degree sequence functions#41188
vbraun merged 24 commits intosagemath:developfrom
cxzhong:patch-3

Conversation

@cxzhong
Copy link
Copy Markdown
Contributor

@cxzhong cxzhong commented Nov 16, 2025

Refactor degree sequence generation to use generators, reducing memory usage. Fix #41187

📝 Checklist

  • The title is concise and informative.
  • 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 and checked the documentation preview.

⌛ Dependencies

@cxzhong cxzhong requested a review from maxale November 16, 2025 14:53
@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Nov 16, 2025

Can you help me check if the result is true? Thank you @maxale

@cxzhong cxzhong marked this pull request as ready for review November 16, 2025 15:57
@maxale
Copy link
Copy Markdown
Contributor

maxale commented Nov 16, 2025

These changes look good to me, but with respect to refactoring, I'd also suggest to change list to tuple to enable easy hashability. Thanks!

@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Nov 17, 2025

sage: sum(1 for _ in DegreeSequences(18))
675759564

The result is right. But it takes 11 minutes. Is it normal? @maxale

@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Nov 17, 2025

These changes look good to me, but with respect to refactoring, I'd also suggest to change list to tuple to enable easy hashability. Thanks!

I have used tuple instaed of list

Copy link
Copy Markdown
Contributor

@mantepse mantepse left a comment

Choose a reason for hiding this comment

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

Looks great!

Comment thread src/sage/combinat/degree_sequences.pyx Outdated
@mantepse
Copy link
Copy Markdown
Contributor

Maybe it would make sense to implement a cardinality method using https://arxiv.org/abs/2301.07022, section 5.1. Note that go code is attached to the arxiv submission. I guess that translating the go code to python is a bit too much work, but perhaps one can implement a simple version.

@user202729
Copy link
Copy Markdown
Contributor

wait. Is returning a tuple instead of a list considered a breaking change? (although tuple is "better" in a way that it's immutable and hashable, as pointed out above)

Looks like the original author is no longer around, so I'll ask a few other frequent contributors. @tscrim @dimpase @saraedum

@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Nov 17, 2025

As suggestions I would like to use range instead of this loop

@saraedum
Copy link
Copy Markdown
Member

wait. Is returning a tuple instead of a list considered a breaking change? (although tuple is "better" in a way that it's immutable and hashable, as pointed out above)

Looks like the original author is no longer around, so I'll ask a few other frequent contributors. @tscrim @dimpase @saraedum

I don't think we'd usually consider this a breaking change. I don't think we have a clear policy on this.

@user202729
Copy link
Copy Markdown
Contributor

okay.

cf. #41038 where Family is considered not compatible with tuple

@mantepse
Copy link
Copy Markdown
Contributor

Do we really want to include the last commit (which is a slowdown)?

@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Nov 18, 2025

Do we really want to include the last commit (which is a slowdown)?

If It does not be slower much than before, I think it is acceptable. @user202729

@mantepse
Copy link
Copy Markdown
Contributor

Do we really want to include the last commit (which is a slowdown)?

If It does not be slower much than before, I think it is acceptable. @user202729

Yes, but is there any good reason to do it? The other loops in the same file are consistently done with the same syntax, and I don't see any advantage of imitating python style in this particular case.

@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Nov 18, 2025

Maybe I revert this

@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Nov 18, 2025

Do we really want to include the last commit (which is a slowdown)?

If It does not be slower much than before, I think it is acceptable. @user202729

Yes, but is there any good reason to do it? The other loops in the same file are consistently done with the same syntax, and I don't see any advantage of imitating python style in this particular case.

I have done this. Maybe revert is much faster

cxzhong and others added 12 commits December 3, 2025 21:17
We introduce a new class for Enum
Update the assignment of self._n to avoid unnecessary conversion.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Added examples for checking containment in DegreeSequences.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Dec 5, 2025

@mantepse can you help me review this?

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 12, 2025

Documentation preview for this PR (built with commit 9adc2e0; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@cxzhong cxzhong requested a review from nbruin December 17, 2025 08:34
@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Dec 18, 2025

@user202729 Can you review this again?

@user202729
Copy link
Copy Markdown
Contributor

user202729 commented Dec 24, 2025

  • I'd rather not exposing _DegreeSequenceEnumerator until there's a need. It's an internal class after all. (Although not everyone agree on this point.)
  • Is it possible to overflow the unsigned char in any reasonable time? (If yes, given the old code does not support n ≥ 256 either, I think that's best left to future work.)
  • some ASCII drawing in comments (boxes with # borders) get misaligned, but that's unimportant.

otherwise looks correct.

@cxzhong
Copy link
Copy Markdown
Contributor Author

cxzhong commented Dec 24, 2025

I think _DegreeSequenceEnumerator is a internal class which is only for DegreeSequence. So I do not think it needs to expose to others

@user202729
Copy link
Copy Markdown
Contributor

one comment left

  • Is it possible to overflow the unsigned char in any reasonable time? (If yes, given the old code does not support n ≥ 256 either, I think that's best left to future work.)

but shouldn't be blocking.

@vbraun vbraun merged commit 5cf037d into sagemath:develop Dec 29, 2025
20 of 22 checks passed
@cxzhong cxzhong deleted the patch-3 branch December 29, 2025 14:40
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.

Prohibitive memory requirement in DegreeSequences

9 participants