Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add name param #811

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions swanlab/data/run/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(
log_level: str = None,
exp_num: int = None,
operator: SwanLabRunOperator = SwanLabRunOperator(),
name: str = None,
):
"""
Initializing the SwanLabRun class involves configuring the settings and initiating other logging processes.
Expand All @@ -68,6 +69,8 @@ def __init__(
历史实验总数,用于云端颜色与本地颜色的对应
operator : SwanLabRunOperator, optional
实验操作员,用于批量处理回调函数的调用,如果不提供此参数(为None),则会自动生成一个实例
name : str, optional
实验名称,默认以experiment_name为主,如果experiment_name为None,则以name为主
"""
if self.is_started():
raise RuntimeError("SwanLabRun has been initialized")
Expand Down Expand Up @@ -103,6 +106,13 @@ def __init__(
setattr(config, "_SwanLabConfig__on_setter", self.__operator.on_runtime_info_update)
self.__config = config
# ---------------------------------- 注册实验 ----------------------------------
# 如果experiment_name和name都提供了,则warning
if experiment_name is not None and name is not None:
swanlog.warning("The `experiment_name` has been provided, and the `name` will be ignored.")
# 如果experiment_name为None,则以name为主
elif experiment_name is None and name is not None:
experiment_name = name

self.__exp: SwanLabExp = self.__register_exp(experiment_name, description, num=exp_num)
# 实验状态标记,如果status不为0,则无法再次调用log方法
self.__state = SwanLabRunState.RUNNING
Expand Down
5 changes: 5 additions & 0 deletions swanlab/data/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def init(
mode: MODES = None,
load: str = None,
public: bool = None,
name: str = None,
**kwargs,
) -> SwanLabRun:
"""
Expand Down Expand Up @@ -143,6 +144,8 @@ def init(
public : bool, optional
Whether the project can be seen by anyone, the default is None, which means the project is private.
Only available in cloud mode while the first time you create the project.
name : str, optional
The name of the current run, if not provided, it will be the same as the experiment name.
"""
if SwanLabRun.is_started():
swanlog.warning("You have already initialized a run, the init function will be ignored")
Expand All @@ -158,6 +161,7 @@ def init(
project = _load_data(load_data, "project", project)
workspace = _load_data(load_data, "workspace", workspace)
public = _load_data(load_data, "private", public)
name = _load_data(load_data, "name", name)
project = _check_proj_name(project if project else os.path.basename(os.getcwd())) # 默认实验名称为当前目录名
# ---------------------------------- 启动操作员 ----------------------------------
operator, c = _create_operator(mode, public)
Expand All @@ -177,6 +181,7 @@ def init(
log_level=kwargs.get("log_level", "info"),
exp_num=exp_num,
operator=operator,
name=name,
)
return run

Expand Down