Skip to content

Commit

Permalink
feat: require safe-ds version 0.24.0 (#112)
Browse files Browse the repository at this point in the history
### Summary of Changes

Require the latest version of `safe-ds` (0.24.0).
  • Loading branch information
lars-reimann authored May 9, 2024
1 parent 2866863 commit 7236941
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 25 deletions.
115 changes: 104 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ safe-ds-runner = "safeds_runner.main:main"

[tool.poetry.dependencies]
python = "^3.11,<3.13"
safe-ds = ">=0.22.1,<0.23"
safe-ds = ">=0.24.0,<0.25.0"
hypercorn = "^0.16.0"
psutil = "^5.9.8"
pydantic = "^2.7.0"
Expand Down
43 changes: 33 additions & 10 deletions src/safeds_runner/memoization/_memoization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,28 @@ def __hash__(self) -> int:
return hash(self.value)

def __eq__(self, other: object) -> bool:
if isinstance(other, ExplicitIdentityWrapperLazy):
if self.value.__ex_id__ == other.id:
return True
return self.value == other.value
if isinstance(other, ExplicitIdentityWrapper):
return self.value.__ex_id__ == other.value.__ex_id__ or self.value == other.value
if _has_explicit_identity(other) and self.value.__ex_id__ == other.__ex_id__: # type: ignore[attr-defined]
# Compare IDs
if (
isinstance(other, ExplicitIdentityWrapperLazy)
and self.value.__ex_id__ == other.id
or isinstance(other, ExplicitIdentityWrapper)
and self.value.__ex_id__ == other.value.__ex_id__
or _has_explicit_identity(other)
and self.value.__ex_id__ == other.__ex_id__ # type: ignore[attr-defined]
):
return True
return self.value == other

# Compare values
if isinstance(other, ExplicitIdentityWrapper | ExplicitIdentityWrapperLazy):
other_value = other.value
else:
other_value = other

if hasattr(self.value, "_equals"):
# The `==` of cells is vectorized. We need to use the `_equals` method to compare them.
return self.value._equals(other_value)
else:
return self.value == other_value

def __sizeof__(self) -> int:
return self.memory.size
Expand Down Expand Up @@ -144,6 +157,7 @@ def existing(cls, value: Any) -> ExplicitIdentityWrapperLazy:
return cls(value, value.__ex_id_mem__, value.__ex_id__, value.__ex_hash__)

def __eq__(self, other: object) -> bool:
# Compare IDs
if (
isinstance(other, ExplicitIdentityWrapperLazy)
and self.id == other.id
Expand All @@ -153,9 +167,18 @@ def __eq__(self, other: object) -> bool:
and self.id == other.__ex_id__ # type: ignore[attr-defined]
):
return True

# Compare values
if isinstance(other, ExplicitIdentityWrapper | ExplicitIdentityWrapperLazy):
return self.value == other.value
return self.value == other
other_value = other.value
else:
other_value = other

if hasattr(self.value, "_equals"):
# The `==` of cells is vectorized. We need to use the `_equals` method to compare them.
return self.value._equals(other_value)
else:
return self.value == other_value

def __hash__(self) -> int:
return self.hash
Expand Down
4 changes: 1 addition & 3 deletions src/safeds_runner/server/_pipeline_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def save_placeholder(self, placeholder_name: str, value: Any) -> None:
from safeds.data.image.containers import Image

if isinstance(value, Image):
import torch

value = Image(value._image_tensor, torch.device("cpu"))
value = Image(value._image_tensor.cpu())
placeholder_type = _get_placeholder_type(value)
if _is_deterministically_hashable(value) and _has_explicit_identity_memory(value):
value = ExplicitIdentityWrapperLazy.existing(value)
Expand Down
21 changes: 21 additions & 0 deletions tests/safeds_runner/memoization/test_memoization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,24 @@ def test_wrapper_size(value: Any) -> None:
wrapper1 = ExplicitIdentityWrapper.shared(value)
assert sys.getsizeof(wrapper0) > sys.getsizeof(object())
assert sys.getsizeof(wrapper1) > sys.getsizeof(object())


class SpecialEquals:
def __eq__(self, other: object) -> bool:
return False

def __hash__(self) -> int:
return 0

def _equals(self, _other: object) -> bool:
return True


def test_explicit_identity_wrapper_eq() -> None:
assert ExplicitIdentityWrapper.shared(SpecialEquals()) == SpecialEquals()


def test_explicit_identity_wrapper_lazy_eq() -> None:
value = SpecialEquals()
_set_new_explicit_identity_deterministic_hash(value)
assert ExplicitIdentityWrapperLazy.shared(value) == SpecialEquals()

0 comments on commit 7236941

Please sign in to comment.