Repository navigation
Share GridOptimizer candidate evaluation - #47
Merged
Merged
Conversation
The initial-direction check and the random-candidate loop in GridOptimizer._optimize_sequential each wrote the candidate into best_directions, built the objective arguments and called the objective on the first component + 1 directions. That step is now _evaluate_direction. The `(X, k) if not kwargs else (X, k, *kwargs.values())` branch is collapsed to `(X, k, *kwargs.values())`, which is the same tuple. A new test pins the call protocol (count and order of calls, k, X and kwargs forwarding, in-place write, argmin selection, final evaluation); it passes before and after and fails on two injected mutations. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Duplicated sites
pyppur/optimizers/grid_optimizer.py:129-145(evaluating the supplied initial direction)pyppur/optimizers/grid_optimizer.py:176-192(evaluating each random/perturbed candidate)Both wrote the candidate into
best_directions[component], builtobjective_argsas(X, component + 1)or(X, component + 1, *kwargs.values()), and calledself.objective_func(best_directions[: component + 1].flatten(), *objective_args).How it is shared now
New private method
GridOptimizer._evaluate_direction(X, best_directions, component, direction, kwargs)does the write and the call; both sites call it and keep their own compare-and-keep. The two-branch tuple is collapsed to(X, component + 1, *kwargs.values()): with empty kwargs that is the same tuple, so the objective receives identical arguments. The final all-components evaluation is left as is. Public API unchanged.Numerical identity
Out-of-repo script:
ReconstructionObjectiveandDistanceObjective(withdist_Xkwarg) × initial guess none / full / partial (fewer rows than components) × seeds 0, 7 on 60 standardized digits, 3 components, 15 directions, 3 iterations. Dumped directions, final loss and per-component losses onmainand on this branch: 36/36 arrays bitwise identical (np.array_equal).Tests
Existing grid tests only checked shapes and
loss > 0. Addedtest_grid_optimizer_evaluation_protocolintests/test_optimizer.py, using a recording objective. It pins the number and order of objective calls and theirk, thatXanddist_Xare forwarded positionally, that the first call uses the normalised initial direction, that component 1 is scored with component 0 fixed, the argmin selection andloss_per_component, and the final evaluation. It passes onmainand on this branch. It fails on two injected mutations: passingcomponentinstead ofcomponent + 1(3 failures), and writing-direction(1 failure).Checks
uv run pytestruff check pyppur testsruff format --check pyppur testspyrightpreen check --strict --skip tests(0.7.1)uv.lock)jscpd
uvx jscpd==5.4.2 pyppur --format python --ignore-identifiers=consistent --min-lines 12 --min-tokens 1projection_pursuit.py406-419 ↔ 473-486 ↔ 530-543,utils/visualization.py52-67 ↔ 109-124)🤖 Generated with Claude Code