Coverage for adrs/search/search.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-08-29 04:28 +0800

1from abc import abstractmethod 

2from typing import Any, Sequence 

3from numpy.typing import ArrayLike 

4 

5type ParameterGrid = dict[str, ArrayLike] 

6type Permutation = dict[str, Any] 

7 

8 

9class Search: 

10 """ 

11 Search represents a search function that takes in a grid of parameters and return 

12 a set of permutations of the parameter grid. 

13 

14 It can be expressed mathematically as: 

15 

16 * f(grid) -> ys 

17 

18 There are ton of permutations while performing hyperparameter-tuning hence a 

19 good search function helps reduce the computation needed to perform such operation 

20 by cutting down the problem space. 

21 """ 

22 

23 @staticmethod 

24 @abstractmethod 

25 def id() -> str: 

26 """A name of identifier for the search.""" 

27 raise NotImplementedError("All search should have an identifier.") 

28 

29 @abstractmethod 

30 def search(self, grid: ParameterGrid) -> Sequence[Permutation]: 

31 raise NotImplementedError(f"Search {self.id()} does not implement search().") 

32 

33 @abstractmethod 

34 def filter[T](self, permutations: Sequence[T]) -> Sequence[T]: 

35 raise NotImplementedError(f"Search {self.id()} does not implement filter().")