MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / ApplicationMixin

Class ApplicationMixin

python/graphvite/application/application.py:38–241  ·  view source on GitHub ↗

General interface of graph applications. Parameters: dim (int): dimension of embeddings gpus (list of int, optional): GPU ids, default is all GPUs cpu_per_gpu (int, optional): number of CPU threads per GPU, default is all CPUs gpu_memory_limit (int, optional

Source from the content-addressed store, hash-verified

36
37
38class ApplicationMixin(object):
39 """
40 General interface of graph applications.
41
42 Parameters:
43 dim (int): dimension of embeddings
44 gpus (list of int, optional): GPU ids, default is all GPUs
45 cpu_per_gpu (int, optional): number of CPU threads per GPU, default is all CPUs
46 gpu_memory_limit (int, optional): memory limit per GPU in bytes, default is all memory
47 float_type (dtype, optional): type of parameters
48 index_type (dtype, optional): type of graph indexes
49 """
50 def __init__(self, dim, gpus=[], cpu_per_gpu=auto, gpu_memory_limit=auto,
51 float_type=cfg.float_type, index_type=cfg.index_type):
52 self.dim = dim
53 self.gpus = gpus
54 self.cpu_per_gpu = cpu_per_gpu
55 self.gpu_memory_limit = gpu_memory_limit
56 self.float_type = float_type
57 self.index_type = index_type
58 self.set_format()
59
60 def get_graph(self, **kwargs):
61 raise NotImplementedError
62
63 def get_solver(self, **kwargs):
64 raise NotImplementedError
65
66 def set_format(self, delimiters=" \t\r\n", comment="#"):
67 """
68 Set the format for parsing input data.
69
70 Parameters:
71 delimiters (str, optional): string of delimiter characters
72 comment (str, optional): prefix of comment strings
73 """
74 self.delimiters = delimiters
75 self.comment = comment
76 self.pattern = re.compile("[%s]" % self.delimiters)
77
78 @monitor.time
79 def load(self, **kwargs):
80 """load(**kwargs)
81 Load a graph from file or Python object.
82 Arguments depend on the underlying graph type.
83 """
84 self.graph = self.get_graph(**kwargs)
85 if "file_name" in kwargs or "vector_file" in "kwargs":
86 self.graph.load(delimiters=self.delimiters, comment=self.comment, **kwargs)
87 else:
88 self.graph.load(**kwargs)
89
90 @monitor.time
91 def build(self, **kwargs):
92 """build(**kwargs)
93 Build the solver from the graph.
94 Arguments depend on the underlying solver type.
95 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected