Skip to content

Commit

Permalink
Fix GenerationStrategy and GenerataionNode todos (#330)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/Ax#2142

Pull Request resolved: #330

In this diff we update the Ax GenerationStrategy code to remove all todos related to aepsych, and use the standard GS code flow for aepsych usecases. This required some minimal updates to the aepsych criterion and one of the storage tests.

In following diffs we will:
- revisit storage
- update AEPsych GSs as needed
- determine if run indefinetly can be replaced by simply having gen_unlimited_trials = true

Reviewed By: lena-kashtelyan

Differential Revision: D52898268

fbshipit-source-id: 4cc98b100c26aed052322f13ae103455733e1606
  • Loading branch information
mgarrard authored and facebook-github-bot committed Jan 31, 2024
1 parent 22ea32d commit dcda999
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
21 changes: 17 additions & 4 deletions aepsych/generators/completion_criterion/min_asks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@


class MinAsks(TransitionCriterion, ConfigurableMixin):
def __init__(self, threshold: int) -> None:
def __init__(
self,
threshold: int,
block_transition_if_unmet: Optional[bool] = True,
block_gen_if_met: Optional[bool] = False,
) -> None:
self.threshold = threshold

def is_met(self, experiment: Experiment) -> bool:
super().__init__(
block_transition_if_unmet=block_transition_if_unmet,
block_gen_if_met=block_gen_if_met,
)

def is_met(
self, experiment: Experiment, trials_from_node: Optional[Set[int]] = None
) -> bool:
return experiment.num_asks >= self.threshold

def block_continued_generation_error(
Expand All @@ -32,5 +43,7 @@ def block_continued_generation_error(
@classmethod
def get_config_options(cls, config: Config, name: str) -> Dict[str, Any]:
min_asks = config.getint(name, "min_asks", fallback=1)
options = {"threshold": min_asks}
options = {
"threshold": min_asks,
}
return options
13 changes: 11 additions & 2 deletions aepsych/generators/completion_criterion/run_indefinitely.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@


class RunIndefinitely(TransitionCriterion, ConfigurableMixin):
def __init__(self, run_indefinitely: bool) -> None:
def __init__(
self,
run_indefinitely: bool,
block_transition_if_unmet: Optional[bool] = False,
block_gen_if_met: Optional[bool] = False,
) -> None:
self.run_indefinitely = run_indefinitely
self.block_transition_if_unmet = block_transition_if_unmet
self.block_gen_if_met = block_gen_if_met

def is_met(self, experiment: Experiment) -> bool:
def is_met(
self, experiment: Experiment, trials_from_node: Optional[Set[int]] = None
) -> bool:
return not self.run_indefinitely

def block_continued_generation_error(
Expand Down

0 comments on commit dcda999

Please sign in to comment.