管理许多实验运行和自定义结果分析的简单且极简的实用程序

exman的Python项目详细描述


管理许多实验运行和 自定义结果分析

为什么要另一个自定义解决方案?

我的工作是做深入学习的研究 实验。检验一个假设通常需要反复几次 参数网格。绘制和可视化结果通常是临时的 更新代码生成输出是一种开销。相反,我决定 在Jupyter笔记本中收集所有结果并创建绘图 interest ~ parameters。正如我所说,策划那是一项独立的任务 几乎每次都是。诸如 ModelDB为您提供 可视化,以便可以很容易地为模型聚合它们 比较。检验一个假设不是关于模型比较,因此 需要特殊处理。

可视化结果变成了一种痛苦,你必须记住一个映射 parameters -> results,将结果分成不同的文件夹 更糟的是。我在视觉化方面有很糟糕的经验。我 我所需要的就是用结果遍历文件夹并应用 它的功能是一样的。

安装

pip install -U git+https://github.com/ferrine/exman.git#egg=exman
# or
pip install exman

简单启动

简单的替换标准argparse.ArgumentParser

#file: main.pyimportexman# you should always use `exman.simpleroot(__file__)` unless you want another dirparser=exman.ExParser(root=exman.simpleroot(__file__))# `root = ./exman` relative to the main fileparser.add_argument(...)

然后像以前一样添加参数,不做任何更改。

最佳实践

main中的错误处理

从0.0.3开始,您可以使用以下上下文管理器。如果main() 函数失败,将移动到exman/fails

importexman# you should always use `exman.simpleroot(__file__)` unless you want another dirparser=exman.ExParser(root=exman.simpleroot(__file__))# `root = ./exman` relative to the main fileparser.add_argument(...)...if__name__=='__main__':args=parser.parse_args()withargs.safe_experiment:# do your stuffmain(args)

可选参数

避免reproducing experiments中的问题 您应该考虑使用exman.optional(type)作为可选 参数

importexman# you should always use `exman.simpleroot(__file__)` unless you want another dirparser=exman.ExParser(root=exman.simpleroot(__file__))# `root = ./exman` relative to the main fileparser.add_argument('--myarg',type=exman.optional(int))

验证器

在简单的argparser中,不能很容易地验证多个参数,它是 在埃克斯曼很容易。您可以创建一条信息性错误消息

importexman# you should always use `exman.simpleroot(__file__)` unless you want another dirparser=exman.ExParser(root=exman.simpleroot(__file__))# `root = ./exman` relative to the main fileparser.add_argument(...)# here `p` stands for initial namespace parsed from argumentsparser.register_validator(lambdap:p.arg1!=p.arg2orp.arg3==p.arg4,# next line will be autoformatted for you using .format'You have provided wrong set of arguments: {arg1}, {arg2}, {arg3}, {arg4}')

高级验证器可以引发exman.argumenterror,它包含比验证器函数中的消息更好的消息

与前夫结婚

pandas是处理表数据的好工具。实验是一样的 数据并可以在python中加载。所以你只需要运行 实验和打开一个笔记本电脑。

importexmanindex=exman.Index(exman.simpleroot('/path/to/main.py'))experiments=index.info()

表中有实验列time (datetime64[ns]),并且 root (pathlib.Path)结果路径。而且这张桌子还有 其他实验参数。您以后可以筛选/订购 根据结果,轻松访问结果文件夹 这就是内容。

fori,exinexperiments.iterrows():# do some actions# use ex.param for parameters# ex.root / 'plot.png' for file paths...

本地配置

您可以将本地配置文件存储在实验文件夹中。你 也应该提供文件名给exparser。

importexman# you should always use `exman.simpleroot(__file__)` unless you want another dirparser=exman.ExParser(root=exman.simpleroot(__file__),default_config_files=['local.cfg'])

本地配置存储全局定义的默认值,它们 覆盖主文件中设置的默认值

汽车结构

如果您想要参数特定的人类友好目录结构,可以 为此绑定特定的参数名

importexman# you should always use `exman.simpleroot(__file__)` unless you want another dirparser=exman.ExParser(root=exman.simpleroot(__file__),automark=['arg1','constant'])parser.add_argument('--arg1')

稍后您可以看到您的marked folder 看起来像这样

exman/marked/arg1/<arg1>/constant/<name-of-experiment>/...

如果你在一个团队里工作,这是有用的。写入main.py

importexman# you should always use `exman.simpleroot(__file__)` unless you want another dirparser=exman.ExParser(root=exman.simpleroot(__file__),automark=['user'],# store `user: myuser` content in local.cfgdefault_config_files=['local.cfg'])parser.add_argument('--user')

完成后,您的团队跑步记录可以存储在单个exman中 假定所有访问权限都已正确设置的目录。

exman/marked/user/<username>/constant/<name-of-experiment>/...

目录结构和cli

在命令行中运行也将相同:

python main.py --param1 foo --param2 bar

如果你真的运行这个程序,情况就会改变。它将所有解析的 将参数与默认值组合到yaml样式文件的位置 root/runs/<name-of-experiment>/params.yamlname-of-experiment 是通用的,动态自动创建的。快速查看或搜索 符号链接在index文件夹中,例如。 root/index/<name-of-experiment>.yaml。因为很多实验 创建和调试有时是必需的,您可能不希望创建 在runs文件夹中调试实验。如果是那样的话,你只要加上 --tmp标记和新文件将写入 root/tmp/<name-of-experiment>文件夹。你们两个都方便 不要松开即时消息有关实验和结果的重要信息,可以恢复 如果需要的话,这些符号链接是手工索引的。

root
|-- runs
|   `-- xxxxxx-YYYY-mm-dd-HH-MM-SS
|       |-- params.yaml
|       `-- ...
|-- fails
|-- index
|   `-- xxxxxx-YYYY-mm-dd-HH-MM-SS.yaml (symlink)
|-- marked
|   `-- <mark>
|       `-- xxxxxx-YYYY-mm-dd-HH-MM-SS (symlink)
|           |-- params.yaml
|           `-- ...
`-- tmp
    `-- xxxxxx-YYYY-mm-dd-HH-MM-SS
        |-- params.yaml
        `-- ...

重新运行实验

如果你想复制一个实验,你可以提供 yaml格式的配置文件。例如:

python main.py --config root/index/<name-of-experiment-to-reproduce>.yaml

所有值都将从上一次运行中还原。你也可以 使用--config ...修改旧值

python main.py --config root/index/<name-of-experiment-to-reproduce>.yaml --override-param=new_value

如果不想从保存的配置中还原某个参数(它 可能是一些动态设置的变量)您应该在 add_argument

parser.add_argument('--my_dynamic_id',default=os.environ.get('AUTOSETTED_ID'),volatile=True)

标记实验

如果你喜欢一些实验,你可以标记它们,以便日后更容易访问。

cd root_of_exman_dir
exman mark <key> <#ex1> [<#ex2> <#ex3> ...]

后来在朱庇特

index=exman.Index(exman.simpleroot('/path/to/main.py'))experiments=index.info('<key>')# assuming you work in a team and use best practice adviceuser_experiments=index.info('user/username')

删除实验

cd root_of_exman_dir
# delete only index
exman delete <#ex1> [<#ex2> <#ex3> ...]
# delete all files
exman delete --all <#ex1> [<#ex2> <#ex3> ...]

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java算法:如何对实体进行分组   C语言中的Java X509EncodedKeySpec#   如何修复java lambda筛选器(缺少返回语句)与future   java有没有办法在Swing中以亚像素精度绘制线条?   HV000030:找不到约束“javax”的验证器。验证。限制。大小为“验证类型”的java。util。可选<java。lang.String>'   CQL中语句的java分页状态   在开发时使用applet查看器的java对象相关applet   java如何从Oracle获取时区ID而不是时区偏移量   java递增变量   java JavaFX InvalizationListener或ChangeListener   java使用多个数据包将大量XMP数据插入jpg?   java允许删除请求   java为什么与类同名的方法不需要返回类型?   java数据转换错误转换   java一旦布尔值为真,如何关闭JFrame?   如何将数据写入两个java。木卫一。一次输出流对象?   mysql如何使用java在SQL中划分两列?   java使用Saxon/XQuery设置URI或目录解析器   mysql java。sql。SQLException:无法将值“20200816 17:33:21.690”从第18列转换为时间戳