Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ classifiers=[

dependencies = [
"numpy >=1.18.1, <3.0.0",
"tqdm >=4.48.0, <5.0.0",
"pandas <3.0.0",
"gradient-free-optimizers >=1.2.4, <2.0.0",
"scikit-base <1.0.0",
Expand All @@ -62,6 +61,7 @@ test = [
]
all_extras = [
"hyperactive[integrations]",
"tqdm >=4.48.0, <5.0.0",
]


Expand Down
7 changes: 5 additions & 2 deletions src/hyperactive/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# Email: [email protected]
# License: MIT License

from skbase.utils.dependencies import _check_soft_dependencies
from sys import platform
from tqdm import tqdm

if platform.startswith("linux"):
if platform.startswith("linux") and _check_soft_dependencies("tqdm", severity="none"):
from tqdm import tqdm

# Use tqdm's lock for multiprocessing to avoid issues with progress bars
initializer = tqdm.set_lock
initargs = (tqdm.get_lock(),)
else:
Expand Down
9 changes: 6 additions & 3 deletions src/hyperactive/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
# License: MIT License


from tqdm import tqdm


def _process_(nth_process, optimizer):
if "progress_bar" in optimizer.verbosity:
from skbase.utils.dependencies import _check_soft_dependencies

_check_soft_dependencies("tqdm", obj="progress_bar verbosity")

from tqdm import tqdm

p_bar = tqdm(
position=nth_process,
total=optimizer.n_iter,
Expand Down
9 changes: 8 additions & 1 deletion tests/test_distribution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import sys, pytest
from tqdm import tqdm
from skbase.utils.dependencies import _check_soft_dependencies

from hyperactive import Hyperactive

Expand Down Expand Up @@ -82,7 +82,14 @@ def test_multiprocessing_0():
hyper.run()


@pytest.mark.skipif(
not _check_soft_dependencies("tqdm"),
severity="none",
reason="if soft dependency tqdm is not installed, skip tqdm related tests",
)
def test_multiprocessing_1():
from tqdm import tqdm

hyper = Hyperactive(
distribution={
"multiprocessing": {
Expand Down
12 changes: 10 additions & 2 deletions tests/test_optimizers/test_gfo_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import numpy as np
from skbase.utils.dependencies import _check_soft_dependencies

from tqdm import tqdm
from ._parametrize import optimizers
from hyperactive.search_space import SearchSpace

Expand Down Expand Up @@ -99,6 +99,14 @@ def test_gfo_opt_wrapper_0(Optimizer, search_space, objective):
verbosity=verbosity,
)
opt.max_time = None
opt.search(nth_process=0, p_bar=tqdm(total=n_iter))

if _check_soft_dependencies("tqdm", severity="none"):
from tqdm import tqdm

p_bar_kwargs = {"p_bar": tqdm(total=n_iter)}
else:
p_bar_kwargs = {}

opt.search(nth_process=0, **p_bar_kwargs)

assert opt.best_score == objective_function(opt.best_para)