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

Allow overwriting existing rewrites during registration #1119

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

AdvH039
Copy link
Contributor

@AdvH039 AdvH039 commented Dec 12, 2024

Description

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pytensor--1119.org.readthedocs.build/en/1119/

@AdvH039
Copy link
Contributor Author

AdvH039 commented Dec 12, 2024

I want to add tests but am unsure of the best approach. Will a simple test like the one below suffice?
Thanks.

Screenshot from 2024-12-12 16-48-33

@AdvH039 AdvH039 changed the title Add overwrite existing flag Add overwrite_existing flag Dec 12, 2024
@ricardoV94
Copy link
Member

I want to add tests but am unsure of the best approach. Will a simple test like the one below suffice? Thanks.

Better to create a separate database just for testing, and register directly to it (no decorator). It should fail on the second attempt, but pass on the third when pass an overwrite=True kwarg

@AdvH039
Copy link
Contributor Author

AdvH039 commented Dec 14, 2024

@ricardoV94 done. Thanks.

@AdvH039
Copy link
Contributor Author

AdvH039 commented Jan 11, 2025

@ricardoV94 please let me know the further steps. Thanks!!

Comment on lines 91 to 94
if overwrite_existing:
raise ValueError(
f"The tag '{name}' does not exist in the database. Cannot be overwritten."
)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't needed. It's enough not to fail when it already exists

Comment on lines 99 to 100
if not overwrite_existing:
self.add_tags(name, *tags)
Copy link
Member

@ricardoV94 ricardoV94 Jan 15, 2025

Choose a reason for hiding this comment

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

Can we remove the tags in the previous block, so this doesn't need to be conditional?

Comment on lines 41 to 61
db.register("c", NewTestRewriter()) # name taken

db.register("c", NewTestRewriter(), overwrite_existing=True)
Copy link
Member

Choose a reason for hiding this comment

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

Can we use a separate test for readability?

I would like to test the new rewrite actually replaces the old one. You can make two rewrites that do nothing but update a global counter and check the first time you rewrite an fgraph the first counter goes up (but not the second) and vice-versa

Copy link
Member

@ricardoV94 ricardoV94 Jan 15, 2025

Choose a reason for hiding this comment

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

Still check the raises in the first time you try to redefine the rewrite (and that the original rewrite isn't broken by this attempt)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ricardoV94 I implemented the additonal test as you mentioned. Please let me know if it matches with the idea you had in mind.

@AdvH039 AdvH039 force-pushed the add_overwrite_existing_flag branch from aac4457 to aefb963 Compare January 25, 2025 18:59
@AdvH039
Copy link
Contributor Author

AdvH039 commented Jan 28, 2025

@ricardoV94 please let me know about further steps to be taken. Thank you !!

@ricardoV94
Copy link
Member

ricardoV94 commented Jan 28, 2025

Hi @AdvH039 I wanted to use the DB user-facing API on the tests, but I didn't know it by heart so I checked the PR and changed it myself. I also put the helper classes inside the relevant test function to keep things a bit tidier.

Anyway the logic seems to be working (it already was). Let me know if the changes I pushed look good and we can merge this one.

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.29%. Comparing base (4ea4259) to head (32b82be).
Report is 15 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1119      +/-   ##
==========================================
+ Coverage   82.27%   82.29%   +0.01%     
==========================================
  Files         186      186              
  Lines       48000    48014      +14     
  Branches     8621     8625       +4     
==========================================
+ Hits        39490    39511      +21     
+ Misses       6353     6346       -7     
  Partials     2157     2157              
Files with missing lines Coverage Δ
pytensor/graph/rewriting/db.py 89.27% <100.00%> (+3.30%) ⬆️

... and 1 file with indirect coverage changes

@AdvH039
Copy link
Contributor Author

AdvH039 commented Jan 28, 2025

@ricardoV94 the changes look great. We can merge it.

@ricardoV94 ricardoV94 merged commit 5fb56ba into pymc-devs:main Jan 28, 2025
64 checks passed
@ricardoV94
Copy link
Member

@AdvH039 this was great, looking forward to your next PR if you're so inclined!

@AdvH039
Copy link
Contributor Author

AdvH039 commented Jan 28, 2025

@ricardoV94 Do you know any compiler related issues here that are beginner/intermediate?

@ricardoV94
Copy link
Member

@AdvH039 I'm sure we do, but may not have opened them. What sort of compiler-related stuff interests you?

@AdvH039
Copy link
Contributor Author

AdvH039 commented Jan 29, 2025

@ricardoV94 anything really. I just want the experience. But it would be nice if it had something to do with compiler optimization.
Thanks!! (edit: or instrumentation)

@ricardoV94
Copy link
Member

Perhhaps something along the lines of: #138 #140, #945, #1006, #845 (in no order whatsoever)

@ricardoV94 ricardoV94 changed the title Add overwrite_existing flag Allow overwriting existing rewrites during registration Feb 3, 2025
@ricardoV94 ricardoV94 added the enhancement New feature or request label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request graph rewriting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow overwriting registered rewrite
2 participants