feat: mcts policy based on trace scheduler - #1203
Merged
Merged
Conversation
you-n-g
reviewed
Sep 12, 2025
| self.trace.set_current_selection(exp.local_selection) | ||
| self.trace.sync_dag_parent_and_hist((exp, prev_out["feedback"]), cur_loop_id) | ||
| # Notify MCTS scheduler for value backpropagation | ||
| scheduler = getattr(self.exp_gen, "trace_scheduler", None) |
Contributor
There was a problem hiding this comment.
Can we put these logic in exp_gen, and make the framework less complicated.
| self.trace_scheduler: TraceScheduler = import_class(DS_RD_SETTING.trace_scheduler)( | ||
| DS_RD_SETTING.max_trace_num, | ||
| DS_RD_SETTING.scheduler_temperature, | ||
| c_puct=DS_RD_SETTING.scheduler_c_puct, |
Contributor
There was a problem hiding this comment.
I think we should put it into the specific schedular to make it more general
you-n-g
reviewed
Sep 12, 2025
| scheduler = getattr(self.exp_gen, "trace_scheduler", None) | ||
| if isinstance(scheduler, MCTSScheduler): | ||
| try: | ||
| scheduler.reset() |
you-n-g
reviewed
Sep 12, 2025
| logger.log_object(self.trace, tag="trace before restart") | ||
| self.trace = DSTrace(scen=self.trace.scen, knowledge_base=self.trace.knowledge_base) | ||
| # Reset the trace; MCTS stats will be cleared via registered callback | ||
| self.trace.reset() |
|
|
||
| self.uncommitted_experiments: dict[int, DSExperiment] = {} # loop_id -> DSExperiment | ||
|
|
||
| def reset(self) -> None: |
Contributor
There was a problem hiding this comment.
Trace does not need reset.
| if callable(fn): | ||
| self._on_reset_callbacks.append(fn) | ||
|
|
||
| def reset(self) -> None: |
Contributor
There was a problem hiding this comment.
Override def reset for ParallelMultiTraceExpGen
you-n-g
reviewed
Sep 12, 2025
|
|
||
| # Register MCTS reset callback so trace.reset() can cascade to MCTS stats reset | ||
| scheduler = getattr(self.exp_gen, "trace_scheduler", None) | ||
| if isinstance(scheduler, MCTSScheduler): |
you-n-g
reviewed
Oct 14, 2025
| reward = 0.0 | ||
|
|
||
| # Attribute the reward to the immediate parent leaf that was expanded | ||
| parent_tuple = trace.dag_parent[new_idx] if 0 <= new_idx < len(trace.dag_parent) else () |
| if trace.sub_trace_count + self.uncommited_rec_status[trace.NEW_ROOT] < self.max_trace_num: | ||
| return trace.NEW_ROOT | ||
|
|
||
| # Step 2: consider only available leaves (not being expanded) |
Contributor
There was a problem hiding this comment.
You can't only calculate UCT on leaves
you-n-g
reviewed
Oct 14, 2025
| # Avoid div-by-zero; encourage exploration when visits are small | ||
| return self.c_puct * prior * math.sqrt(max(1, self.global_visit_count)) / (1 + visits) | ||
|
|
||
| def select(self, trace: DSTrace) -> tuple[int, ...] | None: |
you-n-g
reviewed
Oct 14, 2025
| else: | ||
| # New root expansion: no parent leaf to credit; optional: keep a pseudo key | ||
| pass | ||
| except Exception as e: |
you-n-g
reviewed
Oct 14, 2025
| for idx in range(start_idx, end_idx): | ||
| self.observe_feedback(trace, idx) | ||
| self.last_observed_commit_idx = end_idx | ||
| except Exception as e: |
you-n-g
reviewed
Oct 17, 2025
| new_idx: Index of the newly appended experiment in trace.hist. | ||
| reward: Optional explicit reward. If None, derive from feedback.decision (1.0/0.0). | ||
| """ | ||
| if reward is None: |
| reward: Optional explicit reward. If None, derive from feedback.decision (1.0/0.0). | ||
| """ | ||
| if reward is None: | ||
| if 0 <= new_idx < len(trace.hist): |
Hoder-zyf
added a commit
that referenced
this pull request
Oct 21, 2025
* init mcts class * full ver of MCTS * auto-lint * make MCTS feedback in exp-gen() * refactor: move reset logic from Trace to ExpGen and update usage accordingly * fix: reinitialize trace on consecutive errors in DataScienceRDLoop * feat: add reset method to BaseScheduler and call in MCTSScheduler reset * style: reorder imports for consistency and PEP8 compliance * lint * fix observe_feedback * fix bug * remove uncommited_rec_status * more simple * refactor: move commit observation logic to process_uncommitted_nodes method * docs: add TODO comment about rule-based virtual root node expansion * add score reward * fix bug * fix small bug * lint * change reward * lint --------- Co-authored-by: Young <afe.young@gmail.com> Co-authored-by: jingyuanlm <842442862@qq.com> Co-authored-by: amstrongzyf <amstrongzyf@126.com>
licong01-cloud
pushed a commit
to licong01-cloud/RD-Agent
that referenced
this pull request
Dec 13, 2025
* init mcts class * full ver of MCTS * auto-lint * make MCTS feedback in exp-gen() * refactor: move reset logic from Trace to ExpGen and update usage accordingly * fix: reinitialize trace on consecutive errors in DataScienceRDLoop * feat: add reset method to BaseScheduler and call in MCTSScheduler reset * style: reorder imports for consistency and PEP8 compliance * lint * fix observe_feedback * fix bug * remove uncommited_rec_status * more simple * refactor: move commit observation logic to process_uncommitted_nodes method * docs: add TODO comment about rule-based virtual root node expansion * add score reward * fix bug * fix small bug * lint * change reward * lint --------- Co-authored-by: Young <afe.young@gmail.com> Co-authored-by: jingyuanlm <842442862@qq.com> Co-authored-by: amstrongzyf <amstrongzyf@126.com>
yongbin4
pushed a commit
to yongbin4/RD-Agent
that referenced
this pull request
Mar 8, 2026
* init mcts class * full ver of MCTS * auto-lint * make MCTS feedback in exp-gen() * refactor: move reset logic from Trace to ExpGen and update usage accordingly * fix: reinitialize trace on consecutive errors in DataScienceRDLoop * feat: add reset method to BaseScheduler and call in MCTSScheduler reset * style: reorder imports for consistency and PEP8 compliance * lint * fix observe_feedback * fix bug * remove uncommited_rec_status * more simple * refactor: move commit observation logic to process_uncommitted_nodes method * docs: add TODO comment about rule-based virtual root node expansion * add score reward * fix bug * fix small bug * lint * change reward * lint --------- Co-authored-by: Young <afe.young@gmail.com> Co-authored-by: jingyuanlm <842442862@qq.com> Co-authored-by: amstrongzyf <amstrongzyf@126.com>
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.
MCTS policy based on trace scheduler
📚 Documentation preview 📚: https://RDAgent--1203.org.readthedocs.build/en/1203/