Improve apyds_egg API: make repair private, add equivalence check, complete docstrings, make UnionFind generic - #152
Merged
Conversation
…e docstrings Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix public API exposure and add equality check for eclassid
Improve apyds_egg API: make repair private, add equivalence check, complete docstrings
Dec 22, 2025
| def test_egraph_are_equal_after_rebuild(): | ||
| eg = EGraph() | ||
|
|
||
| x = eg.add(apyds.Term("x")) |
Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Contributor
Author
Done in 507b8d7. UnionFind is now Generic[T] and can work with any type, not just EClassId. |
Copilot
AI
changed the title
Improve apyds_egg API: make repair private, add equivalence check, complete docstrings
Improve apyds_egg API: make repair private, add equivalence check, complete docstrings, make UnionFind generic
Dec 22, 2025
hzhangxyz
approved these changes
Dec 22, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the API design of the E-graph implementation by privatizing an internal method, adding an equivalence check method, completing documentation, and making the UnionFind data structure generic for better reusability.
- Privatized the
repairmethod to_repairto prevent unintended external usage - Added a new
are_equalpublic API method to check E-class equivalence - Completed parameter documentation for all public methods using Google-style docstrings
- Converted
UnionFindto a generic classUnionFind[T]for type safety and reusability
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| egg/apyds_egg/init.py | Renamed repair to _repair, added are_equal method, completed docstrings for merge, find, union, and canonicalize methods, made UnionFind generic by adding Generic[T] and updated type annotations |
| egg/tests/test_egraph.py | Added comprehensive tests for the new are_equal method, including basic equality checks and post-rebuild congruence verification |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def test_egraph_are_equal_after_rebuild(): | ||
| eg = EGraph() | ||
|
|
||
| x = eg.add(apyds.Term("x")) |
There was a problem hiding this comment.
Variable x is not used.
Suggested change
| x = eg.add(apyds.Term("x")) | |
| x = eg.add(apyds.Term("x")) | |
| assert isinstance(x, int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four API improvements to
/egg/apyds_egg/__init__.py: privatize internal method, add equivalence testing, complete parameter documentation for public methods, and make UnionFind a generic data structure.Changes
Made
repairprivate: Renamed to_repairto prevent exposure as public API. This method is an internal implementation detail ofrebuild().Added
are_equalmethod: New public API to check if twoEClassIdvalues belong to the same equivalence class:Completed parameter docstrings: Added Args/Returns sections to all public methods (
merge,find,union,canonicalize) following Google-style format. Previously onlyaddhad complete parameter documentation.Made UnionFind generic: Changed
UnionFindtoUnionFind(Generic[T])to make it a reusable generic data structure that can work with any type, not justEClassId. TheEGraphclass now usesUnionFind[EClassId]()to explicitly specify the type parameter. This improves code reusability without breaking existing functionality.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.