Muyi 0.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+ Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ of this software and associated documentation files (the "Software"), to deal
4
+ in the Software without restriction, including without limitation the rights
5
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
+ copies of the Software, and to permit persons to whom the Software is
7
+ furnished to do so, subject to the following conditions:
8
+ The above copyright notice and this permission notice shall be included in all
9
+ copies or substantial portions of the Software.
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: Muyi
3
+ Version: 0.0.0
4
+ Summary: Some useful utils.
5
+ Author: muyiiiii
6
+ Author-email:
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+
14
+ # muyiiiii_graph
15
+
16
+ Some useful utils for GNNs.
@@ -0,0 +1,8 @@
1
+ muyi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ muyi/graph.py,sha256=4okLvgp0TboSpuKtlzXTTbLin2K-RMVxhqJ7CZt6Tps,1145
3
+ muyi/utils.py,sha256=VuuZ0S4CieON-bNHmKqrinTEvmIdfUQF0gXhiapkUnM,1220
4
+ Muyi-0.0.0.dist-info/LICENSE,sha256=GzHS9pi6vw_oGwKIGxAPch8iuVrHazOilEsYL7AlPK0,1085
5
+ Muyi-0.0.0.dist-info/METADATA,sha256=FGffGdElQ4CcBWlVtWz-eu4cnOboef_YGz2ZJhodRhE,400
6
+ Muyi-0.0.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
7
+ Muyi-0.0.0.dist-info/top_level.txt,sha256=3X0xmx0SvmCNEj1ISqmD2evKh_ejCJQaLA4GEbGfKc4,5
8
+ Muyi-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ muyi
muyi/__init__.py ADDED
File without changes
muyi/graph.py ADDED
@@ -0,0 +1,42 @@
1
+ import torch
2
+ import dgl
3
+
4
+ def pyg_data_to_dgl_graph(pyg_data_obj):
5
+ print(pyg_data_obj)
6
+
7
+ # 获取边索引
8
+ edge_index = pyg_data_obj.edge_index
9
+
10
+ # DGL需要的边索引格式是两列的数组,而不是两行的索引
11
+ src, dst = edge_index
12
+ edge_list = torch.stack((src, dst), dim=1)
13
+
14
+ # 创建DGL图
15
+ g = dgl.graph((edge_list[:, 0], edge_list[:, 1]), num_nodes=pyg_data_obj.x.shape[0])
16
+
17
+ # 添加节点特征
18
+ if 'x' in pyg_data_obj:
19
+ g.ndata['feature'] = pyg_data_obj.x
20
+
21
+ # 添加边特征
22
+ if 'edge_attr' in pyg_data_obj:
23
+ g.edata['feat'] = pyg_data_obj.edge_attr
24
+
25
+ # 添加节点标签
26
+ if 'y' in pyg_data_obj:
27
+ g.ndata['label'] = pyg_data_obj.y
28
+
29
+ # 添加节点标签
30
+ if 'train_mask' in pyg_data_obj:
31
+ g.ndata['train_mask'] = pyg_data_obj.train_mask
32
+
33
+ # 添加节点标签
34
+ if 'test_mask' in pyg_data_obj:
35
+ g.ndata['test_mask'] = pyg_data_obj.test_mask
36
+
37
+ # 添加节点标签
38
+ if 'val_mask' in pyg_data_obj:
39
+ g.ndata['val_mask'] = pyg_data_obj.val_mask
40
+
41
+
42
+ return g
muyi/utils.py ADDED
@@ -0,0 +1,39 @@
1
+ import os
2
+ import matplotlib.pyplot as plt
3
+
4
+ import GPUtil
5
+
6
+ def get_gpu_memory_usage():
7
+ # 获取GPU使用情况
8
+ gpus = GPUtil.getGPUs()
9
+ gpu_memory_info = []
10
+ for gpu in gpus:
11
+ gpu_memory_info.append((gpu.id, gpu.name, f"{gpu.memoryUsed} MB", f"{gpu.memoryTotal} MB", f"{gpu.memoryUtil * 100:.1f}%"))
12
+
13
+ return gpu_memory_info
14
+
15
+ def display_gpu_memory_usage():
16
+ gpu_memory_info = get_gpu_memory_usage()
17
+
18
+ if gpu_memory_info:
19
+ print("GPU Memory Usage:")
20
+ for info in gpu_memory_info:
21
+ print(f"GPU ID: {info[0]}, Name: {info[1]}, Memory Used: {info[2]}, Total Memory: {info[3]}, Memory Utilization: {info[4]}")
22
+ else:
23
+ print("No GPU found.")
24
+
25
+ def color_print(content):
26
+ print(f'\033[1;46m{content}\033[0m\n')
27
+
28
+ def save_pic_iterly(pic_name, postfix, info):
29
+ pic_idx=1
30
+ pic_name_full=f'{pic_name}_{pic_idx}.{postfix}'
31
+
32
+ while os.path.exists(pic_name_full):
33
+ print(f'File {pic_name_full} already exists.')
34
+ pic_idx += 1
35
+ pic_name_full=f'{pic_name}_{pic_idx}.png'
36
+
37
+ plt.savefig(pic_name_full, dpi=300, bbox_inches='tight')
38
+
39
+ color_print(f'!!!!! {info} is saved in file {pic_name_full}')