-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy path_graph_sampler.py
42 lines (32 loc) · 1.27 KB
/
_graph_sampler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import torch
import typing
from autogl.utils import universal_registry
class GraphSampler(torch.nn.Module, typing.Iterable):
def __iter__(self):
raise NotImplementedError
class SampledSubgraph:
...
class GraphSamplerUniversalRegistry(universal_registry.UniversalRegistryBase):
@classmethod
def register_graph_sampler(cls, name: str) -> typing.Callable[
[typing.Type[GraphSampler]], typing.Type[GraphSampler]
]:
def register_sampler(
graph_sampler: typing.Type[GraphSampler]
) -> typing.Type[GraphSampler]:
if not issubclass(graph_sampler, GraphSampler):
raise TypeError
else:
cls[name] = graph_sampler
return graph_sampler
return register_sampler
@classmethod
def get_graph_sampler(cls, name: str) -> typing.Type[GraphSampler]:
if name not in cls:
raise ValueError(f"Graph Sampler with name \"{name}\" not exist")
else:
return cls[name]
def instantiate_graph_sampler(
graph_sampler_name: str, data, sampler_configurations: typing.Mapping[str, typing.Any], **kwargs
) -> GraphSampler:
return GraphSamplerUniversalRegistry[graph_sampler_name](data, sampler_configurations, **kwargs)