@@ -328,7 +328,7 @@ def current_generator_run_limit(
328328 generate any more generator runs at all.
329329 """
330330 try :
331- self ._maybe_transition_to_next_node (raise_data_required_error = False )
331+ self .maybe_transition_to_next_node (raise_data_required_error = False )
332332 except GenerationStrategyCompleted :
333333 return 0 , True
334334
@@ -543,7 +543,7 @@ def _gen_with_multiple_nodes(
543543 # reset should skip as conditions may have changed, do not reset
544544 # until now so node properties can be as up to date as possible
545545 node_to_gen_from ._should_skip = False
546- transitioned = self ._maybe_transition_to_next_node ()
546+ transitioned = self ._transition_to_next_node ()
547547 try :
548548 gr = self ._curr .gen (
549549 experiment = experiment ,
@@ -604,24 +604,11 @@ def _should_continue_gen_for_trial(self) -> bool:
604604
605605 # ------------------------- Node selection logic helpers. -------------------------
606606
607- def _maybe_transition_to_next_node (
608- self ,
609- raise_data_required_error : bool = True ,
610- ) -> bool :
611- """Moves this generation strategy to next node if the current node's
612- transition criteria are met. This method is safe to use both when generating
613- candidates or simply checking how many generator runs (to be made into trials)
614- can currently be produced.
615-
616- NOTE: this method raises ``GenerationStrategyCompleted`` error if the
617- optimization is complete
618-
619- Args:
620- raise_data_required_error: Whether to raise ``DataRequiredError`` in the
621- maybe_step_completed method in GenerationNode class.
607+ def _transition_to_next_node (self , raise_data_required_error : bool = True ) -> bool :
608+ """Attempts a single transition to the next node if criteria are met.
622609
623610 Returns:
624- Whether generation strategy moved to the next node.
611+ Whether the generation strategy moved to the next node.
625612 """
626613 move_to_next_node , next_node = self ._curr .should_transition_to_next_node (
627614 raise_data_required_error = raise_data_required_error
@@ -634,3 +621,29 @@ def _maybe_transition_to_next_node(
634621 )
635622 self ._curr = self .nodes_by_name [next_node ]
636623 return move_to_next_node
624+
625+ def maybe_transition_to_next_node (
626+ self , raise_data_required_error : bool = True
627+ ) -> bool :
628+ """Moves this generation strategy to next node if the current node's
629+ transition criteria are met, advancing through multiple nodes if
630+ possible. This method is safe to use both when generating candidates or
631+ simply checking how many generator runs (to be made into trials) can
632+ currently be produced.
633+
634+ NOTE: this method raises ``GenerationStrategyCompleted`` error if the
635+ optimization is complete
636+
637+ Args:
638+ raise_data_required_error: Whether to raise ``DataRequiredError`` in the
639+ maybe_step_completed method in GenerationNode class.
640+
641+ Returns:
642+ Whether generation strategy moved to the next node.
643+ """
644+ moved = False
645+ while self ._transition_to_next_node (
646+ raise_data_required_error = raise_data_required_error
647+ ):
648+ moved = True
649+ return moved
0 commit comments