Code Duplication    Length = 13-13 lines in 3 locations

gradient_free_optimizers/search.py 1 location

@@ 20-32 (lines=13) @@
17
from .stop_run import StopRun
18
19
20
def set_random_seed(nth_process, random_state):
21
    """
22
    Sets the random seed separately for each thread
23
    (to avoid getting the same results in each thread)
24
    """
25
    if nth_process is None:
26
        nth_process = 0
27
28
    if random_state is None:
29
        random_state = np.random.randint(0, high=2 ** 31 - 2, dtype=np.int64)
30
31
    random.seed(random_state + nth_process)
32
    np.random.seed(random_state + nth_process)
33
34
35
class Search(TimesTracker):

gradient_free_optimizers/optimizers/pop_opt/base_population_optimizer.py 1 location

@@ 16-28 (lines=13) @@
13
from ...init_positions import Initializer
14
15
16
def set_random_seed(nth_process, random_state):
17
    """
18
    Sets the random seed separately for each thread
19
    (to avoid getting the same results in each thread)
20
    """
21
    if nth_process is None:
22
        nth_process = 0
23
24
    if random_state is None:
25
        random_state = np.random.randint(0, high=2 ** 31 - 2, dtype=np.int64)
26
27
    random.seed(random_state + nth_process)
28
    np.random.seed(random_state + nth_process)
29
30
31
class BasePopulationOptimizer:

gradient_free_optimizers/optimizers/base_optimizer.py 1 location

@@ 14-26 (lines=13) @@
11
from ..init_positions import Initializer
12
13
14
def set_random_seed(nth_process, random_state):
15
    """
16
    Sets the random seed separately for each thread
17
    (to avoid getting the same results in each thread)
18
    """
19
    if nth_process is None:
20
        nth_process = 0
21
22
    if random_state is None:
23
        random_state = np.random.randint(0, high=2 ** 31 - 2, dtype=np.int64)
24
25
    random.seed(random_state + nth_process)
26
    np.random.seed(random_state + nth_process)
27
28
29
def get_n_inits(initialize):