Skip to content

refactor: unify evaluate_* positional signatures#342

Open
mpvanderschelling wants to merge 1 commit into
developfrom
refactor/issue-309-evaluate-signatures
Open

refactor: unify evaluate_* positional signatures#342
mpvanderschelling wants to merge 1 commit into
developfrom
refactor/issue-309-evaluate-signatures

Conversation

@mpvanderschelling

Copy link
Copy Markdown
Collaborator

Summary

Closes #309. The five evaluate_* functions formerly disagreed on the positional shape after execute_fn. evaluate_mpi inserted comm at index 1; evaluate_cluster_array inserted job_number at index 2. Both forced DataGenerator.call to know each mode's positional contract.

  • Standardise on (execute_fn, data, pass_id, **kwargs) across all five functions.
  • evaluate_mpi now pulls comm = kwargs.pop("comm") and evaluate_cluster_array pulls job_number = kwargs.pop("job_number") at the top of the function. Missing values surface as a clean TypeError (evaluate_mpi requires the MPI communicator via \comm=...`) rather than a deep KeyError`.
  • DataGenerator.call already dispatched everything as keyword arguments, so no caller update is needed. Existing tests already passed comm= and job_number= as keywords.

Test plan

  • uv run pytest tests/datageneration/ --no-cov — 81 passed
  • New test_cluster_array_missing_job_number_raises checks the clean TypeError
  • New TestUnifiedEvaluateSignatures parametrises across all five evaluators and asserts (a) the first three positional parameters are (execute_fn, data, pass_id) and (b) each accepts **kwargs — a contract pin so the next change can't silently regress
  • uv run pre-commit run ... — clean

Notes for reviewers

  • This is the third branch in the datagenerator.py triplet (#247 → #234 → #309). Both prior branches are open against develop; once one merges, the next will need a rebase. No conflict expected in _run_sample or the helpers.

Fix #309

🤖 Generated with Claude Code

Five `evaluate_*` functions formerly disagreed on the positional
shape after `execute_fn`:

- `evaluate_sequential(execute_fn, data, pass_id, **kwargs)`
- `evaluate_multiprocessing(execute_fn, data, pass_id, nodes=..., **kwargs)`
- `evaluate_cluster(execute_fn, data, pass_id, wait_for_creation=..., max_tries=..., **kwargs)`
- `evaluate_mpi(execute_fn, comm, data, pass_id, ...)`  -- `comm` injected at index 1
- `evaluate_cluster_array(execute_fn, data, job_number, pass_id, **kwargs)`  -- `job_number` at index 2

The mismatch forced `DataGenerator.call` to know each mode's
positional contract and ruled out cleanly accepting a generic
evaluator plug-in (issue #309).

Move `comm` and `job_number` into `**kwargs`. Each evaluator
pops its required mode-specific arg from `kwargs` and raises a
clear `TypeError` ("evaluate_mpi requires the MPI communicator
via `comm=...`") if absent. The leading positional shape is
now `(execute_fn, data, pass_id, **kwargs)` across all five
functions, matching how `DataGenerator.call` already invoked
them.

`core.DataGenerator.call` already used keyword-only dispatch, so
no caller update is needed. Existing tests already passed
`comm=` and `job_number=` as keywords (see
`tests/datageneration/test_datagenerator_modes.py`).

Adds:
- `test_cluster_array_missing_job_number_raises` -- omission
  surfaces as a clean TypeError instead of a deep KeyError.
- `TestUnifiedEvaluateSignatures` -- introspection tests pinning
  the contract: all five evaluators must share the first three
  positional parameters and all must accept `**kwargs`.

Fix #309

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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