Skip to content

Design patterns: Context, EvaluationParameters and ParsedQuantity dataclasses, graph helpers - #283

Draft
m-messer wants to merge 7 commits into
refactor/restructure-appfrom
refactor/design-patterns
Draft

m-messer wants to merge 7 commits into
refactor/restructure-appfrom
refactor/design-patterns

Conversation

@m-messer

Copy link
Copy Markdown
Member

Problem

This is the design-patterns follow-up deferred from #281, and it's stacked on that PR. After the restructure, the contexts were still plain dicts of functions. The evaluation parameters were a FrozenValuesDictionary read by string keys, and parsed quantities were a QuantityDict. Because of this, neither mypy nor a reader could see which fields exist. The graph builders also repeated the same setup code, and parse_reserved_expressions repeated its learner/task error handling three times.

Changes

Behaviour is unchanged. Feedback strings, tags, graph shapes and raised exceptions are all the same as before.

  • outcome_graph helper (app/context/graph_helpers.py): creates a graph with its end node and evaluation node. It is used in the generic, WHERE and physical-quantity order graphs. In order.py the graph now gets its real label instead of None.
  • check_equality (app/context/symbolic/comparison.py): the simplification retries are now straight-line code with early returns.
  • Context dataclass (app/context/base.py): a frozen dataclass replaces the context dicts. select_context(params) replaces determine_context. The context is passed explicitly instead of being deep-copied into parameters["context"].
  • ParsedQuantity dataclass (app/context/physical_quantity/parsing.py): replaces QuantityDict.
  • EvaluationParameters dataclass (app/evaluation_parameters.py): replaces FrozenValuesDictionary, and app/frozen_dict.py is removed. GraphTemplate and Context.feedback_procedure_generator now take it. Parameters stays for the raw request parameters. A criterion given twice still fails with Cannot parse criteria: …, now through an explicit check.
  • _report helper (app/evaluation.py): the learner → feedback / task → raise choice in parse_reserved_expressions is now in one helper. A task parse error still raises without a tag, as before.
  • Rename: parameters_dict → parameters in the symbolic context.
  • Docs: the Context and evaluation-flow sections of app/docs/dev.md are updated.

Checklist

  • Tests added/updated (n/a, no behaviour change)
  • Docs updated (app/docs.md) if user-facing behaviour changed (n/a, no behaviour change; app/docs/dev.md updated)

Testing

  • pytest app/tests: 1217 passed, 2 skipped, 1 failed. The failure is the known test_radians_to_frequency.
  • mypy app: no issues.
  • After each commit, evaluation_function(..., include_test_data=True) output for 15 symbolic and physical-quantity cases was byte-identical to the output before it (with PYTHONHASHSEED=0). For the _report commit, the raised exceptions (args, cause, suppressed context) for bad responses and answers were also compared and matched.

🤖 Generated with Claude Code

…ialization logic with `outcome_graph` helper function, update imports, and streamline related modules.
…parison, eliminate redundant structures, and streamline simplification handling.
…` dataclass, introduce `base.py` for shared context logic, update evaluation methods to use `Context` object, and streamline context selection logic in `select_context`.
…sedQuantity` dataclass, update type aliases and dependent methods, and streamline parameter lookups in evaluation logic.
… `EvaluationParameters` dataclass, update all affected modules and type hints, streamline parameter access, and update dev documentation accordingly.
…_report` helper to centralize feedback and exception handling logic, reduce redundancy, and streamline reserved expression evaluation.
…s, internal references, and type hints across symbolic evaluation modules to streamline parameter usage and improve consistency.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant