Skip to content

Commit

Permalink
Bugfix/v0.1.6 (#282)
Browse files Browse the repository at this point in the history
Fix some bugs before release.
  • Loading branch information
SAKURA-CAT committed Jan 25, 2024
1 parent 3f5e428 commit a58975b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
9 changes: 8 additions & 1 deletion swanlab/data/run/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,14 @@ def __save(self):
with get_a_lock(self.__settings.get("save_path"), "w") as f:
# 将config的每个key的value转换为desc和value两部分,value就是原来的value,desc是None
# 这样做的目的是为了在web界面中显示config的内容,desc是用于描述value的
config = {key: {"desc": None, "value": value} for key, value in self.__config.items()}
config = {
key: {
"desc": None,
"sort": index,
"value": value,
}
for index, (key, value) in enumerate(self.__config.items())
}
yaml.dump(config, f)

def __iter__(self):
Expand Down
2 changes: 1 addition & 1 deletion swanlab/db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ def save(self, *args, **kwargs):
"""保存数据
经过swanmodel的覆写,save方法自动更新update_time字段
"""
self.update(update_time=create_time())
self.update_time = create_time()
super().save(*args, **kwargs)
8 changes: 4 additions & 4 deletions swanlab/server/controller/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import datetime
from ..module.resp import SUCCESS_200, DATA_ERROR_500, CONFLICT_409, NOT_FOUND_404
from fastapi import Request
from urllib.parse import unquote
from urllib.parse import quote
from ..settings import (
get_logs_dir,
get_exp_dir,
Expand Down Expand Up @@ -334,16 +334,16 @@ def get_experiment_summary(experiment_id: int) -> dict:
tags = [f for f in os.listdir(experiment_path) if os.path.isdir(os.path.join(experiment_path, f))]
summaries = []
for tag in tag_list:
if tag not in tags:
if quote(tag, safe="") not in tags:
summaries.append({"key": tag, "value": "TypeError"})
continue
tag_path = os.path.join(experiment_path, tag)
tag_path = os.path.join(experiment_path, quote(tag, safe=""))
logs = sorted([item for item in os.listdir(tag_path) if item != "_summary.json"])
with get_a_lock(os.path.join(tag_path, logs[-1]), mode="r") as f:
data = ujson.load(f)
# str 转化的目的是为了防止有些不合规范的数据导致返回体对象化失败
data = str(data["data"][-1]["data"])
summaries.append({"key": unquote(tag), "value": data})
summaries.append({"key": tag, "value": data})

return SUCCESS_200({"summaries": summaries})

Expand Down
12 changes: 6 additions & 6 deletions swanlab/server/controller/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
import shutil
from ..module.resp import SUCCESS_200, DATA_ERROR_500, CONFLICT_409
from fastapi import Request
from urllib.parse import unquote
from urllib.parse import quote
from ..settings import (
get_logs_dir,
get_tag_dir,
get_exp_dir,
get_config_path,
Expand Down Expand Up @@ -115,7 +114,8 @@ def get_project_summary(project_id: int = DEFAULT_PROJECT_ID) -> dict:

# 根据 id 列表找到所有的 tag,提出不含重复 tag 名的元组
tags = Tag.filter(Tag.experiment_id.in_(ids))
tag_names = list(set(unquote(tag["name"]) for tag in __to_list(tags)))
# tag_names不用编码,因为前端需要展示
tag_names = list(set(tag["name"] for tag in __to_list(tags)))

# 所有总结数据
data = {}
Expand All @@ -124,16 +124,16 @@ def get_project_summary(project_id: int = DEFAULT_PROJECT_ID) -> dict:
# 第二层为 tag 层,在实验目录下遍历所有 tag,若存在则获取最后一个次提交的值
experiment_summaries = {}
for tag in expr["tags"]:
tag_path = get_tag_dir(expr["run_id"], tag)
tag_path = get_tag_dir(expr["run_id"], quote(tag, safe=""))
if not os.path.exists(tag_path):
experiment_summaries[unquote(tag)] = "TypeError"
experiment_summaries[tag] = "TypeError"
continue
logs = sorted([item for item in os.listdir(tag_path) if item != "_summary.json"])
with open(os.path.join(tag_path, logs[-1]), mode="r") as f:
try:
tag_data = ujson.load(f)
# str 转化的目的是为了防止有些不合规范的数据导致返回体对象化失败
experiment_summaries[unquote(tag)] = str(tag_data["data"][-1]["data"])
experiment_summaries[tag] = str(tag_data["data"][-1]["data"])
except Exception as e:
print(f"[expr: {expr['name']} - {tag}] --- {e}")
continue
Expand Down
5 changes: 3 additions & 2 deletions test/create_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
logggings=True,
)

for i in range(10):
swanlab.log({"acc": i, "loss": "123"})
for i in range(30):
swanlab.log({"acc": i, "hhh/loss": "123"})
time.sleep(0.5)
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ const configs = computed(() => {
for (const key in experiment.value.config) {
configs.push({
key,
value: experiment.value.config[key].value
value: experiment.value.config[key].value,
sort: experiment.value.config[key].sort
})
}
// 按照 sort 排序,然后删除 sort 属性
return configs
.sort((a, b) => {
return a.sort - b.sort
})
.map((item) => {
delete item.sort
return item
})
})
// ---------------------------------- 获取实验的总结数据 ----------------------------------
Expand Down

0 comments on commit a58975b

Please sign in to comment.