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

switch to nauty for generating posets #38795

Merged
merged 6 commits into from
Oct 12, 2024

Conversation

fchapoton
Copy link
Contributor

as there is now a direct method in nauty and we have added the interface previously

📝 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.

Copy link

github-actions bot commented Oct 9, 2024

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

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

LGTM.

@mantepse
Copy link
Collaborator

This is a very impressive speedup:

sage: %time n=7; sum(1 for dig in DiGraphGenerators()(n, is_poset))
CPU times: user 5.85 s, sys: 0 ns, total: 5.85 s
Wall time: 5.85 s
2045
sage: %time n=7; sum(1 for dig in DiGraphGenerators().nauty_posetg(f"{n} o"))
CPU times: user 57.3 ms, sys: 0 ns, total: 57.3 ms
Wall time: 66.7 ms
2045
sage: %time n=8; sum(1 for dig in DiGraphGenerators().nauty_posetg(f"{n} o"))
CPU times: user 395 ms, sys: 0 ns, total: 395 ms
Wall time: 399 ms
16999

@dcoudert
Copy link
Contributor

Actually, there is another issue: nauty_posetg works only for $n\leq 16$. You could use a switch to use it only in this case and use the previous (slower) method otherwise.

@mantepse
Copy link
Collaborator

Actually, there is another issue: nauty_posetg works only for n ≤ 16 . You could use a switch to use it only in this case and use the previous (slower) method otherwise.

Great catch!

To avoid such oversights in future (not in this pull request!), wouldn't it be better to have intermediate methods that call nauty_posetg and do the argument parsing? I am frequently wasting time looking up the precise string for nauty_geng to generate connected graphs only :-)

@mantepse
Copy link
Collaborator

I think that the issue pointed out by @dcoudert still needs fixing.

@fchapoton
Copy link
Contributor Author

We lose a lot of speed in the relabeling..

@dcoudert
Copy link
Contributor

I don't see how to avoid the topological sort. However, you can avoid a copy of the graph

-            yield FinitePoset(dig.relabel(label_dict, inplace=False))
+            yield FinitePoset(dig.relabel(label_dict, inplace=True))

note also that instead of dig.order(), you can use self._n. All graphs have the same number of vertices.

@fchapoton
Copy link
Contributor Author

merci pour les suggestions

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 11, 2024
as there is now a direct method in `nauty` and we have added the
interface previously

### 📝 Checklist

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

URL: sagemath#38795
Reported by: Frédéric Chapoton
Reviewer(s): David Coudert, Frédéric Chapoton, Martin Rubey
@vbraun vbraun merged commit 4326d0d into sagemath:develop Oct 12, 2024
19 of 20 checks passed
@fchapoton fchapoton deleted the nauty_for_poset branch October 16, 2024 18:57
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.

4 participants