utils.py (605B)
1 import networkx as nx 2 import torch 3 import numpy as np 4 import random 5 6 def load_graph_from_path(path: str) -> nx.Graph: 7 ''' 8 Load a graph from a given path. 9 10 Args: 11 path (str): The path to the graph file. 12 13 Returns: 14 G (networkx.Graph): The loaded graph. 15 16 ''' 17 G = nx.read_graphml(f'{path}') 18 return G 19 20 def set_seed(seed: int) -> None: 21 torch.manual_seed(seed) 22 torch.cuda.manual_seed(seed) 23 torch.cuda.manual_seed_all(seed) 24 np.random.seed(seed) 25 random.seed(seed) 26 torch.backends.cudnn.benchmark = False 27 torch.backends.cudnn.deterministic = True