[Data] Refactor Planner to avoid storing plan-specific state#53955
Merged
bveeramani merged 2 commits intomasterfrom Jun 19, 2025
Merged
[Data] Refactor Planner to avoid storing plan-specific state#53955bveeramani merged 2 commits intomasterfrom
Planner to avoid storing plan-specific state#53955bveeramani merged 2 commits intomasterfrom
Conversation
Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu> [Data] Insert checkpoint layers during planning instead of during physical optimization (#1860) Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Planner to remove plan-specific state by replacing direct instantiations of Planner with a factory function (create_planner), and updates the planning logic to use a functional approach with a mapping of logical operator types to planning functions.
- Replace direct Planner instantiation with create_planner in tests and logical optimizers.
- Change the PLAN_LOGICAL_OP_FNS collection from a list to a dictionary and update the planning recursion accordingly.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| python/ray/data/tests/test_randomize_block_order.py | Updated Planner instantiation to use create_planner |
| python/ray/data/tests/test_operator_fusion.py | Updated multiple Planner instantiations with create_planner |
| python/ray/data/tests/test_execution_optimizer.py | Replaced Planner() calls with create_planner() in tests |
| python/ray/data/_internal/planner/planner.py | Refactored internal planning logic and mapping collection |
| python/ray/data/_internal/planner/init.py | Added create_planner factory method |
| python/ray/data/_internal/logical/optimizers.py | Updated get_execution_plan to use create_planner |
Comments suppressed due to low confidence (1)
python/ray/data/_internal/planner/planner.py:182
- The function plan_recursively's return type annotation and its docstring appear to be mismatched; the docstring suggests a mapping from physical to logical operators, while the annotation indicates Dict[LogicalOperator, PhysicalOperator]. Consider updating the annotation and docstring to accurately reflect that the mapping is from PhysicalOperator to LogicalOperator.
def plan_recursively(
Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
| """ | ||
|
|
||
| def __init__(self): | ||
| self._physical_op_to_logical_op: Dict[PhysicalOperator, LogicalOperator] = {} |
Contributor
There was a problem hiding this comment.
@bveeramani i don't think there's anything wrong with the planner being stateful component
I think issue you're running into could be addressed much more easily:
- Make Planner.plan class/static method
- Planner.plan initializes planner and makes sure that instances aren't shared b/w invocations
raulchen
approved these changes
Jun 19, 2025
minerharry
pushed a commit
to minerharry/ray
that referenced
this pull request
Jun 27, 2025
…roject#53955) <!-- Thank you for your contribution! Please review https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? <!-- Please give a short summary of the change and the problem this solves. --> The current `Planner` implementation stores plan-specific state (like the `op_map`) as a class attribute. This makes the planner technically stateful across calls, which could lead to incorrect results if `.plan()` is called multiple times on the same instance: ``` planner = Planner() planner.plan(logical_plan1) # This will lead to incorrect results because it reuses state form the first plan planner.plan(logical_plan2) ``` While this doesn’t currently happen in practice, it’s fragile and could easily lead to bugs. This PR refactors the planner to avoid storing any state tied to a specific plan, making it safe to reuse across multiple calls. ## Related issue number <!-- For example: "Closes ray-project#1234" --> ## Checks - [ ] I've signed off every commit(by using the -s flag, i.e., `git commit -s`) in this PR. - [ ] I've run `scripts/format.sh` to lint the changes in this PR. - [ ] I've included any doc changes needed for https://docs.ray.io/en/master/. - [ ] I've added any new APIs to the API Reference. For example, if I added a method in Tune, I've added it in `doc/source/tune/api/` under the corresponding `.rst` file. - [ ] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/ - Testing Strategy - [ ] Unit tests - [ ] Release tests - [ ] This PR is not tested :( --------- Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
elliot-barn
pushed a commit
that referenced
this pull request
Jul 2, 2025
<!-- Thank you for your contribution! Please review https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? <!-- Please give a short summary of the change and the problem this solves. --> The current `Planner` implementation stores plan-specific state (like the `op_map`) as a class attribute. This makes the planner technically stateful across calls, which could lead to incorrect results if `.plan()` is called multiple times on the same instance: ``` planner = Planner() planner.plan(logical_plan1) # This will lead to incorrect results because it reuses state form the first plan planner.plan(logical_plan2) ``` While this doesn’t currently happen in practice, it’s fragile and could easily lead to bugs. This PR refactors the planner to avoid storing any state tied to a specific plan, making it safe to reuse across multiple calls. ## Related issue number <!-- For example: "Closes #1234" --> ## Checks - [ ] I've signed off every commit(by using the -s flag, i.e., `git commit -s`) in this PR. - [ ] I've run `scripts/format.sh` to lint the changes in this PR. - [ ] I've included any doc changes needed for https://docs.ray.io/en/master/. - [ ] I've added any new APIs to the API Reference. For example, if I added a method in Tune, I've added it in `doc/source/tune/api/` under the corresponding `.rst` file. - [ ] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/ - Testing Strategy - [ ] Unit tests - [ ] Release tests - [ ] This PR is not tested :( --------- Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu> Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
snorkelopsstgtesting1-spec
pushed a commit
to snorkel-marlin-repos/ray-project_ray_pr_53955_d6a41f93-e10a-44d7-b4c3-8d181e0cde7d
that referenced
this pull request
Oct 22, 2025
Original PR #53955 by bveeramani Original: ray-project/ray#53955
snorkelopstesting4-web
added a commit
to snorkel-marlin-repos/ray-project_ray_pr_53955_d6a41f93-e10a-44d7-b4c3-8d181e0cde7d
that referenced
this pull request
Oct 22, 2025
…n-specific state Merged from original PR #53955 Original: ray-project/ray#53955
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.
Why are these changes needed?
The current
Plannerimplementation stores plan-specific state (like theop_map) as a class attribute. This makes the planner technically stateful across calls, which could lead to incorrect results if.plan()is called multiple times on the same instance:While this doesn’t currently happen in practice, it’s fragile and could easily lead to bugs.
This PR refactors the planner to avoid storing any state tied to a specific plan, making it safe to reuse across multiple calls.
Related issue number
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.