Skip to content

Commit

Permalink
feat!: remove verbose parameter (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicrie authored Sep 1, 2024
1 parent de9eaa7 commit 2fd90dd
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 89 deletions.
9 changes: 2 additions & 7 deletions xeofs/data_container/data_container.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Dict

import dask
from dask.diagnostics.progress import ProgressBar
from typing_extensions import Self

try:
Expand Down Expand Up @@ -52,13 +51,9 @@ def deserialize(cls, dt: DataTree) -> Self:
container._allow_compute[key] = node.attrs["allow_compute"]
return container

def compute(self, verbose=False, **kwargs):
def compute(self, **kwargs):
computed_data = {k: v for k, v in self.items() if self._allow_compute[k]}
if verbose:
with ProgressBar():
(computed_data,) = dask.compute(computed_data, **kwargs)
else:
(computed_data,) = dask.compute(computed_data, **kwargs)
(computed_data,) = dask.compute(computed_data, **kwargs)
for k, v in computed_data.items():
self[k] = v

Expand Down
11 changes: 2 additions & 9 deletions xeofs/models/_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import dask.base
import xarray as xr
from dask.diagnostics.progress import ProgressBar
from typing_extensions import Self

from .._version import __version__
Expand Down Expand Up @@ -54,13 +53,11 @@ def get_serialization_attrs(self) -> dict:
"""Get the attributes to serialize."""
raise NotImplementedError

def compute(self, verbose: bool = False, **kwargs):
def compute(self, **kwargs):
"""Compute and load delayed model results.
Parameters
----------
verbose : bool
Whether or not to provide additional information about the computing progress.
**kwargs
Additional keyword arguments to pass to `dask.compute()`.
"""
Expand All @@ -74,11 +71,7 @@ def compute(self, verbose: bool = False, **kwargs):
if data_is_dask(v) and v.attrs.get("allow_compute", True)
}

if verbose:
with ProgressBar():
(data_objs,) = dask.base.compute(data_objs, **kwargs)
else:
(data_objs,) = dask.base.compute(data_objs, **kwargs)
(data_objs,) = dask.base.compute(data_objs, **kwargs)

for k, v in data_objs.items():
dt[k] = DataTree(v)
Expand Down
11 changes: 0 additions & 11 deletions xeofs/models/_base_model_cross_set.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import warnings
from abc import abstractmethod
from typing import Any, Hashable, Sequence

Expand Down Expand Up @@ -80,19 +79,11 @@ def __init__(
alpha: Sequence[float] | float = 1.0,
solver: Sequence[str] | str = "auto",
compute: bool = True,
verbose: bool = False,
sample_name: str = "sample",
feature_name: Sequence[str] | str = "feature",
random_state: Generator | int | None = None,
solver_kwargs: dict[str, Any] = {},
):
if verbose:
warnings.warn(
"The 'verbose' parameter is deprecated and will be removed in a future release.",
category=DeprecationWarning,
stacklevel=3,
)

super().__init__()

# Process parameters
Expand Down Expand Up @@ -134,7 +125,6 @@ def __init__(
"sample_name": sample_name,
"feature_name": feature_name,
"random_state": random_state,
"verbose": verbose,
"compute": compute,
"solver": solver,
}
Expand All @@ -145,7 +135,6 @@ def __init__(
"solver": solver,
"random_state": random_state,
"compute": compute,
"verbose": False,
"solver_kwargs": solver_kwargs,
}

Expand Down
13 changes: 0 additions & 13 deletions xeofs/models/_base_model_single_set.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import warnings
from abc import abstractmethod
from typing import (
Hashable,
Expand Down Expand Up @@ -49,8 +48,6 @@ class _BaseModelSingleSet(_BaseModel):
If True, four pieces of the fit will be computed sequentially: 1) the
preprocessor scaler, 2) optional NaN checks, 3) SVD decomposition, 4) scores
and components.
verbose: bool, default=False
Whether to show a progress bar when computing the decomposition.
random_state: int | None, default=None
Seed for the random number generator.
solver: {"auto", "full", "randomized"}, default="auto"
Expand All @@ -70,18 +67,10 @@ def __init__(
sample_name="sample",
feature_name="feature",
compute=True,
verbose=False,
random_state=None,
solver="auto",
solver_kwargs={},
):
if verbose:
warnings.warn(
"The 'verbose' parameter is deprecated and will be removed in a future release.",
category=DeprecationWarning,
stacklevel=3,
)

super().__init__()

self.n_modes = n_modes
Expand All @@ -98,7 +87,6 @@ def __init__(
"sample_name": sample_name,
"feature_name": feature_name,
"random_state": random_state,
"verbose": verbose,
"compute": compute,
"solver": solver,
"solver_kwargs": solver_kwargs,
Expand All @@ -108,7 +96,6 @@ def __init__(
"solver": solver,
"random_state": random_state,
"compute": compute,
"verbose": verbose,
"solver_kwargs": solver_kwargs,
}

Expand Down
3 changes: 0 additions & 3 deletions xeofs/models/_np_classes/_sparse_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,6 @@ def compute_rspca(
tol : float, (default ``tol = 1e-5``).
Stopping tolerance for reconstruction error.
verbose : bool ``{'True', 'False'}``, optional (default ``verbose = True``).
Display progress.
oversample : integer, optional (default: 10)
Controls the oversampling of column space. Increasing this parameter
may improve numerical accuracy.
Expand Down
4 changes: 0 additions & 4 deletions xeofs/models/_np_classes/_svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class _SVD:
and optionally truncated afterwards.
random_state : np.random.Generator | int | None, default=None
Seed for the random number generator.
verbose: bool, default=False
Whether to show a progress bar when computing the decomposition.
solver_kwargs : dict, default={}
Additional keyword arguments passed to the SVD solver.
"""
Expand All @@ -67,7 +65,6 @@ def __init__(
flip_signs: bool = True,
solver: str = "auto",
random_state: np.random.Generator | int | None = None,
verbose: bool = False,
solver_kwargs: dict = {},
):
sanity_check_n_modes(n_modes)
Expand All @@ -83,7 +80,6 @@ def __init__(
self.n_modes_precompute = n_modes
self.init_rank_reduction = init_rank_reduction
self.flip_signs = flip_signs
self.verbose = verbose
self.solver = solver
self.random_state = random_state
self.solver_kwargs = solver_kwargs
Expand Down
6 changes: 0 additions & 6 deletions xeofs/models/cpcca.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def __init__(
pca_init_rank_reduction: Sequence[float] | float = 0.3,
check_nans: Sequence[bool] | bool = True,
compute: bool = True,
verbose: bool = False,
sample_name: str = "sample",
feature_name: Sequence[str] | str = "feature",
solver: str = "auto",
Expand All @@ -151,7 +150,6 @@ def __init__(
pca_init_rank_reduction=pca_init_rank_reduction,
alpha=alpha,
compute=compute,
verbose=verbose,
sample_name=sample_name,
feature_name=feature_name,
solver=solver,
Expand Down Expand Up @@ -1128,7 +1126,6 @@ def __init__(
n_pca_modes: Sequence[float | int | str] | float | int | str = 0.999,
pca_init_rank_reduction: Sequence[float] | float = 0.3,
compute: bool = True,
verbose: bool = True,
sample_name: str = "sample",
feature_name: Sequence[str] | str = "feature",
solver: str = "auto",
Expand All @@ -1146,7 +1143,6 @@ def __init__(
pca_init_rank_reduction=pca_init_rank_reduction,
alpha=alpha,
compute=compute,
verbose=verbose,
sample_name=sample_name,
feature_name=feature_name,
solver=solver,
Expand Down Expand Up @@ -1402,7 +1398,6 @@ def __init__(
n_pca_modes: Sequence[float | int | str] | float | int | str = 0.999,
pca_init_rank_reduction: Sequence[float] | float = 0.3,
compute: bool = True,
verbose: bool = True,
sample_name: str = "sample",
feature_name: Sequence[str] | str = "feature",
solver: str = "auto",
Expand All @@ -1420,7 +1415,6 @@ def __init__(
pca_init_rank_reduction=pca_init_rank_reduction,
alpha=alpha,
compute=compute,
verbose=verbose,
sample_name=sample_name,
feature_name=feature_name,
solver=solver,
Expand Down
12 changes: 1 addition & 11 deletions xeofs/models/decomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import xarray as xr
from dask.array import Array as DaskArray # type: ignore
from dask.array.linalg import svd_compressed as dask_svd
from dask.diagnostics.progress import ProgressBar
from scipy.sparse.linalg import svds as complex_svd # type: ignore
from sklearn.utils.extmath import randomized_svd

Expand Down Expand Up @@ -38,8 +37,6 @@ class Decomposer:
and optionally truncated afterwards.
random_state : np.random.Generator | int | None, default=None
Seed for the random number generator.
verbose: bool, default=False
Whether to show a progress bar when computing the decomposition.
component_dim_name : str, default='mode'
Name of the component dimension in the output DataArrays.
solver_kwargs : dict, default={}
Expand All @@ -54,7 +51,6 @@ def __init__(
compute: bool = True,
solver: str = "auto",
random_state: np.random.Generator | int | None = None,
verbose: bool = False,
component_dim_name: str = "mode",
solver_kwargs: dict = {},
):
Expand All @@ -72,7 +68,6 @@ def __init__(
self.init_rank_reduction = init_rank_reduction
self.flip_signs = flip_signs
self.compute = compute
self.verbose = verbose
self.solver = solver
self.random_state = random_state
self.component_dim_name = component_dim_name
Expand Down Expand Up @@ -299,10 +294,5 @@ def _compute_svd_result(self, U, s, VT):
case False:
pass
case True:
match self.verbose:
case True:
with ProgressBar():
U, s, VT = dask.compute(U, s, VT)
case False:
U, s, VT = dask.compute(U, s, VT)
U, s, VT = dask.compute(U, s, VT)
return U, s, VT
12 changes: 0 additions & 12 deletions xeofs/models/eof.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class EOF(_BaseModelSingleSet):
If True, four pieces of the fit will be computed sequentially: 1) the
preprocessor scaler, 2) optional NaN checks, 3) SVD decomposition, 4) scores
and components.
verbose: bool, default=False
Whether to show a progress bar when computing the decomposition.
random_state : Optional[int], default=None
Seed for the random number generator.
solver: {"auto", "full", "randomized"}, default="auto"
Expand All @@ -64,7 +62,6 @@ def __init__(
sample_name: str = "sample",
feature_name: str = "feature",
compute: bool = True,
verbose: bool = False,
random_state: Optional[int] = None,
solver: str = "auto",
solver_kwargs: Dict = {},
Expand All @@ -79,7 +76,6 @@ def __init__(
sample_name=sample_name,
feature_name=feature_name,
compute=compute,
verbose=verbose,
random_state=random_state,
solver=solver,
solver_kwargs=solver_kwargs,
Expand Down Expand Up @@ -278,8 +274,6 @@ class ComplexEOF(EOF):
computation. If True, four pieces of the fit will be computed
sequentially: 1) the preprocessor scaler, 2) optional NaN checks, 3) SVD
decomposition, 4) scores and components.
verbose: bool, default=False
Whether to show a progress bar when computing the decomposition.
random_state : Optional[int], default=None
Seed for the random number generator.
solver: {"auto", "full", "randomized"}, default="auto"
Expand Down Expand Up @@ -318,7 +312,6 @@ def __init__(
sample_name: str = "sample",
feature_name: str = "feature",
compute: bool = True,
verbose: bool = False,
random_state: Optional[int] = None,
solver: str = "auto",
solver_kwargs: Dict = {},
Expand All @@ -333,7 +326,6 @@ def __init__(
sample_name=sample_name,
feature_name=feature_name,
compute=compute,
verbose=verbose,
random_state=random_state,
solver=solver,
solver_kwargs=solver_kwargs,
Expand Down Expand Up @@ -485,8 +477,6 @@ class HilbertEOF(ComplexEOF):
If True, four pieces of the fit will be computed sequentially: 1) the
preprocessor scaler, 2) optional NaN checks, 3) SVD decomposition, 4) scores
and components.
verbose: bool, default=False
Whether to show a progress bar when computing the decomposition.
random_state : Optional[int], default=None
Seed for the random number generator.
solver: {"auto", "full", "randomized"}, default="auto"
Expand Down Expand Up @@ -522,7 +512,6 @@ def __init__(
sample_name: str = "sample",
feature_name: str = "feature",
compute: bool = True,
verbose: bool = False,
random_state: Optional[int] = None,
solver: str = "auto",
solver_kwargs: Dict = {},
Expand All @@ -537,7 +526,6 @@ def __init__(
sample_name=sample_name,
feature_name=feature_name,
compute=compute,
verbose=verbose,
random_state=random_state,
solver=solver,
solver_kwargs=solver_kwargs,
Expand Down
Loading

0 comments on commit 2fd90dd

Please sign in to comment.