Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove numpy-based random hint #220

Merged
merged 2 commits into from Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/pykeen/datasets/base.py
Expand Up @@ -20,7 +20,7 @@

from ..constants import PYKEEN_DATASETS
from ..triples import TriplesFactory
from ..typing import RandomHint
from ..typing import TorchRandomHint
from ..utils import normalize_string

__all__ = [
Expand Down Expand Up @@ -520,7 +520,7 @@ def __init__(
eager: bool = False,
create_inverse_triples: bool = False,
delimiter: Optional[str] = None,
random_state: RandomHint = None,
random_state: TorchRandomHint = None,
randomize_cleanup: bool = False,
):
"""Initialize dataset.
Expand Down Expand Up @@ -596,7 +596,7 @@ def __init__(
cache_root: Optional[str] = None,
eager: bool = False,
create_inverse_triples: bool = False,
random_state: RandomHint = None,
random_state: TorchRandomHint = None,
):
"""Initialize dataset.

Expand Down Expand Up @@ -654,7 +654,7 @@ def __init__(
cache_root: Optional[str] = None,
eager: bool = False,
create_inverse_triples: bool = False,
random_state: RandomHint = None,
random_state: TorchRandomHint = None,
read_csv_kwargs: Optional[Mapping[str, Any]] = None,
):
"""Initialize dataset.
Expand Down
4 changes: 2 additions & 2 deletions src/pykeen/datasets/ckg.py
Expand Up @@ -11,7 +11,7 @@
import pandas as pd

from .base import TabbedDataset
from ..typing import RandomHint
from ..typing import TorchRandomHint

__all__ = [
'CKG',
Expand All @@ -34,7 +34,7 @@ def __init__(
self,
eager: bool = False,
create_inverse_triples: bool = False,
random_state: RandomHint = 0,
random_state: TorchRandomHint = 0,
cache_root: Optional[str] = None,
):
super().__init__(
Expand Down
4 changes: 2 additions & 2 deletions src/pykeen/datasets/conceptnet.py
Expand Up @@ -9,7 +9,7 @@
from more_click import verbose_option

from .base import SingleTabbedDataset
from ..typing import RandomHint
from ..typing import TorchRandomHint

URL = 'https://s3.amazonaws.com/conceptnet/downloads/2019/edges/conceptnet-assertions-5.7.0.csv.gz'

Expand All @@ -28,7 +28,7 @@ class ConceptNet(SingleTabbedDataset):
def __init__(
self,
create_inverse_triples: bool = False,
random_state: RandomHint = 0,
random_state: TorchRandomHint = 0,
**kwargs,
):
super().__init__(
Expand Down
4 changes: 2 additions & 2 deletions src/pykeen/datasets/drkg.py
Expand Up @@ -8,7 +8,7 @@
import logging

from .base import TarFileSingleDataset
from ..typing import RandomHint
from ..typing import TorchRandomHint

__all__ = [
'DRKG',
Expand All @@ -29,7 +29,7 @@ class DRKG(TarFileSingleDataset):
def __init__(
self,
create_inverse_triples: bool = False,
random_state: RandomHint = 0,
random_state: TorchRandomHint = 0,
**kwargs,
):
super().__init__(
Expand Down
4 changes: 2 additions & 2 deletions src/pykeen/datasets/hetionet.py
Expand Up @@ -10,7 +10,7 @@
import click

from .base import SingleTabbedDataset
from ..typing import RandomHint
from ..typing import TorchRandomHint

__all__ = [
'Hetionet',
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(
self,
create_inverse_triples: bool = False,
eager: bool = False,
random_state: RandomHint = 0,
random_state: TorchRandomHint = 0,
):
super().__init__(
url=URL,
Expand Down
2 changes: 0 additions & 2 deletions src/pykeen/typing.py
Expand Up @@ -17,7 +17,6 @@
'Constrainer',
'InteractionFunction',
'DeviceHint',
'RandomHint',
'TorchRandomHint',
]

Expand All @@ -34,5 +33,4 @@
Constrainer = Callable[[TensorType], TensorType]

DeviceHint = Union[None, str, torch.device]
RandomHint = Union[None, int, np.random.RandomState]
TorchRandomHint = Union[None, int, torch.Generator]
15 changes: 1 addition & 14 deletions src/pykeen/utils.py
Expand Up @@ -21,7 +21,7 @@
import torch.nn.modules.batchnorm

from .constants import PYKEEN_BENCHMARKS
from .typing import DeviceHint, RandomHint, TorchRandomHint
from .typing import DeviceHint, TorchRandomHint
from .version import get_git_hash

__all__ = [
Expand All @@ -48,7 +48,6 @@
'NoRandomSeedNecessary',
'Result',
'fix_dataclass_init_docs',
'ensure_random_state',
'get_benchmark',
]

Expand Down Expand Up @@ -406,18 +405,6 @@ def random_non_negative_int() -> int:
return int(sq.generate_state(1)[0])


def ensure_random_state(random_state: RandomHint) -> np.random.RandomState:
"""Prepare a random state."""
if random_state is None:
random_state = random_non_negative_int()
logger.warning(f'using automatically assigned random_state={random_state}')
if isinstance(random_state, int):
random_state = np.random.RandomState(random_state)
if not isinstance(random_state, np.random.RandomState):
raise TypeError
return random_state


def ensure_torch_random_state(random_state: TorchRandomHint) -> torch.Generator:
"""Prepare a random state for PyTorch."""
if random_state is None:
Expand Down