Skip to content

ENH: split StateTransitionManager into a workflow module - #344

Open
grayson-helmholz wants to merge 6 commits into
mainfrom
split-stm-workflow
Open

ENH: split StateTransitionManager into a workflow module#344
grayson-helmholz wants to merge 6 commits into
mainfrom
split-stm-workflow

Conversation

@grayson-helmholz

@grayson-helmholz grayson-helmholz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What

Extracts the pipeline stages of the StateTransitionManager into free functions in a new qrules.workflow module, so that intermediate results — most notably QNProblemSets — can be inspected, modified, and fed back into the pipeline (GROMACS-style workflow, as proposed in #305). The STM remains as a thin facade that delegates to these functions; its public API and behavior are unchanged.

New data structures

Pipeline stage functions

Stage Extracted from
create_graph_settings() STM.__determine_graph_settings
create_problem_sets() STM.create_problem_sets
solve() STM.find_quantum_number_transitions + STM._solve
convert_to_particle_transitions() STM._find_particle_transitions + STM.__convert_to_particle_definitions
collect_reaction_info() post-processing half of STM.find_solutions

Crucially, solve() takes strength-grouped QNProblemSets directly, closing the gap described in #305: generated QNProblemSets can now be filtered/modified (e.g. with filter_quantum_number_problem_set()) and solved, without reconstructing STM-internal state around a bare CSPSolver.

Default use-case wrappers

Two functions cover the standard workflow, meeting at the strength-grouped QNProblemSets — the natural inspection point:

qn_problem_sets = create_qn_problem_sets(["J/psi(1S)"], ["gamma", "pi0", "pi0"], particle_db)
# ... inspect / filter / modify ...
reaction = find_solutions(qn_problem_sets, particle_db, final_state=["gamma", "pi0", "pi0"])

create_qn_problem_sets() generates QNProblemSets without the StateTransitionManager, which closes #284 as written. Note that it still expands spin projections into separate problem sets internally (via the particle-level ProblemSet dual); the facts-driven generation without projection expansion is tracked separately in #338/#339.

Notes

  • Pure refactor: extracted function bodies are verbatim where possible; tests/channels/ results are identical.
  • The private helpers _group_by_strength, _filter_by_name_pattern, _match_final_state_ids, and _strip_spin moved from transition.py to workflow.py, next to their only remaining callers.
  • Multiprocessing now pickles only the allowed-intermediate-state property maps (via functools.partial) instead of the whole STM instance.
  • Pre-existing quirk kept as-is (candidate for a separate BEHAVIOR fix): STM.reaction_mode is stored as str(solving_mode), so the SolvingMode.FAST early-break in the solving loop never triggers through the STM. The new workflow.solve() compares the enum properly, so FAST works as documented when using the new API; the STM delegation preserves the old (always-FULL) behavior.
  • qrules.workflow is not re-exported in qrules.__init__ for now; happy to add that if preferred.

Part of epic #336 (Stage 3 of the roadmap).

Verification

  • pytest tests/unit src -m "not slow": 696 passed
  • pytest tests/channels -m "slow or not slow": 55 passed
  • mypy src/qrules: clean; ruff check / ruff format: clean; all pre-commit hooks (incl. pyright) pass

🤖 Generated with Claude Code

Extract the pipeline stages of the `StateTransitionManager` into free
functions in a new `qrules.workflow` module, so that intermediate
results (most notably `QNProblemSet`s) can be inspected, modified, and
fed back into the pipeline. The STM remains as a thin facade that
delegates to these functions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@redeboer redeboer added ⚠️ Interface Breaking changes to the API ⚙️ Enhancement Improvements and optimizations of existing features labels Jul 10, 2026
@redeboer
redeboer self-requested a review July 10, 2026 13:15
@grayson-helmholz

Copy link
Copy Markdown
Contributor Author
qrules-flowchart3

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

web-flow and others added 4 commits July 10, 2026 13:45
Introduce `QNProblemSetCollection`, returned by `create_qn_problem_sets()`, which
carries the intermediate-particle selection, final state, and formalism along with
the strength-grouped `QNProblemSet`s. `find_solutions()` defaults to these values,
so the solving stage can no longer silently diverge from the values with which the
problem sets were created (e.g. matching against the full PDG although the problem
sets were built for a restricted resonance selection, or deduplicating canonical
solutions with helicity filters). Explicit arguments still override, and a plain
strength-grouped dictionary is still accepted.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TWmXKcjJMmRVJCUi58JDLH
The topology creation (including the n-body mass-conservation toggle) and the
`ProblemSet` to `QNProblemSet` conversion were duplicated between the
`StateTransitionManager` and the workflow module; both now delegate to the
single implementation in `qrules.workflow`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TWmXKcjJMmRVJCUi58JDLH
Mirrors `src/qrules/workflow.py` with `tests/unit/test_workflow.py`, covering the
intermediate-particle selection, `InteractionConfig` get/set semantics, and an
equivalence test that reproduces the STM-generated `ReactionInfo` through the
`create_qn_problem_sets`/`find_solutions` pipeline.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TWmXKcjJMmRVJCUi58JDLH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚙️ Enhancement Improvements and optimizations of existing features ⚠️ Interface Breaking changes to the API

Projects

None yet

3 participants