def binSrchIncorrectStep()

in 1_synthetic-qa-generation/reasoningplaning/evolve.py [0:0]


    def binSrchIncorrectStep(self, s_ast: Nde, steps: List[str], left: int, right: int):
        """
        Recursively call bin search

        Parameters:
        - s_ast (Nde): The selected parent node.
        - steps (List[str]): The branch steps as a list.
        - left (int): Left index of the current search interval.
        - right (int): Right index of the current search interval.
        """
        if left > right:
            return

        mid = (left + right) // 2
        new_steps = steps[left:mid + 1]
        if new_steps:
            prefix_solution = s_ast.solution_prefix + '\n\n' + separateSteps(new_steps, mode='join')
        else:
            assert False
            prefix_solution = s_ast.solution_prefix
        # Create new node s_new
        s_new = Nde(solution_prefix=prefix_solution.strip(), parent=s_ast)
        self.mct.addNode(s_new)
        s_ast.children.append(s_new)

        # Perform Monte Carlo estimate
        self.monteCarloEstimation(s_new)

        if s_new.reward == 0:
            # Found incorrect step; continue searching in the left half to find earlier incorrect steps
            self.binSrchIncorrectStep(s_ast, steps, left, mid - 1)
        else:
            self.binSrchIncorrectStep(s_new, steps, mid + 1, right)