Skip to content

Commit

Permalink
Add a time limit multiplier to all algorithm base tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinT committed Sep 3, 2023
1 parent 131ed83 commit 822d6b3
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions syntheseus/tests/search/algorithms/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class BaseAlgorithmTest(abc.ABC):

# Some tolerances for tests
time_limit_upper_bound_s = 0.05
time_limit_multiplier = 1.0 # can be overridden by subclasses for slower algorithms

@abc.abstractmethod
def setup_algorithm(self, **kwargs) -> SearchAlgorithm:
Expand Down Expand Up @@ -63,7 +64,7 @@ def test_smoke(self, retrosynthesis_task1: RetrosynthesisTask) -> None:
alg = self.setup_algorithm(
reaction_model=retrosynthesis_task1.reaction_model,
mol_inventory=retrosynthesis_task1.inventory,
time_limit_s=0.1,
time_limit_s=0.1 * self.time_limit_multiplier,
limit_iterations=1_000,
limit_reaction_model_calls=10,
)
Expand All @@ -86,7 +87,7 @@ def test_smoke2(self, retrosynthesis_task4: RetrosynthesisTask) -> None:
reaction_model=retrosynthesis_task4.reaction_model,
mol_inventory=retrosynthesis_task4.inventory,
limit_iterations=10_000,
time_limit_s=0.1,
time_limit_s=0.1 * self.time_limit_multiplier,
)
output_graph, _ = alg.run_from_mol(retrosynthesis_task4.target_mol)
assert output_graph.root_node.has_solution
Expand Down Expand Up @@ -139,7 +140,8 @@ def test_limit_reaction_model_calls(
alg = self.setup_algorithm(
reaction_model=retrosynthesis_task1.reaction_model,
mol_inventory=retrosynthesis_task1.inventory,
time_limit_s=1e3, # set a finite but extremely large limit to avoid warnings
time_limit_s=1e3
* self.time_limit_multiplier, # set a finite but extremely large limit to avoid warnings
limit_iterations=INT_INF,
limit_reaction_model_calls=limit,
)
Expand Down Expand Up @@ -214,7 +216,7 @@ def test_max_expansion_depth(
alg = self.setup_algorithm(
reaction_model=retrosynthesis_task1.reaction_model,
mol_inventory=retrosynthesis_task1.inventory,
time_limit_s=0.2,
time_limit_s=0.2 * self.time_limit_multiplier,
limit_iterations=10_000,
limit_reaction_model_calls=1_000,
max_expansion_depth=depth,
Expand Down Expand Up @@ -242,7 +244,7 @@ def test_expand_purchasable_mols(
alg = self.setup_algorithm(
reaction_model=retrosynthesis_task1.reaction_model,
mol_inventory=retrosynthesis_task1.inventory,
time_limit_s=0.1,
time_limit_s=0.1 * self.time_limit_multiplier,
limit_iterations=10_000,
limit_reaction_model_calls=1_000,
max_expansion_depth=4,
Expand Down Expand Up @@ -292,7 +294,7 @@ def test_unique_nodes(
alg = self.setup_algorithm(
reaction_model=retrosynthesis_task5.reaction_model,
mol_inventory=retrosynthesis_task5.inventory,
time_limit_s=0.1,
time_limit_s=0.1 * self.time_limit_multiplier,
limit_iterations=10_000,
limit_reaction_model_calls=100,
max_expansion_depth=10,
Expand Down Expand Up @@ -344,7 +346,7 @@ def test_set_has_solution(
reaction_model=retrosynthesis_task4.reaction_model,
mol_inventory=retrosynthesis_task4.inventory,
limit_iterations=10_000,
time_limit_s=0.1,
time_limit_s=0.1 * self.time_limit_multiplier,
set_has_solution=set_has_solution,
)
output_graph, _ = alg.run_from_mol(retrosynthesis_task4.target_mol)
Expand Down Expand Up @@ -376,7 +378,7 @@ def test_set_depth(self, set_depth: bool, retrosynthesis_task4: RetrosynthesisTa
reaction_model=retrosynthesis_task4.reaction_model,
mol_inventory=retrosynthesis_task4.inventory,
limit_iterations=10_000,
time_limit_s=0.1,
time_limit_s=0.1 * self.time_limit_multiplier,
set_depth=set_depth,
)
output_graph, _ = alg.run_from_mol(retrosynthesis_task4.target_mol)
Expand Down Expand Up @@ -422,7 +424,7 @@ def test_prevent_repeat_mol_in_trees(
alg = self.setup_algorithm(
reaction_model=retrosynthesis_task5.reaction_model,
mol_inventory=SmilesListInventory([]),
time_limit_s=10.0,
time_limit_s=10.0 * self.time_limit_multiplier,
limit_iterations=1_000,
limit_reaction_model_calls=100,
prevent_repeat_mol_in_trees=prevent,
Expand Down Expand Up @@ -478,7 +480,9 @@ def test_found_routes1(self, retrosynthesis_task1: RetrosynthesisTask) -> None:
"""Test that the correct routes are found for a simple example."""

route_objs = self._run_alg_and_extract_routes(
retrosynthesis_task1, time_limit_s=0.1, limit_iterations=10_000
retrosynthesis_task1,
time_limit_s=0.1 * self.time_limit_multiplier,
limit_iterations=10_000,
)
assert len(route_objs) > 2 # should find AT LEAST this many routes

Expand All @@ -491,7 +495,9 @@ def test_found_routes2(self, retrosynthesis_task2: RetrosynthesisTask) -> None:
"""Test that correct routes are found for a more complex example."""

route_objs = self._run_alg_and_extract_routes(
retrosynthesis_task2, time_limit_s=0.2, limit_iterations=10_000
retrosynthesis_task2,
time_limit_s=0.2 * self.time_limit_multiplier,
limit_iterations=10_000,
)
assert len(route_objs) > 5 # should find AT LEAST this many routes

Expand Down Expand Up @@ -519,7 +525,7 @@ def test_stop_on_first_solution(self, retrosynthesis_task1: RetrosynthesisTask)

route_objs = self._run_alg_and_extract_routes(
retrosynthesis_task1,
time_limit_s=0.1,
time_limit_s=0.1 * self.time_limit_multiplier,
limit_iterations=10_000,
stop_on_first_solution=True,
)
Expand Down

0 comments on commit 822d6b3

Please sign in to comment.