Skip to content

FEAT: declare rule facts with TypedDict - #379

Open
grayson-helmholz wants to merge 1 commit into
solver-without-particle-dbfrom
typeddict-facts
Open

grayson-helmholz wants to merge 1 commit into
solver-without-particle-dbfrom
typeddict-facts

Conversation

@grayson-helmholz

@grayson-helmholz grayson-helmholz commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

✨ New features

  • qrules.quantum_numbers gains two TypedDicts, EdgeFacts and NodeFacts, 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 instance ChargeFacts with its single required key charge.
  • RuleArgumentHandler and get_required_qns() now recognise TypedDict rule inputs next to the existing attrs composites and bare quantum-number types. The required keys of the TypedDict determine 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, and helicity_conservation. The remaining rules keep their current input types, which is why both mechanisms coexist in RuleArgumentHandler.

⚠️ Interface changes

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. ChargeConservation no longer derives from the additive_quantum_number_rule() decorator but spells out its __call__, and the attrs class SpinMagnitudeNodeInput is replaced by a TypedDict.

Old name New name
SpinMagnitudeNodeInput SpinMagnitudeNodeFacts (a TypedDict)
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

* BREAK: pass rule facts as dicts keyed by QN name
* BREAK: replace SpinMagnitudeNodeInput with TypedDict

@redeboer
redeboer added this pull request to stack #386 September 15, 2026 14:29
@redeboer redeboer changed the title ENH: type rule facts with TypedDict FEAT: declare rule facts with TypedDict Sep 15, 2026
@redeboer redeboer added ⚠️ Interface Breaking changes to the API ✨ Feature New feature added to the package labels Sep 15, 2026
@redeboer
redeboer self-requested a review September 15, 2026 14:40
@redeboer redeboer added this to the 0.11.0 milestone Sep 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ Feature New feature added to the package ⚠️ Interface Breaking changes to the API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type quantum-number maps and rule signatures with TypedDict

2 participants