ztxexp


Nameztxexp JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
Summary一个轻量、强大的Python库,旨在简化计算实验的管理、执行和分析。
upload_time2025-08-03 12:37:22
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2025 Tianxiang Zhan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords experiment management machine learning deep learning reproducibility parameter search data science pytorch
VCS
bugtrack_url
requirements dill joblib numpy pandas psutil torch twine build
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ztxexp

**ztxexp** (ZTX-Experiment)
是一个轻量级、零依赖(除Python标准库外)且功能强大的Python工具库,旨在将您从繁琐的计算实验管理中解放出来。它特别适用于机器学习、深度学习和任何需要进行大量参数搜索与结果分析的研究场景。

由 [**ztxtech**](https://github.com/ztxtech) 开发,ztxexp 将实验设计的全流程——**配置生成、增量运行、结果分析、目录清理**
——封装在一套优雅流畅的API中。

## 核心功能 ✨

* **🚀 流畅的参数配置**: 使用链式API轻松定义参数空间,支持网格搜索 (`Grid Search`) 和独立变体 (`Variants`)。
* **🔧 自定义逻辑**: 通过添加自定义的修改器和过滤器函数,实现任意复杂的参数调整和筛选逻辑。
* **💡 智能防重运行**: 自动检测已完成的实验,避免重复计算,节省宝贵的计算时间和资源。
* **⚡️ 灵活的执行引擎**: 支持多种实验执行模式,包括**顺序执行**、**并行执行** (`ProcessPoolExecutor` 或 `joblib`)。
* **📊 强大的结果分析**: 一键将所有分散的实验结果聚合到 Pandas DataFrame 中,并支持生成多维数据透视表(Pivot Table)与排名。
* **🧹 安全的目录清理**: 提供安全的 `dry_run` 模式和交互式确认,帮助你轻松删除未成功或不符合预期的实验结果。
* **🛠️ 丰富的工具集**: 内置一个不断丰富的 `utils.py` 模块,提供日志设置、代码计时、模型保存、路径管理等高频实用工具。

## 安装

```bash
pip install ztxexp
```

-----

## 核心工作流

`ztxexp` 的设计遵循一个简单直观的三段式工作流:

1. **管理 (Manage)**: 使用 `ztxexp.ExpManager` 定义和生成所有需要运行的实验配置。
2. **运行 (Run)**: 使用 `ztxexp.ExpRunner` 来执行这些配置,支持并行化和断点续跑。
3. **分析 (Analyze)**: 使用 `ztxexp.ResultAnalyzer` 来聚合结果、生成报告以及清理工作目录。

-----

## 用法示例

为了帮助你快速上手,我们在项目中提供了几个可直接运行的示例脚本。建议你亲自运行它们,以更好地理解库的功能。

* **`main_run_experiments.py`**: **(核心示例)** 展示了如何使用 `ExpManager` 的链式API组合网格搜索、变体、修改器和过滤器来生成复杂的实验配置,并使用
  `ExpRunner` 进行并行执行。这是理解本库强大之处的最佳起点。

  ```python
  # 节选自 main_run_experiments.py
  configs_to_run = (
      manager.add_grid_search(GRID_SPACE)
             .add_variants(VARIANT_SPACE)
             .add_modifier(modifier_func)
             .add_filter(filter_func)
             .filter_completed('./results_demo')
             .get_configs()
  )
  ```

* **`main_analyze_results.py`**: 演示了在实验运行后,如何使用 `ResultAnalyzer` 将所有成功运行的结果汇总到CSV文件,并创建一个带排名的精美Excel数据透视表。

* **`main_cleanup.py`**: 专注于目录维护。它展示了如何使用 `clean_results` 方法安全地、有选择性地删除那些失败的、未完成的、或者结果不符合预期的实验文件夹。

* **`main_utils_demo.py`**: 展示了 `ztxexp.utils` 模块的威力。即使不使用完整的 Manager/Runner
  工作流,你也可以在任何Python脚本中单独使用这些方便的工具函数,如日志记录器、代码计时器、PyTorch模型保存等。

-----

## API核心:自定义函数详解

`ztxexp` 的强大之处在于其高度的可定制性。你需要提供几个关键的自定义函数,下面是它们的详细“接口契约”。

### 1\. 实验主函数 (`exp_function`)

这是你的核心业务逻辑所在,由 `ExpRunner` 负责调用。

* **签名**: `def my_experiment(args: argparse.Namespace):`
* **参数**:
    * `args`: 一个 `Namespace` 对象,包含了本次运行所需的所有配置。`ExpRunner` 会自动向其添加两个额外的属性:
        * `args.setting`: 本次运行的唯一标识符(例如 `20250803_202020_a1b2c3`)。
        * `args.setting_path`: 本次运行的专属结果目录 (`Path` 对象),你可以向其中保存任何文件。
* **职责**:
    1. 执行你的实验代码(模型训练、数据处理等)。
    2. **必须自己保存结果**。例如,将指标保存到 `args.setting_path / 'results.json'`,将模型权重保存到
       `args.setting_path / 'model.pth'`。
* **返回值**: 无需返回值。`ExpRunner` 通过检查 `_SUCCESS` 标记文件(在函数成功返回后自动创建)来判断成功与否。

### 2\. 参数修改器 (`modifier_func`)

用于在生成最终配置列表前,对参数进行动态调整。

* **签名**: `def my_modifier(args: argparse.Namespace) -> argparse.Namespace:`
* **参数**:
    * `args`: 一个待处理的 `Namespace` 配置对象。
* **职责**: 根据已有参数修改`args`对象。例如:`if args.model == 'A': args.layers = 12`。
* **返回值**: **必须**返回修改后的 `args` 对象。

### 3\. 参数过滤器 (`filter_func`)

用于在生成最终配置列表前,剔除无效或不想运行的参数组合。

* **签名**: `def my_filter(args: argparse.Namespace) -> bool:`

* **参数**:

    * `args`: 一个待检查的 `Namespace` 配置对象。

* **职责**: 根据一组规则判断该配置是否有效。

* **返回值**: **必须**返回一个布尔值:

    * `True`:保留这个配置。
    * `False`:从待运行列表中**剔除**这个配置。

* **最佳实践**: 为了防止因参数缺失而导致程序崩溃,请始终使用 `.get()` 方法来安全地访问 `args` 中的属性。

  ```python
  # 安全的写法
  def my_safe_filter(args):
      # 如果 'lr' 存在且小于 0.001,则保留
      if args_dict := vars(args):
           if args_dict.get('lr', 999) < 0.001:
               return True
      return False

  # 不安全的写法 (如果 'lr' 缺失会引发 AttributeError)
  # def my_unsafe_filter(args):
  #     return args.lr < 0.001
  ```

### 4\. 目录清理过滤器 (`filter_func` for `clean_results`)

用于 `ResultAnalyzer.clean_results` 方法,以编程方式决定哪些文件夹需要被删除。

* **签名**: `def my_cleanup_filter(config_dict: dict) -> bool:`

* **参数**:

    * `config_dict`: 从一个 `args.json` 文件中加载而来的字典。

* **职责**: 判断这个配置是否符合被删除的条件。

* **返回值**: **必须**返回一个布尔值:

    * `True`:**标记此文件夹为待删除**。
    * `False`:保留此文件夹。

* **最佳实践**: 同样地,请务必使用 `.get()` 来处理可能缺失的键。

  ```python
  # 安全的写法:删除所有准确率低于 0.5 的实验
  def cleanup_low_accuracy(config):
      # 如果 'accuracy' 键不存在,.get 返回 1.0,条件不成立,不会被删除
      return config.get('accuracy', 1.0) < 0.5
  ```

## 贡献

欢迎任何形式的贡献!如果你有好的想法或发现了Bug,请随时在 [GitHub Issues](https://www.google.com/search?q=https://github.com/ztxtech/ztxtech-exp/issues)
中提出,或者直接提交一个 Pull Request。

## 许可证

该项目采用 [MIT License](https://opensource.org/licenses/MIT) 授权。

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ztxexp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "experiment management, machine learning, deep learning, reproducibility, parameter search, data science, pytorch",
    "author": null,
    "author_email": "ztxtech <ztxtech@foxmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f9/3b/08441c6246b7759a0fe1b92cab84c5146850fa2930febe2a869712c63142/ztxexp-0.1.0.tar.gz",
    "platform": null,
    "description": "# ztxexp\r\n\r\n**ztxexp** (ZTX-Experiment)\r\n\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u3001\u96f6\u4f9d\u8d56\uff08\u9664Python\u6807\u51c6\u5e93\u5916\uff09\u4e14\u529f\u80fd\u5f3a\u5927\u7684Python\u5de5\u5177\u5e93\uff0c\u65e8\u5728\u5c06\u60a8\u4ece\u7e41\u7410\u7684\u8ba1\u7b97\u5b9e\u9a8c\u7ba1\u7406\u4e2d\u89e3\u653e\u51fa\u6765\u3002\u5b83\u7279\u522b\u9002\u7528\u4e8e\u673a\u5668\u5b66\u4e60\u3001\u6df1\u5ea6\u5b66\u4e60\u548c\u4efb\u4f55\u9700\u8981\u8fdb\u884c\u5927\u91cf\u53c2\u6570\u641c\u7d22\u4e0e\u7ed3\u679c\u5206\u6790\u7684\u7814\u7a76\u573a\u666f\u3002\r\n\r\n\u7531 [**ztxtech**](https://github.com/ztxtech) \u5f00\u53d1\uff0cztxexp \u5c06\u5b9e\u9a8c\u8bbe\u8ba1\u7684\u5168\u6d41\u7a0b\u2014\u2014**\u914d\u7f6e\u751f\u6210\u3001\u589e\u91cf\u8fd0\u884c\u3001\u7ed3\u679c\u5206\u6790\u3001\u76ee\u5f55\u6e05\u7406**\r\n\u2014\u2014\u5c01\u88c5\u5728\u4e00\u5957\u4f18\u96c5\u6d41\u7545\u7684API\u4e2d\u3002\r\n\r\n## \u6838\u5fc3\u529f\u80fd \u2728\r\n\r\n* **\ud83d\ude80 \u6d41\u7545\u7684\u53c2\u6570\u914d\u7f6e**: \u4f7f\u7528\u94fe\u5f0fAPI\u8f7b\u677e\u5b9a\u4e49\u53c2\u6570\u7a7a\u95f4\uff0c\u652f\u6301\u7f51\u683c\u641c\u7d22 (`Grid Search`) \u548c\u72ec\u7acb\u53d8\u4f53 (`Variants`)\u3002\r\n* **\ud83d\udd27 \u81ea\u5b9a\u4e49\u903b\u8f91**: \u901a\u8fc7\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u4fee\u6539\u5668\u548c\u8fc7\u6ee4\u5668\u51fd\u6570\uff0c\u5b9e\u73b0\u4efb\u610f\u590d\u6742\u7684\u53c2\u6570\u8c03\u6574\u548c\u7b5b\u9009\u903b\u8f91\u3002\r\n* **\ud83d\udca1 \u667a\u80fd\u9632\u91cd\u8fd0\u884c**: \u81ea\u52a8\u68c0\u6d4b\u5df2\u5b8c\u6210\u7684\u5b9e\u9a8c\uff0c\u907f\u514d\u91cd\u590d\u8ba1\u7b97\uff0c\u8282\u7701\u5b9d\u8d35\u7684\u8ba1\u7b97\u65f6\u95f4\u548c\u8d44\u6e90\u3002\r\n* **\u26a1\ufe0f \u7075\u6d3b\u7684\u6267\u884c\u5f15\u64ce**: \u652f\u6301\u591a\u79cd\u5b9e\u9a8c\u6267\u884c\u6a21\u5f0f\uff0c\u5305\u62ec**\u987a\u5e8f\u6267\u884c**\u3001**\u5e76\u884c\u6267\u884c** (`ProcessPoolExecutor` \u6216 `joblib`)\u3002\r\n* **\ud83d\udcca \u5f3a\u5927\u7684\u7ed3\u679c\u5206\u6790**: \u4e00\u952e\u5c06\u6240\u6709\u5206\u6563\u7684\u5b9e\u9a8c\u7ed3\u679c\u805a\u5408\u5230 Pandas DataFrame \u4e2d\uff0c\u5e76\u652f\u6301\u751f\u6210\u591a\u7ef4\u6570\u636e\u900f\u89c6\u8868\uff08Pivot Table\uff09\u4e0e\u6392\u540d\u3002\r\n* **\ud83e\uddf9 \u5b89\u5168\u7684\u76ee\u5f55\u6e05\u7406**: \u63d0\u4f9b\u5b89\u5168\u7684 `dry_run` \u6a21\u5f0f\u548c\u4ea4\u4e92\u5f0f\u786e\u8ba4\uff0c\u5e2e\u52a9\u4f60\u8f7b\u677e\u5220\u9664\u672a\u6210\u529f\u6216\u4e0d\u7b26\u5408\u9884\u671f\u7684\u5b9e\u9a8c\u7ed3\u679c\u3002\r\n* **\ud83d\udee0\ufe0f \u4e30\u5bcc\u7684\u5de5\u5177\u96c6**: \u5185\u7f6e\u4e00\u4e2a\u4e0d\u65ad\u4e30\u5bcc\u7684 `utils.py` \u6a21\u5757\uff0c\u63d0\u4f9b\u65e5\u5fd7\u8bbe\u7f6e\u3001\u4ee3\u7801\u8ba1\u65f6\u3001\u6a21\u578b\u4fdd\u5b58\u3001\u8def\u5f84\u7ba1\u7406\u7b49\u9ad8\u9891\u5b9e\u7528\u5de5\u5177\u3002\r\n\r\n## \u5b89\u88c5\r\n\r\n```bash\r\npip install ztxexp\r\n```\r\n\r\n-----\r\n\r\n## \u6838\u5fc3\u5de5\u4f5c\u6d41\r\n\r\n`ztxexp` \u7684\u8bbe\u8ba1\u9075\u5faa\u4e00\u4e2a\u7b80\u5355\u76f4\u89c2\u7684\u4e09\u6bb5\u5f0f\u5de5\u4f5c\u6d41\uff1a\r\n\r\n1. **\u7ba1\u7406 (Manage)**: \u4f7f\u7528 `ztxexp.ExpManager` \u5b9a\u4e49\u548c\u751f\u6210\u6240\u6709\u9700\u8981\u8fd0\u884c\u7684\u5b9e\u9a8c\u914d\u7f6e\u3002\r\n2. **\u8fd0\u884c (Run)**: \u4f7f\u7528 `ztxexp.ExpRunner` \u6765\u6267\u884c\u8fd9\u4e9b\u914d\u7f6e\uff0c\u652f\u6301\u5e76\u884c\u5316\u548c\u65ad\u70b9\u7eed\u8dd1\u3002\r\n3. **\u5206\u6790 (Analyze)**: \u4f7f\u7528 `ztxexp.ResultAnalyzer` \u6765\u805a\u5408\u7ed3\u679c\u3001\u751f\u6210\u62a5\u544a\u4ee5\u53ca\u6e05\u7406\u5de5\u4f5c\u76ee\u5f55\u3002\r\n\r\n-----\r\n\r\n## \u7528\u6cd5\u793a\u4f8b\r\n\r\n\u4e3a\u4e86\u5e2e\u52a9\u4f60\u5feb\u901f\u4e0a\u624b\uff0c\u6211\u4eec\u5728\u9879\u76ee\u4e2d\u63d0\u4f9b\u4e86\u51e0\u4e2a\u53ef\u76f4\u63a5\u8fd0\u884c\u7684\u793a\u4f8b\u811a\u672c\u3002\u5efa\u8bae\u4f60\u4eb2\u81ea\u8fd0\u884c\u5b83\u4eec\uff0c\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u5e93\u7684\u529f\u80fd\u3002\r\n\r\n* **`main_run_experiments.py`**: **\uff08\u6838\u5fc3\u793a\u4f8b\uff09** \u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 `ExpManager` \u7684\u94fe\u5f0fAPI\u7ec4\u5408\u7f51\u683c\u641c\u7d22\u3001\u53d8\u4f53\u3001\u4fee\u6539\u5668\u548c\u8fc7\u6ee4\u5668\u6765\u751f\u6210\u590d\u6742\u7684\u5b9e\u9a8c\u914d\u7f6e\uff0c\u5e76\u4f7f\u7528\r\n  `ExpRunner` \u8fdb\u884c\u5e76\u884c\u6267\u884c\u3002\u8fd9\u662f\u7406\u89e3\u672c\u5e93\u5f3a\u5927\u4e4b\u5904\u7684\u6700\u4f73\u8d77\u70b9\u3002\r\n\r\n  ```python\r\n  # \u8282\u9009\u81ea main_run_experiments.py\r\n  configs_to_run = (\r\n      manager.add_grid_search(GRID_SPACE)\r\n             .add_variants(VARIANT_SPACE)\r\n             .add_modifier(modifier_func)\r\n             .add_filter(filter_func)\r\n             .filter_completed('./results_demo')\r\n             .get_configs()\r\n  )\r\n  ```\r\n\r\n* **`main_analyze_results.py`**: \u6f14\u793a\u4e86\u5728\u5b9e\u9a8c\u8fd0\u884c\u540e\uff0c\u5982\u4f55\u4f7f\u7528 `ResultAnalyzer` \u5c06\u6240\u6709\u6210\u529f\u8fd0\u884c\u7684\u7ed3\u679c\u6c47\u603b\u5230CSV\u6587\u4ef6\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u5e26\u6392\u540d\u7684\u7cbe\u7f8eExcel\u6570\u636e\u900f\u89c6\u8868\u3002\r\n\r\n* **`main_cleanup.py`**: \u4e13\u6ce8\u4e8e\u76ee\u5f55\u7ef4\u62a4\u3002\u5b83\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 `clean_results` \u65b9\u6cd5\u5b89\u5168\u5730\u3001\u6709\u9009\u62e9\u6027\u5730\u5220\u9664\u90a3\u4e9b\u5931\u8d25\u7684\u3001\u672a\u5b8c\u6210\u7684\u3001\u6216\u8005\u7ed3\u679c\u4e0d\u7b26\u5408\u9884\u671f\u7684\u5b9e\u9a8c\u6587\u4ef6\u5939\u3002\r\n\r\n* **`main_utils_demo.py`**: \u5c55\u793a\u4e86 `ztxexp.utils` \u6a21\u5757\u7684\u5a01\u529b\u3002\u5373\u4f7f\u4e0d\u4f7f\u7528\u5b8c\u6574\u7684 Manager/Runner\r\n  \u5de5\u4f5c\u6d41\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5728\u4efb\u4f55Python\u811a\u672c\u4e2d\u5355\u72ec\u4f7f\u7528\u8fd9\u4e9b\u65b9\u4fbf\u7684\u5de5\u5177\u51fd\u6570\uff0c\u5982\u65e5\u5fd7\u8bb0\u5f55\u5668\u3001\u4ee3\u7801\u8ba1\u65f6\u5668\u3001PyTorch\u6a21\u578b\u4fdd\u5b58\u7b49\u3002\r\n\r\n-----\r\n\r\n## API\u6838\u5fc3\uff1a\u81ea\u5b9a\u4e49\u51fd\u6570\u8be6\u89e3\r\n\r\n`ztxexp` \u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5176\u9ad8\u5ea6\u7684\u53ef\u5b9a\u5236\u6027\u3002\u4f60\u9700\u8981\u63d0\u4f9b\u51e0\u4e2a\u5173\u952e\u7684\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u4e0b\u9762\u662f\u5b83\u4eec\u7684\u8be6\u7ec6\u201c\u63a5\u53e3\u5951\u7ea6\u201d\u3002\r\n\r\n### 1\\. \u5b9e\u9a8c\u4e3b\u51fd\u6570 (`exp_function`)\r\n\r\n\u8fd9\u662f\u4f60\u7684\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\u6240\u5728\uff0c\u7531 `ExpRunner` \u8d1f\u8d23\u8c03\u7528\u3002\r\n\r\n* **\u7b7e\u540d**: `def my_experiment(args: argparse.Namespace):`\r\n* **\u53c2\u6570**:\r\n    * `args`: \u4e00\u4e2a `Namespace` \u5bf9\u8c61\uff0c\u5305\u542b\u4e86\u672c\u6b21\u8fd0\u884c\u6240\u9700\u7684\u6240\u6709\u914d\u7f6e\u3002`ExpRunner` \u4f1a\u81ea\u52a8\u5411\u5176\u6dfb\u52a0\u4e24\u4e2a\u989d\u5916\u7684\u5c5e\u6027\uff1a\r\n        * `args.setting`: \u672c\u6b21\u8fd0\u884c\u7684\u552f\u4e00\u6807\u8bc6\u7b26\uff08\u4f8b\u5982 `20250803_202020_a1b2c3`\uff09\u3002\r\n        * `args.setting_path`: \u672c\u6b21\u8fd0\u884c\u7684\u4e13\u5c5e\u7ed3\u679c\u76ee\u5f55 (`Path` \u5bf9\u8c61)\uff0c\u4f60\u53ef\u4ee5\u5411\u5176\u4e2d\u4fdd\u5b58\u4efb\u4f55\u6587\u4ef6\u3002\r\n* **\u804c\u8d23**:\r\n    1. \u6267\u884c\u4f60\u7684\u5b9e\u9a8c\u4ee3\u7801\uff08\u6a21\u578b\u8bad\u7ec3\u3001\u6570\u636e\u5904\u7406\u7b49\uff09\u3002\r\n    2. **\u5fc5\u987b\u81ea\u5df1\u4fdd\u5b58\u7ed3\u679c**\u3002\u4f8b\u5982\uff0c\u5c06\u6307\u6807\u4fdd\u5b58\u5230 `args.setting_path / 'results.json'`\uff0c\u5c06\u6a21\u578b\u6743\u91cd\u4fdd\u5b58\u5230\r\n       `args.setting_path / 'model.pth'`\u3002\r\n* **\u8fd4\u56de\u503c**: \u65e0\u9700\u8fd4\u56de\u503c\u3002`ExpRunner` \u901a\u8fc7\u68c0\u67e5 `_SUCCESS` \u6807\u8bb0\u6587\u4ef6\uff08\u5728\u51fd\u6570\u6210\u529f\u8fd4\u56de\u540e\u81ea\u52a8\u521b\u5efa\uff09\u6765\u5224\u65ad\u6210\u529f\u4e0e\u5426\u3002\r\n\r\n### 2\\. \u53c2\u6570\u4fee\u6539\u5668 (`modifier_func`)\r\n\r\n\u7528\u4e8e\u5728\u751f\u6210\u6700\u7ec8\u914d\u7f6e\u5217\u8868\u524d\uff0c\u5bf9\u53c2\u6570\u8fdb\u884c\u52a8\u6001\u8c03\u6574\u3002\r\n\r\n* **\u7b7e\u540d**: `def my_modifier(args: argparse.Namespace) -> argparse.Namespace:`\r\n* **\u53c2\u6570**:\r\n    * `args`: \u4e00\u4e2a\u5f85\u5904\u7406\u7684 `Namespace` \u914d\u7f6e\u5bf9\u8c61\u3002\r\n* **\u804c\u8d23**: \u6839\u636e\u5df2\u6709\u53c2\u6570\u4fee\u6539`args`\u5bf9\u8c61\u3002\u4f8b\u5982\uff1a`if args.model == 'A': args.layers = 12`\u3002\r\n* **\u8fd4\u56de\u503c**: **\u5fc5\u987b**\u8fd4\u56de\u4fee\u6539\u540e\u7684 `args` \u5bf9\u8c61\u3002\r\n\r\n### 3\\. \u53c2\u6570\u8fc7\u6ee4\u5668 (`filter_func`)\r\n\r\n\u7528\u4e8e\u5728\u751f\u6210\u6700\u7ec8\u914d\u7f6e\u5217\u8868\u524d\uff0c\u5254\u9664\u65e0\u6548\u6216\u4e0d\u60f3\u8fd0\u884c\u7684\u53c2\u6570\u7ec4\u5408\u3002\r\n\r\n* **\u7b7e\u540d**: `def my_filter(args: argparse.Namespace) -> bool:`\r\n\r\n* **\u53c2\u6570**:\r\n\r\n    * `args`: \u4e00\u4e2a\u5f85\u68c0\u67e5\u7684 `Namespace` \u914d\u7f6e\u5bf9\u8c61\u3002\r\n\r\n* **\u804c\u8d23**: \u6839\u636e\u4e00\u7ec4\u89c4\u5219\u5224\u65ad\u8be5\u914d\u7f6e\u662f\u5426\u6709\u6548\u3002\r\n\r\n* **\u8fd4\u56de\u503c**: **\u5fc5\u987b**\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff1a\r\n\r\n    * `True`\uff1a\u4fdd\u7559\u8fd9\u4e2a\u914d\u7f6e\u3002\r\n    * `False`\uff1a\u4ece\u5f85\u8fd0\u884c\u5217\u8868\u4e2d**\u5254\u9664**\u8fd9\u4e2a\u914d\u7f6e\u3002\r\n\r\n* **\u6700\u4f73\u5b9e\u8df5**: \u4e3a\u4e86\u9632\u6b62\u56e0\u53c2\u6570\u7f3a\u5931\u800c\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\uff0c\u8bf7\u59cb\u7ec8\u4f7f\u7528 `.get()` \u65b9\u6cd5\u6765\u5b89\u5168\u5730\u8bbf\u95ee `args` \u4e2d\u7684\u5c5e\u6027\u3002\r\n\r\n  ```python\r\n  # \u5b89\u5168\u7684\u5199\u6cd5\r\n  def my_safe_filter(args):\r\n      # \u5982\u679c 'lr' \u5b58\u5728\u4e14\u5c0f\u4e8e 0.001\uff0c\u5219\u4fdd\u7559\r\n      if args_dict := vars(args):\r\n           if args_dict.get('lr', 999) < 0.001:\r\n               return True\r\n      return False\r\n\r\n  # \u4e0d\u5b89\u5168\u7684\u5199\u6cd5 (\u5982\u679c 'lr' \u7f3a\u5931\u4f1a\u5f15\u53d1 AttributeError)\r\n  # def my_unsafe_filter(args):\r\n  #     return args.lr < 0.001\r\n  ```\r\n\r\n### 4\\. \u76ee\u5f55\u6e05\u7406\u8fc7\u6ee4\u5668 (`filter_func` for `clean_results`)\r\n\r\n\u7528\u4e8e `ResultAnalyzer.clean_results` \u65b9\u6cd5\uff0c\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u51b3\u5b9a\u54ea\u4e9b\u6587\u4ef6\u5939\u9700\u8981\u88ab\u5220\u9664\u3002\r\n\r\n* **\u7b7e\u540d**: `def my_cleanup_filter(config_dict: dict) -> bool:`\r\n\r\n* **\u53c2\u6570**:\r\n\r\n    * `config_dict`: \u4ece\u4e00\u4e2a `args.json` \u6587\u4ef6\u4e2d\u52a0\u8f7d\u800c\u6765\u7684\u5b57\u5178\u3002\r\n\r\n* **\u804c\u8d23**: \u5224\u65ad\u8fd9\u4e2a\u914d\u7f6e\u662f\u5426\u7b26\u5408\u88ab\u5220\u9664\u7684\u6761\u4ef6\u3002\r\n\r\n* **\u8fd4\u56de\u503c**: **\u5fc5\u987b**\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff1a\r\n\r\n    * `True`\uff1a**\u6807\u8bb0\u6b64\u6587\u4ef6\u5939\u4e3a\u5f85\u5220\u9664**\u3002\r\n    * `False`\uff1a\u4fdd\u7559\u6b64\u6587\u4ef6\u5939\u3002\r\n\r\n* **\u6700\u4f73\u5b9e\u8df5**: \u540c\u6837\u5730\uff0c\u8bf7\u52a1\u5fc5\u4f7f\u7528 `.get()` \u6765\u5904\u7406\u53ef\u80fd\u7f3a\u5931\u7684\u952e\u3002\r\n\r\n  ```python\r\n  # \u5b89\u5168\u7684\u5199\u6cd5\uff1a\u5220\u9664\u6240\u6709\u51c6\u786e\u7387\u4f4e\u4e8e 0.5 \u7684\u5b9e\u9a8c\r\n  def cleanup_low_accuracy(config):\r\n      # \u5982\u679c 'accuracy' \u952e\u4e0d\u5b58\u5728\uff0c.get \u8fd4\u56de 1.0\uff0c\u6761\u4ef6\u4e0d\u6210\u7acb\uff0c\u4e0d\u4f1a\u88ab\u5220\u9664\r\n      return config.get('accuracy', 1.0) < 0.5\r\n  ```\r\n\r\n## \u8d21\u732e\r\n\r\n\u6b22\u8fce\u4efb\u4f55\u5f62\u5f0f\u7684\u8d21\u732e\uff01\u5982\u679c\u4f60\u6709\u597d\u7684\u60f3\u6cd5\u6216\u53d1\u73b0\u4e86Bug\uff0c\u8bf7\u968f\u65f6\u5728 [GitHub Issues](https://www.google.com/search?q=https://github.com/ztxtech/ztxtech-exp/issues)\r\n\u4e2d\u63d0\u51fa\uff0c\u6216\u8005\u76f4\u63a5\u63d0\u4ea4\u4e00\u4e2a Pull Request\u3002\r\n\r\n## \u8bb8\u53ef\u8bc1\r\n\r\n\u8be5\u9879\u76ee\u91c7\u7528 [MIT License](https://opensource.org/licenses/MIT) \u6388\u6743\u3002\r\n",
    "bugtrack_url": null,
    "license": "MIT License\r\n        \r\n        Copyright (c) 2025 Tianxiang Zhan\r\n        \r\n        Permission is hereby granted, free of charge, to any person obtaining a copy\r\n        of this software and associated documentation files (the \"Software\"), to deal\r\n        in the Software without restriction, including without limitation the rights\r\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n        copies of the Software, and to permit persons to whom the Software is\r\n        furnished to do so, subject to the following conditions:\r\n        \r\n        The above copyright notice and this permission notice shall be included in all\r\n        copies or substantial portions of the Software.\r\n        \r\n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n        SOFTWARE.\r\n        ",
    "summary": "\u4e00\u4e2a\u8f7b\u91cf\u3001\u5f3a\u5927\u7684Python\u5e93\uff0c\u65e8\u5728\u7b80\u5316\u8ba1\u7b97\u5b9e\u9a8c\u7684\u7ba1\u7406\u3001\u6267\u884c\u548c\u5206\u6790\u3002",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://ztxtech.github.io/ztxexp/",
        "Repository": "https://github.com/ztxtech/ztxexp"
    },
    "split_keywords": [
        "experiment management",
        " machine learning",
        " deep learning",
        " reproducibility",
        " parameter search",
        " data science",
        " pytorch"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "676e7f4758b3358c22dbf7f5c1e1bdaf38bf67e988c01bb57efb3ad204b1222b",
                "md5": "6d82e0ed06a9a5b4e80dfcdde955614e",
                "sha256": "da794dc44831110b80d1da04f134e224d0afaf7483b1c7f55b23300f5367f4c0"
            },
            "downloads": -1,
            "filename": "ztxexp-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6d82e0ed06a9a5b4e80dfcdde955614e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 22859,
            "upload_time": "2025-08-03T12:37:20",
            "upload_time_iso_8601": "2025-08-03T12:37:20.722482Z",
            "url": "https://files.pythonhosted.org/packages/67/6e/7f4758b3358c22dbf7f5c1e1bdaf38bf67e988c01bb57efb3ad204b1222b/ztxexp-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f93b08441c6246b7759a0fe1b92cab84c5146850fa2930febe2a869712c63142",
                "md5": "babb0645f1850bf542e0b2ddacbfc180",
                "sha256": "76ef1229ad1a17358b7e1f6bcf0988779d2cc221e86a4daaff20d9079613dfd9"
            },
            "downloads": -1,
            "filename": "ztxexp-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "babb0645f1850bf542e0b2ddacbfc180",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 23801,
            "upload_time": "2025-08-03T12:37:22",
            "upload_time_iso_8601": "2025-08-03T12:37:22.346373Z",
            "url": "https://files.pythonhosted.org/packages/f9/3b/08441c6246b7759a0fe1b92cab84c5146850fa2930febe2a869712c63142/ztxexp-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-03 12:37:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ztxtech",
    "github_project": "ztxexp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "dill",
            "specs": []
        },
        {
            "name": "joblib",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "pandas",
            "specs": []
        },
        {
            "name": "psutil",
            "specs": []
        },
        {
            "name": "torch",
            "specs": []
        },
        {
            "name": "twine",
            "specs": []
        },
        {
            "name": "build",
            "specs": []
        }
    ],
    "lcname": "ztxexp"
}
        
Elapsed time: 1.30470s