FEAT: declare rule facts with TypedDict - #379
Open
grayson-helmholz wants to merge 1 commit into
Open
grayson-helmholz wants to merge 1 commit into
grayson-helmholz wants to merge 1 commit into
Conversation
redeboer
added this pull request to stack #386
September 15, 2026 14:29
redeboer
self-requested a review
September 15, 2026 14:40
This branch has not been deployed
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.
TypedDict#337✨ New features
qrules.quantum_numbersgains twoTypedDicts,EdgeFactsandNodeFacts, that name every quantum number a state or interaction can carry. A conservation rule declares what it needs as a subset of these keys, for instanceChargeFactswith its single required keycharge.RuleArgumentHandlerandget_required_qns()now recogniseTypedDictrule inputs next to the existingattrscomposites and bare quantum-number types. The required keys of theTypedDictdetermine when a rule can be executed, and its full annotations determine which quantum numbers are passed in, so a rule states its run conditions in its own signature instead of relying on a separately declared input class.This is a spike that converts a representative sample of rules:
ChargeConservation,spin_magnitude_conservation, andhelicity_conservation. The remaining rules keep their current input types, which is why both mechanisms coexist inRuleArgumentHandler.Rules that were converted now receive a list of dicts rather than a list of bare quantum-number values, so direct calls have to pass the quantum numbers by name.
ChargeConservationno longer derives from theadditive_quantum_number_rule()decorator but spells out its__call__, and theattrsclassSpinMagnitudeNodeInputis replaced by aTypedDict.SpinMagnitudeNodeInputSpinMagnitudeNodeFacts(aTypedDict)spin_magnitude_conservation(ingoing_spin_magnitudes=[Fraction(1)], ...)spin_magnitude_conservation(ingoing_spin_magnitudes=[{"spin_magnitude": Fraction(1)}], ...)helicity_conservation(ingoing_spin_mags=[Fraction(1)], ...)helicity_conservation(ingoing_spin_mags=[{"spin_magnitude": Fraction(1)}], ...)Squash commit messages