Skip to content

Commit

Permalink
Remove deprecated code (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite authored Jan 16, 2024
1 parent 6364895 commit 3bd6167
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 84 deletions.
8 changes: 1 addition & 7 deletions cubed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
__version__ = "unknown"

from .array_api import Array
from .core.array import (
compute,
measure_reserved_mem,
measure_reserved_memory,
visualize,
)
from .core.array import compute, measure_reserved_mem, visualize
from .core.gufunc import apply_gufunc
from .core.ops import from_array, from_zarr, map_blocks, store, to_zarr
from .nan_functions import nanmean, nansum
Expand All @@ -37,7 +32,6 @@
"from_zarr",
"map_blocks",
"measure_reserved_mem",
"measure_reserved_memory",
"nanmean",
"nansum",
"store",
Expand Down
9 changes: 1 addition & 8 deletions cubed/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# flake8: noqa
from .array import (
CoreArray,
compute,
gensym,
measure_reserved_mem,
measure_reserved_memory,
visualize,
)
from .array import CoreArray, compute, gensym, measure_reserved_mem, visualize
from .gufunc import apply_gufunc
from .ops import (
blockwise,
Expand Down
12 changes: 0 additions & 12 deletions cubed/core/array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from operator import mul
from typing import Optional, TypeVar
from warnings import warn

import numpy as np
from toolz import map, reduce
Expand Down Expand Up @@ -284,17 +283,6 @@ def on_task_end(self, event):
self.peak_measured_mem = event.peak_measured_mem_end


def measure_reserved_memory(
executor: Executor, work_dir: Optional[str] = None, **kwargs
) -> int:
warn(
"`measure_reserved_memory` is deprecated, please use `measure_reserved_mem` instead",
DeprecationWarning,
stacklevel=2,
)
return measure_reserved_mem(executor, work_dir=work_dir, **kwargs)


def measure_reserved_mem(
executor: Executor, work_dir: Optional[str] = None, **kwargs
) -> int:
Expand Down
13 changes: 1 addition & 12 deletions cubed/spec.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Optional, Union
from warnings import warn

from cubed.runtime.types import Executor
from cubed.utils import convert_to_bytes
Expand All @@ -11,7 +10,6 @@ class Spec:
def __init__(
self,
work_dir: Union[str, None] = None,
max_mem: Union[int, None] = None,
allowed_mem: Union[int, str, None] = None,
reserved_mem: Union[int, str, None] = 0,
executor: Union[Executor, None] = None,
Expand All @@ -24,8 +22,6 @@ def __init__(
----------
work_dir : str or None
The directory path (specified as an fsspec URL) used for storing intermediate data.
max_mem : int, optional
**Deprecated**. The maximum memory available to a worker for data use for the computation, in bytes.
allowed_mem : int or str, optional
The total memory available to a worker for running a task, in bytes.
Expand All @@ -41,18 +37,11 @@ def __init__(
Storage options to be passed to fsspec.
"""

if max_mem is not None:
warn(
"`max_mem` is deprecated, please use `allowed_mem` instead",
DeprecationWarning,
stacklevel=2,
)

self._work_dir = work_dir

self._reserved_mem = convert_to_bytes(reserved_mem or 0)
if allowed_mem is None:
self._allowed_mem = (max_mem or 0) + self.reserved_mem
self._allowed_mem = self.reserved_mem
else:
self._allowed_mem = convert_to_bytes(allowed_mem)

Expand Down
82 changes: 37 additions & 45 deletions cubed/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,51 +291,43 @@ def test_different_specs(tmp_path):
xp.add(a, b)


class TestSpecMemArgTypes:
def test_max_mem_deprecation_warning(self):
# Remove once max_mem fully deprecated in favour of allowed_mem
with pytest.warns(
DeprecationWarning,
match="`max_mem` is deprecated, please use `allowed_mem` instead",
):
cubed.Spec(max_mem=100_000)

@pytest.mark.parametrize(
"input_value, expected_value",
[
(500, 500),
(100_000, 100_000),
(50.0, 50),
("500B", 500),
("1kB", 1000),
("1MB", 1000**2),
("1GB", 1000**3),
("1TB", 1000**4),
("1PB", 1000**5),
("100_000", 100_000),
("1.2MB", 1.2 * 1000**2),
("1 MB", 1000**2),
("1.2 MB", 1.2 * 1000**2),
],
)
def test_convert_to_bytes(self, input_value, expected_value):
spec = cubed.Spec(allowed_mem=input_value)
assert spec.allowed_mem == expected_value

@pytest.mark.parametrize(
"input_value",
[
"1EB", # EB is not a valid unit in this function
"1kb", # lower-case k is not valid
"invalid", # completely invalid input
-512, # negative integer
"kB", # only unit, no value
"1.1B", # can't have a fractional number of bytes
],
)
def test_convert_to_bytes_error(self, input_value):
with pytest.raises(ValueError):
cubed.Spec(allowed_mem=input_value)
@pytest.mark.parametrize(
"input_value, expected_value",
[
(500, 500),
(100_000, 100_000),
(50.0, 50),
("500B", 500),
("1kB", 1000),
("1MB", 1000**2),
("1GB", 1000**3),
("1TB", 1000**4),
("1PB", 1000**5),
("100_000", 100_000),
("1.2MB", 1.2 * 1000**2),
("1 MB", 1000**2),
("1.2 MB", 1.2 * 1000**2),
],
)
def test_convert_to_bytes(input_value, expected_value):
spec = cubed.Spec(allowed_mem=input_value)
assert spec.allowed_mem == expected_value


@pytest.mark.parametrize(
"input_value",
[
"1EB", # EB is not a valid unit in this function
"1kb", # lower-case k is not valid
"invalid", # completely invalid input
-512, # negative integer
"kB", # only unit, no value
"1.1B", # can't have a fractional number of bytes
],
)
def test_convert_to_bytes_error(input_value):
with pytest.raises(ValueError):
cubed.Spec(allowed_mem=input_value)


def test_reduction_multiple_rounds(tmp_path, executor):
Expand Down

0 comments on commit 3bd6167

Please sign in to comment.