Skip to content

Commit

Permalink
v0.1.0 (#46)
Browse files Browse the repository at this point in the history
* update version

* ui/anglicize(#51)

* update ui

* add english
---------

Co-authored-by: KAAANG <cunykang@gmail.com>

* Feat/pypi (#54)

* add version

* fix init

* update import

* delete experiment_name

* fix #51

* 对 #9 做了一些调整,优化性能。新增index字段,并向下兼容

* update ui

* add version to header

* update script

* fix: minute

* add version

* add blank

* Feat/log (#57)

1. [enchancement] add class FONT to handle text colors
2. [bug, enchancement] switch logging stream to sys.strout
3. [enchancement] remove color code when write swanlog into console folder
---------

Co-authored-by: KAAANG <cunykang@gmail.com>

* v0.0.2beta4

* Update pyproject.toml

* feat:auto publish (#58)

* feat:auto publish

* Feat/log show (#60)

* delete: mock

* 基本样式

* add font

* feat: get logs

* fix bugs and uis

* fix scroll

* feat: get recent logs

* Update create_experiment.py

* fix: error.log

* feat: empty experiment without charts

* feat: loading

* refactor: not return error when it is none

* fix: limit max lines

* fix some bugs

---------

Co-authored-by: KAAANG <cunykang@gmail.com>

* Refactor/log line number (#62)

* fix some bugs
* console log refactor

---------

Co-authored-by: Zirui Cai <1575079435@qq.com>

* v0.0.2beta5

* Update pyproject.toml

* add version

* Update pyproject.toml

* ui: hide links (#63)

---------

 fix #50 #52 #53 #45 #44 #41

Co-authored-by: cunyue-4060 <cunykang@gmail.com>
Co-authored-by: Bote Huang <106975133+KashiwaByte@users.noreply.github.com>
Co-authored-by: KAAANG <79990647+SAKURA-CAT@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 22, 2023
1 parent fa0d1ec commit b60a6b7
Show file tree
Hide file tree
Showing 52 changed files with 1,050 additions and 343 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/ask for question.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: 🤔 Ask for question
about: Look for some help or ask question
title: '🐛 [QUESTION] '
title: '🤔 [QUESTION] '
labels: help wanted
assignees: ''
---
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish to PyPI

on:
release:
types:
- published

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Set Nodejs
uses: actions/setup-node@v4
with:
node-version: 18.15.0

- name: Install Dependencies
run: |
npm install
pip install -r requirements.txt
pip install build
pip install twine
- name: Build and Publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

run: |
npm run build.release
python -m build
python -m twine upload dist/*
8 changes: 0 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "dev"]
},
{
"name": "前端开发:mock",
"request": "launch",
"cwd": "${workspaceRoot}",
"type": "node",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "dev:mock"]
},
// 启动后端开发服务
{
"name": "后端开发",
Expand Down
6 changes: 5 additions & 1 deletion build_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
@File: build_pypi.py
@IDE: vscode
@Description:
构建项目
构建项目的脚本,用于构建pypi包
"""
import subprocess
import shutil
import os

# 如果node_modules文件夹存在则不运行npm install
if not os.path.exists("node_modules"):
# 安装依赖
subprocess.run("npm install", shell=True)
# 构建node项目
subprocess.run("npm run build.release", shell=True)
# 如果dist文件夹存在则删除
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swanlab-ui",
"private": true,
"version": "0.0.2beta3",
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down Expand Up @@ -36,7 +36,6 @@
"tailwindcss": "^3.3.5",
"unplugin-auto-import": "^0.15.2",
"unplugin-vue-components": "^0.24.1",
"vite": "^5.0.0",
"vite-plugin-mock": "^2.9.8"
"vite": "^5.0.0"
}
}
18 changes: 11 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ license = "Apache-2.0" # 项目许可证
requires-python = ">=3.8" # python版本要求,我们只维护python3.8以上版本
authors = [ # 项目作者
{ name = "Cunyue", email = "team@swanhub.co" },
{ name = "Ink", email = "team@swanhub.co" },
{ name = "KaiKai", email = "team@swanhub.co" },
{ name = "Feudalman", email = "team@swanhub.co" }
{ name = "Feudalman", email = "team@swanhub.co" },
{name="ZeYi Lin", email = "team@swanhub.co"},
{name="KashiwaByte", email="team@swanhub.co"}
]
keywords = [ # 项目关键词
"machine learning",
Expand Down Expand Up @@ -47,7 +47,7 @@ swanlab = "swanlab.cli:cli" # 项目命令行工具(可添加多个)
Homepage = "https://swabhub.co"

[tool.hatch.version] # 动态设置项目版本
path = "package.json" # TODO 选择前端package.json文件,从中获取版本号
path = "swanlab/package.json" # package.json文件,从中获取版本号
pattern = ".*\"version\":\\s*\"(?P<version>[^\"]+)\""

[tool.hatch.metadata.hooks.requirements_txt] # 动态设置依赖
Expand All @@ -61,13 +61,14 @@ content-type = "text/markdown"
fragments = [{ path = "README.md" }]


# [[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]] # 动态设置readme中的图片链接,渲染为html格式,gradio设置了,暂时不知道有什么用
# pattern = "(website/homepage|readme_files)/"
# replacement = 'https://raw.githubusercontent.com/SwanHubX/swanlab/main/\g<1>/'
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]] # 动态设置readme中的图片链接,渲染为html格式,gradio设置了,暂时不知道有什么用
pattern = "(website/homepage|readme_files)/"
replacement = 'https://raw.githubusercontent.com/SwanHubX/swanlab/main/\g<1>/'

[tool.hatch.build]
artifacts = [ # 将一些非python文件打包到项目中
"/swanlab/template",
"*.json",
"*.pyi", # 类型提示文件
]

Expand All @@ -86,6 +87,9 @@ include = [
"/package.json", # 包含前端的package.json文件
]

[tool.hatch.build.targets.wheel]
packages = ["swanlab"] # 指定项目包名

[tool.pyright] # 静态类型检查
include = ["swanlab/**/*.py"] # 检查的文件
exclude = [] # 排除的文件
Expand Down
70 changes: 7 additions & 63 deletions swanlab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,9 @@
from .log import swanlog as swl
from .env import swc
# 导出初始化函数和log函数
from .database import (
init,
log,
)
from .utils import get_package_version

_sd = None
"""
swandatabase对象
使用动态导入的方式有助于环境隔离
比如cli不需要此对象,就不需要导入
"""


def init(experiment_name: str = None, description: str = "", config: dict = {}):
"""初始化swanlab的配置
Parameters
----------
experiment_name : str, optional
实验名称, 如果不指定则自动生成一个
description : str, optional
实验描述, 如果不指定默认为空
config : dict, optional
实验可选配置,在此处可以记录一些实验的超参数等信息
"""
global _sd
if _sd is not None:
raise RuntimeError("swanlab has been initialized")
from .database import swandatabase as sd

# 挂载对象
_sd = sd
# 初始化数据库
_sd.init(
experiment_name=experiment_name,
description=description,
config=config,
)
# 初始化日志对象
swl.init(swc.output)
swl.info("Run data will be saved locally in " + swc.exp_folder)
swl.info("Experiment_name: " + _sd.experiment.name)
swl.info("Run `swanlab watch` to view SwanLab Experiment Dashboard")


def log(data: dict):
"""以字典的形式记录数据,字典的key将作为列名,value将作为记录的值
例如:
```python
sw.log({"loss": 0.1, "accuracy": 0.9})
```
Parameters
----------
data : dict
此处填写需要记录的数据
"""
if _sd is None:
raise RuntimeError("swanlab has not been initialized")

if not isinstance(data, dict):
raise TypeError("log data must be a dict")
for key in data:
# 遍历字典的key,记录到本地文件中
_sd.add(key, data[key])


__all__ = ["init", "log"]
__version__ = get_package_version()
79 changes: 66 additions & 13 deletions swanlab/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
from ..env import swc
from ..log import swanlog as swl

# 注册环境变量,需要在初始化数据库之前注册
swc.init(swc.getcwd(), "train")
# 初始化数据库
from .main import SwanDatabase

swandatabase = SwanDatabase()
sd = None


# 定义清理函数
def clean_handler():
if not swl.isError:
swl.info("train successfully")
swandatabase.success()
sd.success()
swl.setSuccess()
swl.reset_console()

Expand All @@ -24,7 +19,7 @@ def clean_handler():
def except_handler(tp, val, tb):
swl.error("Error happended while training, SwanLab will throw it")
# 标记实验失败
swandatabase.fail()
sd.fail()
swl.setError()
# 记录异常信息
# 追踪信息
Expand All @@ -45,11 +40,69 @@ def except_handler(tp, val, tb):
raise tp(val)


# 注册异常处理函数
sys.excepthook = except_handler
def init(experiment_name: str = None, description: str = "", config: dict = {}, *args, **kwargs):
"""初始化swanlab的配置
Parameters
----------
experiment_name : str, optional
实验名称, 如果不指定则自动生成一个
description : str, optional
实验描述, 如果不指定默认为空
config : dict, optional
实验可选配置,在此处可以记录一些实验的超参数等信息
kwargs : dict, optional
其他额外的非必要设置项目
"""
global sd
# 注册环境变量,需要在初始化数据库之前注册
swc.init(swc.getcwd(), "train")
# 初始化数据库
from .main import SwanDatabase

sd = SwanDatabase()

# 注册异常处理函数
sys.excepthook = except_handler

# 注册清理函数
atexit.register(clean_handler)

# 初始化数据库
sd.init(
experiment_name=experiment_name,
description=description,
config=config,
)
# 初始化日志对象

swl.init(swc.output, level=kwargs.get("log_level", "info"))
swl.debug("SwanLab database initialized")
swl.debug("Swanlab will take over all the print information of the terminal from now on")
swl.info("Run data will be saved locally in " + swc.exp_folder)
swl.info("Experiment_name: " + sd.experiment.name)
swl.info("Run `swanlab watch` to view SwanLab Experiment Dashboard")


def log(data: dict):
"""以字典的形式记录数据,字典的key将作为列名,value将作为记录的值
例如:
```python
sw.log({"loss": 0.1, "accuracy": 0.9})
```
Parameters
----------
data : dict
此处填写需要记录的数据
"""
if sd is None:
raise RuntimeError("swanlab is not initialized")
if not isinstance(data, dict):
raise TypeError("log data must be a dict")
for key in data:
# 遍历字典的key,记录到本地文件中
# TODO 检查数据类型
sd.add(key, data[key])

# 注册清理函数
atexit.register(clean_handler)

__all__ = ["swandatabase"]
__all__ = ["log", "init"]
Loading

0 comments on commit b60a6b7

Please sign in to comment.