Make the assumptions system extensible by downstream libraries - #2371
Open
jessegrabowski wants to merge 8 commits into
Open
Make the assumptions system extensible by downstream libraries#2371jessegrabowski wants to merge 8 commits into
jessegrabowski wants to merge 8 commits into
Conversation
Rules declared with register_universal_assumption install onto keys created after the declaration, so a key defined by a downstream library is no longer silently skipped by the modules that previously looped over a frozen ALL_KEYS tuple at import time.
assume() keeps its named arguments for the built-in properties so they stay documented and typo-checked, and accepts registered extension keys through **assumptions.
Holding a key implies it is registered, so a graph can no longer carry a declaration the system cannot resolve and the drain rewrite needs no lookup. AssumptionKey.__reduce__ keeps that true across pickling, where the default dataclass path would skip __init__ and restore a key with no rules installed.
The trailing-two-axes rules were registered for every key, so Alloc broadcasting an index array claimed the result still had distinct entries while duplicating every one of them -- a fact that exists to license lifting an index earlier.
A key wanting all but one of the rules registers its own with prepend=True, since rules are tried in registration order until one answers.
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
Downstream libraries can define their own assumption keys now, and both the built-in and downstream ones can be set and queried off the key object.
Declaring and checking assumptions
holdsbuilds a throwawayFunctionGraphper call; pass one in (SYMMETRIC.holds(x, fgraph)) when asking about several variables of the same graph.Adding your own assumption
Constructing an
AssumptionKeyregisters it, which is all it takes forassume(),debugprint, and the drain rewrite to pick it up.register_matrix_property_rules(key)hands it the built-in trailing-two-axes propagation; a key with its own algebra registers rules the way the built-in properties do.SpecifyAssumptions takes keys, not names
SpecifyAssumptionsstores(AssumptionKey, FactState)pairs rather than(str, FactState), soSpecifyAssumptions({"diagonal": ...})now raises with a pointer toassume(). Holding a key implies it is registered, which makes an unregistered assumption unrepresentable instead of something the drain rewrite has to check for at compile time.AssumptionKey.__reduce__keeps that true across pickling, where the default dataclass path would skip__init__and restore a key with no rules installed.unique_indices no longer inherits the matrix rules
The trailing-two-axes rules were registered for every key rather than just the matrix ones. An
Allocbroadcast therefore claimedunique_indicesstill held on an array where every entry repeats, and that fact exists to license lifting an index earlier.