tests.test_optimizers.test_memory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 27
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test_memory_0() 0 23 1
A objective_function() 0 4 1
1
"""Test module for optimizer memory functionality."""
2
3
import numpy as np
4
import pytest
5
6
from hyperactive import Hyperactive
7
8
from ._parametrize import optimizers
9
10
11
def objective_function(opt):
12
    """Return simple quadratic objective function for memory testing."""
13
    score = -opt["x1"] * opt["x1"]
14
    return score
15
16
17
search_space = {"x1": list(np.arange(-10, 11, 1))}
18
19
20
@pytest.mark.parametrize(*optimizers)
21
def test_memory_0(Optimizer):
22
    """Test memory functionality with multiple search runs."""
23
    optimizer = Optimizer()
24
25
    n_iter = 30
26
27
    hyper = Hyperactive()
28
    hyper.add_search(
29
        objective_function,
30
        search_space,
31
        optimizer=optimizer,
32
        n_iter=n_iter,
33
        n_jobs=2,
34
    )
35
    hyper.add_search(
36
        objective_function,
37
        search_space,
38
        optimizer=optimizer,
39
        n_iter=n_iter,
40
        n_jobs=2,
41
    )
42
    hyper.run()
43