Muyi 0.0.7__py3-none-any.whl → 0.0.9__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.
- muyi/__init__.py +35 -0
- muyi/gpu.py +1 -2
- muyi/graph.py +2 -3
- muyi/utils.py +129 -5
- muyi-0.0.9.dist-info/METADATA +101 -0
- muyi-0.0.9.dist-info/RECORD +9 -0
- {Muyi-0.0.7.dist-info → muyi-0.0.9.dist-info}/WHEEL +1 -1
- Muyi-0.0.7.dist-info/METADATA +0 -36
- Muyi-0.0.7.dist-info/RECORD +0 -9
- {Muyi-0.0.7.dist-info → muyi-0.0.9.dist-info/licenses}/LICENSE +0 -0
- {Muyi-0.0.7.dist-info → muyi-0.0.9.dist-info}/top_level.txt +0 -0
muyi/__init__.py
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# utils
|
|
2
|
+
from .utils import (
|
|
3
|
+
bcolors,
|
|
4
|
+
color_print,
|
|
5
|
+
save_pic_iterly,
|
|
6
|
+
read_csv_tqdm,
|
|
7
|
+
save_result_csv,
|
|
8
|
+
get_unique_save_path,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
# gpu
|
|
12
|
+
from .gpu import (
|
|
13
|
+
get_gpu_memory_usage,
|
|
14
|
+
display_gpu_memory_usage,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
# graph
|
|
18
|
+
from .graph import (
|
|
19
|
+
pyg_data_to_dgl_graph,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
# utils
|
|
24
|
+
'bcolors',
|
|
25
|
+
'color_print',
|
|
26
|
+
'save_pic_iterly',
|
|
27
|
+
'read_csv_tqdm',
|
|
28
|
+
'save_result_csv',
|
|
29
|
+
'get_unique_save_path',
|
|
30
|
+
# gpu
|
|
31
|
+
'get_gpu_memory_usage',
|
|
32
|
+
'display_gpu_memory_usage',
|
|
33
|
+
# graph
|
|
34
|
+
'pyg_data_to_dgl_graph',
|
|
35
|
+
]
|
muyi/gpu.py
CHANGED
muyi/graph.py
CHANGED
muyi/utils.py
CHANGED
|
@@ -1,13 +1,69 @@
|
|
|
1
1
|
import os
|
|
2
|
-
import
|
|
3
|
-
import pandas as pd
|
|
4
|
-
from tqdm import tqdm
|
|
2
|
+
import csv
|
|
5
3
|
import sys
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
class bcolors:
|
|
6
|
+
HEADER = '\033[95m' # 紫色,用于标题
|
|
7
|
+
OKBLUE = '\033[94m' # 蓝色,用于正常或信息性消息
|
|
8
|
+
OKCYAN = '\033[96m' # 青色(浅蓝色),用于信息性消息
|
|
9
|
+
OKGREEN = '\033[92m' # 绿色,用于成功或确认的消息
|
|
10
|
+
WARNING = '\033[93m' # 黄色,用于警告或重要提示
|
|
11
|
+
FAIL = '\033[91m' # 红色,用于错误或失败的消息
|
|
12
|
+
ENDC = '\033[0m' # 重置所有样式,回到默认颜色
|
|
13
|
+
BOLD = '\033[1m' # 粗体文本
|
|
14
|
+
UNDERLINE = '\033[4m' # 下划线文本
|
|
15
|
+
BLACK = '\033[30m' # 黑色
|
|
16
|
+
RED = '\033[31m' # 红色
|
|
17
|
+
GREEN = '\033[32m' # 绿色
|
|
18
|
+
YELLOW = '\033[33m' # 黄色
|
|
19
|
+
BLUE = '\033[34m' # 蓝色
|
|
20
|
+
MAGENTA = '\033[35m' # 品红色(紫红色)
|
|
21
|
+
CYAN = '\033[36m' # 青色
|
|
22
|
+
WHITE = '\033[37m' # 白色
|
|
23
|
+
# 添加背景颜色
|
|
24
|
+
BG_BLACK = '\033[40m' # 黑色背景
|
|
25
|
+
BG_RED = '\033[41m' # 红色背景
|
|
26
|
+
BG_GREEN = '\033[42m' # 绿色背景
|
|
27
|
+
BG_YELLOW = '\033[43m' # 黄色背景
|
|
28
|
+
BG_BLUE = '\033[44m' # 蓝色背景
|
|
29
|
+
BG_MAGENTA = '\033[45m'# 品红色(紫红色)背景
|
|
30
|
+
BG_CYAN = '\033[46m' # 青色背景
|
|
31
|
+
BG_WHITE = '\033[47m' # 白色背景
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def color_print(content, font_color='white', bg_color='bg_blue'):
|
|
35
|
+
colors = {
|
|
36
|
+
'header': bcolors.HEADER,
|
|
37
|
+
'okblue': bcolors.OKBLUE,
|
|
38
|
+
'okcyan': bcolors.OKCYAN,
|
|
39
|
+
'okgreen': bcolors.OKGREEN,
|
|
40
|
+
'warning': bcolors.WARNING,
|
|
41
|
+
'fail': bcolors.FAIL,
|
|
42
|
+
'black': bcolors.BLACK,
|
|
43
|
+
'red': bcolors.RED,
|
|
44
|
+
'green': bcolors.GREEN,
|
|
45
|
+
'yellow': bcolors.YELLOW,
|
|
46
|
+
'blue': bcolors.BLUE,
|
|
47
|
+
'magenta': bcolors.MAGENTA,
|
|
48
|
+
'cyan': bcolors.CYAN,
|
|
49
|
+
'white': bcolors.WHITE,
|
|
50
|
+
'bg_black': bcolors.BG_BLACK,
|
|
51
|
+
'bg_red': bcolors.BG_RED,
|
|
52
|
+
'bg_green': bcolors.BG_GREEN,
|
|
53
|
+
'bg_yellow': bcolors.BG_YELLOW,
|
|
54
|
+
'bg_blue': bcolors.BG_BLUE,
|
|
55
|
+
'bg_magenta': bcolors.BG_MAGENTA,
|
|
56
|
+
'bg_cyan': bcolors.BG_CYAN,
|
|
57
|
+
'bg_white': bcolors.BG_WHITE,
|
|
58
|
+
'end': bcolors.ENDC,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# Apply the background color first, then the font color
|
|
62
|
+
print(f'{colors[bg_color]}{colors[font_color]}{content}{colors["end"]}\n')
|
|
9
63
|
|
|
10
64
|
def save_pic_iterly(pic_name, postfix, info):
|
|
65
|
+
import matplotlib.pyplot as plt
|
|
66
|
+
|
|
11
67
|
pic_idx=1
|
|
12
68
|
pic_name_full=f'{pic_name}_{pic_idx}.{postfix}'
|
|
13
69
|
|
|
@@ -21,6 +77,9 @@ def save_pic_iterly(pic_name, postfix, info):
|
|
|
21
77
|
color_print(f'!!!!! {info} is saved in file {pic_name_full}')
|
|
22
78
|
|
|
23
79
|
def read_csv_tqdm(path, **kwargs):
|
|
80
|
+
import pandas as pd
|
|
81
|
+
from tqdm import tqdm
|
|
82
|
+
|
|
24
83
|
INPUT_FILENAME = path
|
|
25
84
|
LINES_TO_READ_FOR_ESTIMATION = 20
|
|
26
85
|
CHUNK_SIZE_PER_ITERATION = 10**5
|
|
@@ -44,3 +103,68 @@ def read_csv_tqdm(path, **kwargs):
|
|
|
44
103
|
|
|
45
104
|
del df
|
|
46
105
|
return data
|
|
106
|
+
|
|
107
|
+
def save_result_csv(csv_path, data):
|
|
108
|
+
"""保存结果到CSV文件(通用型)
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
csv_path: CSV文件路径
|
|
112
|
+
data: dict, 包含要保存的数据,key为列名,value为对应的值
|
|
113
|
+
"""
|
|
114
|
+
file_exists = os.path.exists(csv_path)
|
|
115
|
+
headers = list(data.keys())
|
|
116
|
+
values = list(data.values())
|
|
117
|
+
|
|
118
|
+
with open(csv_path, 'a', newline='') as f:
|
|
119
|
+
writer = csv.writer(f)
|
|
120
|
+
if not file_exists:
|
|
121
|
+
writer.writerow(headers)
|
|
122
|
+
writer.writerow(values)
|
|
123
|
+
|
|
124
|
+
print(f"Results saved to {csv_path}")
|
|
125
|
+
|
|
126
|
+
def get_unique_save_path(folder_path, base_name_pattern, start_no=1):
|
|
127
|
+
"""生成不重复的保存路径,自动递增版本号。
|
|
128
|
+
|
|
129
|
+
通过检查文件是否存在,自动递增编号直到找到一个不存在的文件路径。
|
|
130
|
+
如果目标文件夹不存在,会自动创建。
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
folder_path: 目标文件夹路径
|
|
134
|
+
base_name_pattern: 文件名模板,必须包含 {no} 占位符用于插入编号
|
|
135
|
+
例如: "result_{no}.csv", "model_v{no}.pt"
|
|
136
|
+
start_no: 起始编号,默认为 1
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
str: 不重复的完整文件路径
|
|
140
|
+
|
|
141
|
+
Examples:
|
|
142
|
+
>>> get_unique_save_path("./output", "result_{no}.csv")
|
|
143
|
+
'./output/result_1.csv' # 如果不存在
|
|
144
|
+
|
|
145
|
+
>>> get_unique_save_path("./output", "result_{no}.csv")
|
|
146
|
+
'./output/result_2.csv' # 如果 result_1.csv 已存在
|
|
147
|
+
|
|
148
|
+
>>> get_unique_save_path("./models", "checkpoint_v{no}.pt", start_no=10)
|
|
149
|
+
'./models/checkpoint_v10.pt' # 从编号 10 开始
|
|
150
|
+
|
|
151
|
+
# 使用 f-string 动态构建模板(注意 {no} 需要用双花括号转义)
|
|
152
|
+
>>> model_name = "transformer"
|
|
153
|
+
>>> dataset = "ETTh1"
|
|
154
|
+
>>> get_unique_save_path("./results", f"{model_name}_{dataset}_{{no}}.csv")
|
|
155
|
+
'./results/transformer_ETTh1_1.csv'
|
|
156
|
+
|
|
157
|
+
>>> pred_len = 96
|
|
158
|
+
>>> get_unique_save_path("./output", f"pred{pred_len}_exp{{no}}.npy")
|
|
159
|
+
'./output/pred96_exp1.npy'
|
|
160
|
+
"""
|
|
161
|
+
if not os.path.exists(folder_path):
|
|
162
|
+
os.makedirs(folder_path)
|
|
163
|
+
|
|
164
|
+
no = start_no
|
|
165
|
+
while True:
|
|
166
|
+
filename = base_name_pattern.format(no=no)
|
|
167
|
+
full_path = os.path.join(folder_path, filename)
|
|
168
|
+
if not os.path.exists(full_path):
|
|
169
|
+
return full_path
|
|
170
|
+
no += 1
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Muyi
|
|
3
|
+
Version: 0.0.9
|
|
4
|
+
Summary: Some useful utils.
|
|
5
|
+
Home-page: https://github.com/Muyiiiii/muyi
|
|
6
|
+
Author: muyiiiii
|
|
7
|
+
Author-email:
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Provides-Extra: plot
|
|
15
|
+
Requires-Dist: matplotlib; extra == "plot"
|
|
16
|
+
Provides-Extra: csv
|
|
17
|
+
Requires-Dist: pandas; extra == "csv"
|
|
18
|
+
Requires-Dist: tqdm; extra == "csv"
|
|
19
|
+
Provides-Extra: gpu
|
|
20
|
+
Requires-Dist: GPUtil; extra == "gpu"
|
|
21
|
+
Provides-Extra: graph
|
|
22
|
+
Requires-Dist: torch; extra == "graph"
|
|
23
|
+
Requires-Dist: dgl; extra == "graph"
|
|
24
|
+
Provides-Extra: all
|
|
25
|
+
Requires-Dist: matplotlib; extra == "all"
|
|
26
|
+
Requires-Dist: pandas; extra == "all"
|
|
27
|
+
Requires-Dist: tqdm; extra == "all"
|
|
28
|
+
Requires-Dist: GPUtil; extra == "all"
|
|
29
|
+
Requires-Dist: torch; extra == "all"
|
|
30
|
+
Requires-Dist: dgl; extra == "all"
|
|
31
|
+
Dynamic: author
|
|
32
|
+
Dynamic: classifier
|
|
33
|
+
Dynamic: description
|
|
34
|
+
Dynamic: description-content-type
|
|
35
|
+
Dynamic: home-page
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
Dynamic: provides-extra
|
|
38
|
+
Dynamic: requires-python
|
|
39
|
+
Dynamic: summary
|
|
40
|
+
|
|
41
|
+
# muyi
|
|
42
|
+
|
|
43
|
+
Some useful utils for GNNs and Deep Learning.
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install muyi # basic installation
|
|
49
|
+
pip install muyi[plot] # + matplotlib
|
|
50
|
+
pip install muyi[csv] # + pandas, tqdm
|
|
51
|
+
pip install muyi[gpu] # + GPUtil
|
|
52
|
+
pip install muyi[graph] # + torch, dgl
|
|
53
|
+
pip install muyi[all] # all dependencies
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## utils
|
|
57
|
+
|
|
58
|
+
1. `color_print(content, font_color, bg_color)`
|
|
59
|
+
2. `save_pic_iterly(pic_name, postfix, info)`
|
|
60
|
+
3. `read_csv_tqdm(path, **kwargs)`
|
|
61
|
+
4. `save_result_csv(csv_path, data)`
|
|
62
|
+
5. `get_unique_save_path(folder_path, base_name_pattern, start_no)`
|
|
63
|
+
|
|
64
|
+
## graph
|
|
65
|
+
|
|
66
|
+
1. `pyg_data_to_dgl_graph(pyg_data_obj)`
|
|
67
|
+
|
|
68
|
+
## gpu
|
|
69
|
+
|
|
70
|
+
1. `get_gpu_memory_usage()`
|
|
71
|
+
2. `display_gpu_memory_usage()`
|
|
72
|
+
|
|
73
|
+
## Upload to PyPI
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# 1. Install build tools
|
|
77
|
+
pip install build twine
|
|
78
|
+
|
|
79
|
+
# 2. Build package
|
|
80
|
+
python -m build
|
|
81
|
+
|
|
82
|
+
# 3. Upload to PyPI
|
|
83
|
+
twine upload dist/*
|
|
84
|
+
# Username: __token__
|
|
85
|
+
# Password: your PyPI API Token (starts with pypi-)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Get API Token: https://pypi.org/manage/account/token/
|
|
89
|
+
|
|
90
|
+
### Save Token Locally (Optional)
|
|
91
|
+
|
|
92
|
+
Create `~/.pypirc` file to avoid entering credentials each time:
|
|
93
|
+
|
|
94
|
+
```ini
|
|
95
|
+
[pypi]
|
|
96
|
+
username = __token__
|
|
97
|
+
password = pypi-your-token-here
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- **Linux/macOS**: `~/.pypirc`
|
|
101
|
+
- **Windows**: `C:\Users\<username>\.pypirc`
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
muyi/__init__.py,sha256=tY99oEmStngLIJCZN1QrKR6oOce-8zt_dzW3hE4SbAU,558
|
|
2
|
+
muyi/gpu.py,sha256=wQozizgnFOCtKThimSQZnArJLeQD485H6mEuAJT84yE,678
|
|
3
|
+
muyi/graph.py,sha256=tOkXMjtOzxxIB326FOshhcZYf4d_6BwPjrxURqywz90,1151
|
|
4
|
+
muyi/utils.py,sha256=Ik9rf6EXgluLnr__SMiHERyWxV3J3UZmVvUdc36XF8A,6066
|
|
5
|
+
muyi-0.0.9.dist-info/licenses/LICENSE,sha256=GzHS9pi6vw_oGwKIGxAPch8iuVrHazOilEsYL7AlPK0,1085
|
|
6
|
+
muyi-0.0.9.dist-info/METADATA,sha256=nIDB8VkyRXX4vokOSkSmlc4vrAXzAEhy0K7mPkhz6bo,2506
|
|
7
|
+
muyi-0.0.9.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
8
|
+
muyi-0.0.9.dist-info/top_level.txt,sha256=3X0xmx0SvmCNEj1ISqmD2evKh_ejCJQaLA4GEbGfKc4,5
|
|
9
|
+
muyi-0.0.9.dist-info/RECORD,,
|
Muyi-0.0.7.dist-info/METADATA
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: Muyi
|
|
3
|
-
Version: 0.0.7
|
|
4
|
-
Summary: Some useful utils.
|
|
5
|
-
Home-page: https://github.com/Muyiiiii/muyi
|
|
6
|
-
Author: muyiiiii
|
|
7
|
-
Author-email:
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
License-File: LICENSE
|
|
14
|
-
|
|
15
|
-
# muyi
|
|
16
|
-
|
|
17
|
-
Some useful utils for GNNs and Deep Learning.
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
pip install muyi
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## utils
|
|
24
|
-
|
|
25
|
-
1. `color_print(content)`
|
|
26
|
-
2. `save_pic_iterly(pic_name, postfix, info)`
|
|
27
|
-
3. `read_csv_tqdm(path, **kwargs)`
|
|
28
|
-
|
|
29
|
-
## graph
|
|
30
|
-
|
|
31
|
-
1. `pyg_data_to_dgl_graph(pyg_data_obj)`
|
|
32
|
-
|
|
33
|
-
## gpu
|
|
34
|
-
|
|
35
|
-
1. `get_gpu_memory_usage()`
|
|
36
|
-
2. `display_gpu_memory_usage()`
|
Muyi-0.0.7.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
muyi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
muyi/gpu.py,sha256=JLr-hQ84gv7afgFX6XHaquvN-HB19NqvwHxoq-rugdM,676
|
|
3
|
-
muyi/graph.py,sha256=4okLvgp0TboSpuKtlzXTTbLin2K-RMVxhqJ7CZt6Tps,1145
|
|
4
|
-
muyi/utils.py,sha256=XJaNLLNvSbaCcFm_dVnHS8RG4AGnQoJj0h5nt5tSYJk,1429
|
|
5
|
-
Muyi-0.0.7.dist-info/LICENSE,sha256=GzHS9pi6vw_oGwKIGxAPch8iuVrHazOilEsYL7AlPK0,1085
|
|
6
|
-
Muyi-0.0.7.dist-info/METADATA,sha256=LeDChXIF81CatUgGGynldsi5F8PD8IXfiUMvEwZ70_Q,741
|
|
7
|
-
Muyi-0.0.7.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
|
|
8
|
-
Muyi-0.0.7.dist-info/top_level.txt,sha256=3X0xmx0SvmCNEj1ISqmD2evKh_ejCJQaLA4GEbGfKc4,5
|
|
9
|
-
Muyi-0.0.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|